【HDOJ】1009 FatMouse' Trade

【题目】http://acm.hdu.edu.cn/showproblem.php?pid=1009

【报告】

    粗一看题目,哇,SF了,部分背包,贪心!

    然后一交,满心期待AC,结果悲剧的WA了。

    百思不得其解,百度了好多代码,总感觉是一样的。

    最后看了DISCUSS版,发现了那组坑爹的数据:

0 1
1 0
1.000

1 0
0.000

5 4
10000 5
2000 2
100 0
300 0
10400.000

    然后,就AC了……

【程序】

// TASK: 1009 FatMouse' Trade
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstdio>
#define N 10000
using namespace std;
class thing
{
      public:
             double j,f;
             double v;
}a[N+1];
long n;
double m;
inline int cmp(const void*aa,const void*bb)
{
       thing a=*(thing*)aa,b=*(thing*)bb;
       if (a.v<b.v)
          return 1;
       else if (a.v==b.v) return 0;
       else return -1;
}
double ans;
int main(int argc, char *argv[])
{
    while (scanf("%lf%d",&m,&n))
    {
          if (m==-1||n==-1) break;
          if (n<=0)
          {
                   printf("%.3f\n",0.0);
             continue;
          }
      //    cout << m << " " << n << endl;
          ans=0.0;
          memset(a,0,sizeof(a));
          for (long i=1;i<=n;i++)
          {
              scanf("%lf%lf",&a[i].j,&a[i].f);
         //     cout << a[i].j << " " << a[i].f << endl;
              if (a[i].j<=0)
              {
                 i--;n--;continue;
  

posted @ 2012-08-29 09:36  为美好世界献上珂学  阅读(140)  评论(0)    收藏  举报