zoukankan      html  css  js  c++  java
  • hdu acm 2187

    #include "iostream"
    #include "stdlib.h"
    #include "string.h"

    typedef struct{
     int p;
     int w;
    }rice;

    int cmp(const void *a,const void *b)
    {
        rice *c=(rice *)a;
        rice *d=(rice *)b;
     return c->p-d->p;
    }

    int main()
    {
     int n,m;
     int c;
     rice r[1005];

     scanf("%d",&c);
     while(c--)
     {
      scanf("%d%d",&n,&m);
      for(int i=0;i<m;i++)
      {
       scanf("%d%d",&r[i].p,&r[i].w);
      }

      qsort(r,m,sizeof(rice),cmp);

      int i=0;
      double sum=0;

      while(r[i].p*r[i].w<=n&&i<m)
      {
       sum+=(double)r[i].w;
       n=n-r[i].w*r[i].p;
       i++;
      }

      if(i<m&&n>0)
       sum+=(double)n/r[i].p;

      printf("%.2lf\n",sum);
     }

     return 0;
    }

       

  • 相关阅读:
    没有上司的舞会
    邮票面值设计
    小木棍
    简单的试炼
    区间质数
    加工生产调度
    泥泞的道路
    总数统计
    中庸之道

  • 原文地址:https://www.cnblogs.com/Shirlies/p/2325035.html
Copyright © 2011-2022 走看看