依然和前几个一样作为最简单的贪心,不在多说
注意第二条是标准在一直都改变...
#include <iostream> #include <string> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; struct T{ int length,weight; }a[5010]; bool cmp(T a,T b){ if(a.length!=b.length) return a.length<b.length; return a.weight<b.weight; } int main (){ int Case,temp; scanf("%d ",&Case); while(Case--){ int mark[5010]={0}; int n,sum=0; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d%d",&a[i].length,&a[i].weight); sort(a,a+n,cmp); int j=n,now=0; while(n>0){ for(int i=now;;i++) if(mark[i]==0) { now=i; n--; mark[i]=1; break; } int temp=now; for(int i=now+1;i<j;i++) if( a[i].length>=a[now].length && a[i].weight>=a[now].weight && mark[i]==0 ) mark[i]=1,n--,now=i; //注意now的不断调整 sum++; now=temp; } printf("%d ",sum); } return 0; }