{"id":92,"date":"2011-08-03T22:51:56","date_gmt":"2011-08-03T14:51:56","guid":{"rendered":"http:\/\/wangkaixuan.tech\/?p=92"},"modified":"2020-06-03T22:53:00","modified_gmt":"2020-06-03T14:53:00","slug":"hdu-1009-fatmouse-trade","status":"publish","type":"post","link":"http:\/\/www.wangkaixuan.tech\/?p=92","title":{"rendered":"hdu 1009 FatMouse&#8217; Trade"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>\/*\nWA\u4e86n\u6b21\uff0c\u6700\u540e\u770b\u9053discuss\u91cc\u9762\u53d1\u73b0\u4e86\u4ee3\u7801\u7684\u7f3a\u9677\n\u539f\u6765\u662f\u6ca1\u6709\u6ce8\u610f\u5230\u539f\u9898\u4e2d\u7684 \u201cnon-negative integers\u201d\n\u4ee4\u4eba\u5410\u8840\u7684\u539f\u56e0...\n\u4e0b\u9762\u7684\u4ee3\u7801\u662f\u6839\u636e\u6211\u81ea\u5df1\u5199\u7684\u6539\u51fa\u6765\u7684\n\u60e8\u4e0d\u5fcd\u7779\u3002\u3002\u3002\n\u60a8\u51d1\u5408\u7740\u770b\u5427\u3002\u3002\u3002\n\u540e\u6765\u770b\u4eba\u5bb6\u4ee3\u7801\u90fd\u5de7\u5999\u5730\u8eb2\u4e86\u8fc7\u53bb\u3002\u3002\u3002\n\u7231\u867d\u8bf4\u72af\u9519\u4e0d\u4e00\u5b9a\u662f\u574f\u4e8b\n\u4f46\u8bbe\u5b9a\u597d\u201c\u8def\u7531\u201d\u8fd8\u662f\u5f88\u91cd\u8981\u6ef4\u3002\u3002\u3002 \n*\/\n#define LOCAL\n#include&lt;iostream>\n#include&lt;iomanip>\nusing namespace std;\nvoid swap(double *a,double *b)\n{\n         double t;\n         t=*a;\n         *a=*b;\n         *b=t;     \n}\nint main()\n{\n#ifdef LOCAL\n       freopen(\"input.txt\",\"r\",stdin);\n       freopen(\"output.txt\",\"w\",stdout);\n#endif\n    \n    \n    double sum,t,rat&#91;1001],x&#91;1001],y&#91;1001];\n    int m,n,i,j;\n    while(cin>>m>>n)\n    {\n            if(m==-1&amp;&amp;n==-1)\n                 return 0;\n            if(n==0)\n            {cout&lt;&lt;setprecision(3)&lt;&lt;setiosflags(ios::fixed)&lt;&lt;0.000&lt;&lt;endl;continue;}\n            for(i=0;i&lt;n;i++)\n            {\n                  cin>>x&#91;i]>>y&#91;i];\n                  rat&#91;i]=x&#91;i]\/y&#91;i];                \n            }                  \n            for(i=0;i&lt;n-1;i++)\n            {\n                 for(j=i+1;j&lt;n;j++)\n                 {\n                       if(rat&#91;i]&lt;rat&#91;j])\n                       {\n                              swap(&amp;rat&#91;i],&amp;rat&#91;j]);\n                              swap(&amp;x&#91;i],&amp;x&#91;j]);\n                              swap(&amp;y&#91;i],&amp;y&#91;j]);                 \n                       }                  \n                 }                \n            }\n            sum=0;\n            i=0;\n            while(m>=0)\n            {\n                 if(m>=y&#91;i])\n                 {sum+=x&#91;i];m-=y&#91;i];i++;\n                 if(i==n)break;}\n                 else\n                 {\n                      sum+=m*rat&#91;i];\n                      break;\n                 }      \n            }\n            cout&lt;&lt;setprecision(3)&lt;&lt;setiosflags(ios::fixed)&lt;&lt;sum&lt;&lt;endl;     \n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-92","post","type-post","status-publish","format-standard","hentry","category-06-01-acm"],"_links":{"self":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/92","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=92"}],"version-history":[{"count":0,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/92\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=92"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=92"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=92"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}