FatMouse' Trade
http://acm.hdu.edu.cn/showproblem.php?pid=1009
1 #include <map> 2 #include <cstdio> 3 #include <stack> 4 #include <cmath> 5 #include <queue> 6 #include <string> 7 #include <queue> 8 #include <cstring> 9 #include <iostream> 10 #include <algorithm> 11 12 #define lid id<<1 13 #define rid id<<1|1 14 #define closein cin.tie(0) 15 #define scac(a) scanf("%c",&a) 16 #define scad(a) scanf("%d",&a) 17 #define print(a) printf("%d\n",a) 18 #define scald(a) scanf("%lld",&a) 19 #define debug printf("hello world") 20 #define form(i,n,m) for(int i=n;i<m;i++) 21 #define mfor(i,n,m) for(int i=n;i>m;i--) 22 #define nfor(i,n,m) for(int i=n;i>=m;i--) 23 #define forn(i,n,m) for(int i=n;i<=m;i++) 24 #define scadd(a,b) scanf("%d%d",&a,&b) 25 #define memset0(a) memset(a,0,sizeof(a)) 26 #define scaldd(a,b) scanf("%lld%lld",&a,&b) 27 #define scaddd(a,b,c) scanf("%d%d%d",&a,&b,&c) 28 #define scadddd(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d) 29 30 #define INF 0x3f3f3f3f 31 #define maxn 50000 32 #define mod 1000000007 33 typedef long long ll; 34 using namespace std; 35 //---------AC(^-^)AC---------\\ 36 37 struct node 38 { 39 int a,b; 40 double x; 41 bool operator < (const node& a)const 42 { 43 return x>a.x; 44 } 45 }s[1005]; 46 int main() 47 { 48 int n,m; 49 while(scadd(n,m)) 50 { 51 if(n==-1&&m==-1) break; 52 for(int i=0;i<m;i++) 53 { 54 scanf("%d%d",&s[i].a,&s[i].b); 55 if(s[i].b!=0) s[i].x=1.0*s[i].a/s[i].b; 56 else s[i].x=1000000; 57 } 58 sort(s,s+m); 59 double ans=0; 60 int tmp=n; 61 int indx=0; 62 while(indx<m) 63 { 64 if(tmp>=s[indx].b) 65 { 66 ans+=s[indx].a; 67 tmp-=s[indx].b; 68 indx++; 69 //cout<<ans<<endl; 70 } 71 else 72 { 73 if(s[indx].x!=1000000) ans+=(1.0*s[indx].a*tmp/s[indx].b); 74 else ans+=s[indx].a; 75 tmp=0; 76 break; 77 } 78 } 79 printf("%.3f\n",ans); 80 } 81 return 0; 82 }
MILE NEVER GIVE UP!!!