3 4 10 20 30 40 50 60 70 80 2 1 3 2 200 3 10 100 20 80 30 50
10 20 30
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; #define max 300 struct node { int left,right; }ab[max]; int cmp(node a,node b) { return a.left<b.left; } int main() { int i,j,temp,T,N,mn[1000],a,b,sum; scanf("%d",&T); if(T>=1&&T<=200) while(T--) { memset(mn,0,sizeof(mn));//清零 ,string.h memset(ab,0,sizeof(ab)); scanf("%d",&N); for(i=0;i<N;i++) { scanf("%d%d",&a,&b); a=(a+1)/2; b=(b+1)/2; ab[i].left=a<b?a:b; ab[i].right=a<b?b:a; } sort(ab,ab+N,cmp); sum=0; for(i=0;i<N;i++) { if(!mn[i]) { temp=ab[i].right; sum++; mn[i]=1; for(j=i+1;j<N;j++) { if(!mn[j]&&temp<ab[j].left) { temp=ab[j].right; mn[j]=1; } } } } printf("%d\n",sum*10); } return 0; }
原文:http://www.cnblogs.com/tt-t/p/5022620.html