C. The Tower is Going Home

链接

[http://codeforces.com/contest/1075/problem/C]

题意

有个1e9*1e9的棋盘(1,1)位置在左下角也就是车这枚棋子的位置,然后有n个在某一列后面划一列,m个从x1到x2在第y行划线,然后这个棋子不能穿过画的线
问你最少需要去掉多少线条是棋子能移动到第1e9行

分析

其实这个问题只需要统计m个操作中有多少是x11开始的,以及终点为x21e9的
因为不是从1开始的总可以绕过,说的不清楚,看代码自己领悟吧

代码

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int shu[N],k1[N];
int main(){
	int n,m,i,j;
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("in.txt","r",stdin);
	while(cin>>n>>m){
		int ans=0;
		for(i=0;i<n;i++)
		cin>>shu[i];
		sort(shu,shu+n);
		int t=0;
		for(i=0;i<m;i++){
			int x1,x2,y;
			cin>>x1>>x2>>y;
			if(x1==1)
				k1[t++]=x2;
				if(x2==1000000000) ans++;
		}
		sort(k1,k1+t);
		ans+=n;
		i=0,j=0;
		int cnt=t;
		while(i<n){
			while(j<t&&k1[j]<shu[i]){
				--cnt;
				++j;
			}
			ans=min(ans,cnt+i);
			if(ans==0) break;
			++i;
		}
		cout<<ans<<endl;
	}
	return 0;
}
posted @ 2018-11-10 16:32  ChunhaoMo  阅读(205)  评论(0)    收藏  举报