标签:
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1051
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13534 Accepted Submission(s):
5590
1 #include <cstdio> 2 #include <cmath> 3 #include <cstring> 4 #include <iostream> 5 #include <algorithm> 6 using namespace std; 7 8 int T,n; 9 int a[5005],b[5005],vis[5001]; 10 11 int main () 12 { 13 int i,j; 14 int time; 15 int x,y; 16 scanf ("%d",&T); 17 while (T--) 18 { 19 scanf ("%d",&n); 20 for (i=0; i<n; i++) 21 scanf ("%d %d",&a[i], &b[i]); 22 for (i=0; i<n; i++)//两个for循环排序,没用结构体,比较麻烦 23 { 24 for (j=i; j<n; j++) 25 { 26 if (a[i] > a[j]) 27 { 28 swap(a[i], a[j]); 29 swap(b[i], b[j]); 30 } 31 if (a[i] == a[j]) 32 { 33 if (b[i] > b[j]) 34 { 35 swap(a[i], a[j]); 36 swap(b[i], b[j]); 37 } 38 } 39 40 } 41 } 42 time = 0; 43 memset(vis, 0, sizeof(vis)); 44 for (i=0; i<n; i++) 45 { 46 if (vis[i])//若该木棍被访问过,跳过 47 continue; 48 //x = a[i]; 49 y = b[i]; 50 for (j=i+1; j<n; j++) 51 { 52 if (!vis[j] && b[j] >= y) 53 { 54 55 vis[j] = 1;//标记访问 56 //x = a[j]; 57 y = b[j];//当前最大重量 58 } 59 } 60 time++;//时间加一 61 } 62 printf ("%d\n",time); 63 } 64 return 0; 65 }
标签:
原文地址:http://www.cnblogs.com/dxd-success/p/4379032.html