标签:des style class blog code color
Description
Input
Output
Sample Input
4 3 6 2 4 0 2 4 7
Sample Output
4
以前做的是选一个点,这个题是选两个点,不过做法都一样,都是选区间最后两个点
#include<iostream> #include<cstdio> #include<map> #include<cstring> #include<string> #include<algorithm> #include<cmath> #include<vector> #include<set> using namespace std; const int maxn=10000+10; struct node { int x,y; }a[maxn]; bool vis[maxn]; bool cmp(node xx,node yy) { return xx.y<yy.y; } int main() { int n; while(scanf("%d",&n)!=EOF) { for (int i=1;i<=n;i++) scanf("%d%d",&a[i].x,&a[i].y); sort(a+1,a+n+1,cmp); memset(vis,0,sizeof(vis)); vis[a[1].y]=1; vis[a[1].y-1]=1; int ans=2; for (int i=2;i<=n;i++) { int m=0; for (int j=a[i].x;j<=a[i].y;j++) { if (vis[j]) m++; if (m==2) break; } if (m==0) { vis[a[i].y]=1; vis[a[i].y-1]=1; ans+=2; } if (m==1) { vis[a[i].y]=1; ans++; } } printf("%d\n",ans); } return 0; }
poj 1716 Integer Intervals,布布扣,bubuko.com
标签:des style class blog code color
原文地址:http://www.cnblogs.com/chensunrise/p/3791078.html