显然是贪心,不过忘了jewellery[i].w,jewellery[i].v中全是整数,做除法要乘以1.0,WA了N次。。看来这东西一旦放下手就不热了。。
1 #include2 #include 3 #include 4 using namespace std; 5 6 struct Jewe{ 7 int v,w; 8 }jewellery[100010]; 9 bool cmp(struct Jewe a,struct Jewe b) 10 { 11 return a.v*b.w>a.w*b.v; 12 } 13 int main() 14 { 15 int N,C; 16 while(scanf("%d%d",&N,&C)!=EOF){ 17 int i; 18 for(i=0;i jewellery[i].w){ 25 cur_val+=jewellery[i].v; 26 C-=jewellery[i].w; 27 }else{ 28 cur_val+=(int)((double)(1.0*C)*(jewellery[i].v*1.0/jewellery[i].w)+0.5); 29 break; 30 } 31 } 32 printf("%lld\n",cur_val); 33 } 34 }