uva 10670 - Work Reduction

题目大意是:第一行输入原来的文件数,要减少到的文件数,以及相关机构数目L。以下L行每行有:

机构名称:A,B(A代表每处理一件文件的cost,B代表每处理掉文件的一半的cost)。

思路:输入时要用心好好处理一下,我也用ssanf函数试了,也可以A的,以下scanf中的%[]的用法是刚从网上学到的,详细见SCANF函数应用技巧

用贪心的思想,当然是每次尽量用处理掉一半花费较少,详细见代码。。

Problem C: Work Reduction

Paperwork is beginning to pile up on your desk, and tensions at the workplace are starting to mount. Your boss has threatened to fire you if you don't make any progress by the end of the day. You currently have  N  units of paperwork on your desk, and your boss demands that you have exactly  M units of paperwork left by the end of the day.

The only hope for you now is to hire help. There are various agencies which offer paperwork reduction plans:

For $A they will reduce your paperwork by one unit.For $B they will reduce your entire paperwork by half (rounding down when necessary).

Note that work can never be reduced to less than 0.

Your task now is to produce a sorted table of agency names and their respective minimum costs to solve your workload problem.

The first line of input consists of a single positive integer representing the number of cases to follow. Each case begins with three positive integers separated by spaces: N - your starting workload,M - your target workload, and L - the number of work reduction agencies available to you, (1 <= M <= N <= 100000, 1 <= L <= 100). The next L lines have the format "[agency name]:A,B", where A and B are the rates as described above for the given agency. (0 <= A,B <= 10000) The length of the agency name will be between 1 and 16, and will consist only of capital letters. Agency names will be unique.

For each test case, print "Case X", with X being the case number, on a single line, followed by the table of agency names and their respective minimum costs, sorted in non-decreasing order of minimum costs. Sort job agencies with identical minimum costs in alphabetical order by agency name. For each line of the table, print out the agency name, followed by a space, followed by the minimum required cost for that agency to solve your problem.

Sample Input

2
100 5 3
A:1,10
B:2,5
C:3,1
1123 1122 5
B:50,300
A:1,1000
C:10,10
D:1,50
E:0,0

Sample Output

Case 1
C 7
B 22
A 37
Case 2
E 0
A 1
D 1
C 10
B 50
 
#include <iostream>
#include <cstring>
#include <cstdio>
#include<cmath>
#include <algorithm>
using namespace std;
 struct point
 {
     char name[20];
     int A;
     int B;
     int cost;

 }s[110];

 bool cmp(point a,point b)
   {
       if(a.cost==b.cost)
          return strcmp(a.name,b.name)<0;
       else
        return a.cost<b.cost;
   }
   int nn=1;
int main()
{
   int T,n,m,l,sn,sm;
   int i,j,k;

   scanf("%d",&T);
 while(T--)
 {
     scanf("%d%d%d",&sn,&sm,&l);
      getchar();
     for(i=0;i<l;i++)
      {
          scanf("%[A-Z]:%d,%d",s[i].name,&s[i].A,&s[i].B);
           getchar();
           s[i].cost=0;

      }
     for(i=0;i<l;i++)
     {
         int n=sn,m=sm;
         s[i].cost=0;
      while(1)
       {
          if(n==m) break;
           int t=n/2;
           if(s[i].B<(n-t)*s[i].A&&t>=m)
           {
               n=t;
              s[i].cost+=s[i].B;
           }
           else
           {
               n--;
               s[i].cost+=s[i].A;
           }

       }
     }
    sort(s,s+l,cmp);

       printf("Case %d\n",nn++);
     for(i=0;i<l;i++)
        cout<<s[i].name<<' '<<s[i].cost<<endl;

 }

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值