跳到正文

题解

题解 P2255 【[USACO14JAN]Recording the Moolympics S】

VioletIsMyLove约 2 分钟
原文
文章信息与版本

文章信息

发布
2020年8月15日
收录
2026年9月29日
更新
2026年11月7日
篇幅
约 2 分钟
获赞
2
题目
P2255

版本

  1. v1当前

如果只有一台摄像机的话只需要将节目按左端点从大到小排序,如果当前的节目的右端点大于上之前已经左端点,那就不取,否则就取它。但这里有两台摄像机,所以把存两个端点,第一台和第二台的,每次都先把能给第二台摄像机的节目都给第二台,不能给再试着给第一台,当第一台的左端点大于第二台是互换一下就OK了。

Code:

C++
#include<cstdio>
#include<algorithm>
#define maxn 155
using namespace std;
int N,ans;
struct ZS{
	int s,t;
	bool operator <(const ZS b)const{return t<b.t;}
}a[maxn];
inline int read(){
	int ret=0;char ch=getchar();
	while (ch<'0'||ch>'9') ch=getchar();
	while (ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar();
	return ret;
}
int main(){
    N=read();
    for(int i=1;i<=N;i++) a[i].s=read(),a[i].t=read();
    sort(a+1,a+1+N);
    int lst1=0,lst2=0;
    for (int i=1;i<=N;i++)
      if (a[i].s<lst1) continue;else
	  if (a[i].s<lst2) lst1=lst2,lst2=a[i].t,ans++;else lst2=a[i].t,ans++;
    printf("%d\n",ans);
    return 0;
}
原文
存档评论2 条抓取于