标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 1842 | Accepted: 763 |
Description
Input
Output
Sample Input
3 6 10 1 1 100 5 120
Sample Output
111
1 #include<algorithm> 2 #include<cstdio> 3 #include<iostream> 4 #include<cstring> 5 using namespace std; 6 struct TT 7 { 8 int v,w; 9 }a[25]; 10 int need[25]; 11 bool cmp(TT m, TT n) 12 { 13 if(m.v>n.v) return true; 14 return false; 15 } 16 int main() 17 { 18 int n,i,k; 19 int value,aa,bb,ans; 20 while(~scanf("%d %d",&n,&value)) 21 { 22 ans = 0; 23 k = 0; 24 for( i=0;i<n;i++) 25 { 26 scanf("%d %d",&aa,&bb);//排除大数; 27 if( aa>= value) 28 { 29 ans = ans+bb; 30 } 31 else 32 { 33 a[k].v = aa; 34 a[k].w = bb; 35 k++; 36 } 37 } 38 //k = n; 39 //printf("sdfgsdf\n"); 40 sort(a,a+k,cmp); 41 while(1) 42 { 43 memset(need,0,sizeof(need)); 44 int sum = value; 45 for(int i=0; i<k; i++) // Õý×ÅÕÒ 46 { 47 int tmp = sum/a[i].v; 48 need[i] = min(a[i].w,tmp); 49 sum = sum - a[i].v*need[i]; 50 } 51 if(sum>0) 52 { 53 for(int i=k-1;i>=0;i--) 54 { 55 if(a[i].w && a[i].v>=sum) 56 { 57 need[i]++; 58 sum = 0; 59 break; 60 } 61 } 62 } 63 if(sum>0) break; 64 int s = 0x3f3f3f3f; 65 for(int i=0;i<k;i++) 66 { 67 if(need[i]) 68 s = min(s,a[i].w/need[i]); 69 } 70 ans = ans+s; 71 for(int i=0;i<k;i++) 72 { 73 if(need[i]) 74 a[i].w -= need[i]*s; 75 } 76 } 77 printf("%d\n",ans); 78 } 79 return 0; 80 }
标签:
原文地址:http://www.cnblogs.com/lovychen/p/4484212.html