1 solutions
-
0
C++ :
#include <iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; struct stick { int l; int w; }s[5000]; bool cmp(stick a,stick b) { if(a.l<b.l) return true; else if(a.l>b.l) return false; else return a.w<b.w; } int main() { int t,n,minute,ti,number; int mark[5000]; //freopen("sticks.in","r",stdin); //freopen("sticks.out","w",stdout); cin>>t; while(t--) { cin>>n; for(int i=0;i<n;i++) cin>>s[i].l>>s[i].w; sort(s,s+n,cmp); memset(mark,0,sizeof(mark)); number=0; minute=0; int pl; while(number!=n) { for(int i=0;i<n;i++) if(!mark[i]) { pl=i; minute++; break; } for(int i=0;i<n;i++) { if(!mark[i]&&s[i].l>=s[pl].l&&s[i].w>=s[pl].w) { mark[i]=1; number++; pl=i; } } } cout<<minute<<endl; } return 0; } //#include <iostream> //#include <stdio.h> //#include <cstdlib> //#include <ctime> // //int main() //{ // freopen("sticks.in","w",stdout); // srand(time(NULL)); // // int T = 50; // printf("%d\n",T); // printf("5\n4 9 5 2 2 1 3 5 1 4 \n3\n2 2 1 1 2 2 \n3\n1 3 2 2 3 1 \n"); // for(int i = 0;i < T-3;i++) // { // int n = rand()%4985+1; // int l,w; // printf("%d\n",n); // for(int j = 0;j < n;j++) // { // l = rand()%10000+1; // w = rand()%10000+1; // printf("%d %d ",l,w); // } // printf("\n"); // } // return 0; //}
- 1
Information
- ID
- 1320
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- (None)
- # Submissions
- 0
- Accepted
- 0
- Uploaded By