九度 题目1399:名侦探柯南

http://ac.jobdu.com/problem.php?id=1399

View Code
 1 #include<iostream>
2 #include<algorithm>
3 #include<cstdio>
4 #include<cmath>
5 using namespace std;
6 struct node
7 {
8 int w,v;//这里改成double 会超时
9 };
10 node item[100008];
11 bool cmp(const node &a,const node &b)
12 {
13 return ((double)a.v/(double)a.w)>((double)b.v/(double)b.w);//从单位价值最大的开始装,
14 }
15 int main()
16 {
17 int n,C;
18 long long totalvalue;
19 while(scanf("%d%d",&n,&C)==2)
20 {
21 totalvalue=0;
22 int i;
23 for(i=0;i<n;i++) scanf("%d%d",&item[i].w,&item[i].v);
24 sort(item,item+n,cmp);
25 for(i=0;i<n;i++)
26 {
27 if(item[i].w<C)//该类装完
28 {
29 C-=item[i].w;
30 totalvalue+=item[i].v;
31 }
32 else//装一部分,
33 {
34 double per=round((1.0*C*item[i].v)/(1.0*item[i].w));
35 totalvalue+=(long long)per;
36 break;
37 }
38 //cout<<totalvalue<<endl;
39 }
40 printf("%lld\n",totalvalue);
41 }
42 return 0;
43 }


 

posted @ 2012-03-28 21:48  keepmoving89  阅读(271)  评论(1编辑  收藏  举报