10670 - Work Reduction(水题)

11 篇文章 0 订阅
8 篇文章 0 订阅

对于每一个代理。

我们直接模拟就行了,看看是A方案好还是B方案好。

细节参见代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 100000000;
const int maxn = 100 + 5 ;
int T,n,m,l,kase = 0;
struct node{
    char name[20];
    int a,b,cost;
    bool operator < (const node& rhs) const {
        return cost < rhs.cost || (cost == rhs.cost && strcmp(name,rhs.name)<0);
    }
}a[maxn];
char s[100];
int main() {
    scanf("%d",&T);
    while(T--) {
        scanf("%d%d%d",&n,&m,&l);
        for(int i=0;i<l;i++) {
            scanf("%s",s);
            int len = strlen(s), res ;
            for(int j=0;j<len;j++) {
                if(s[j] == ':') { res = j+1; a[i].name[j] = '\0'; break; }
                else a[i].name[j] = s[j];
            }
            a[i].a = a[i].b = 0;
            for(int j=res;j<len;j++) {
                if(s[j] == ',') { res = j+1; break; }
                else a[i].a = a[i].a*10 + s[j] - '0';
            }
            for(int j=res;j<len;j++)
                a[i].b = a[i].b*10 + s[j] - '0';
        }
        for(int i=0;i<l;i++) {
            a[i].cost = 0;
            int cur = n;
            while(true) {
                int v = round(cur*1.0/2);
                if(cur - v < m) {
                    a[i].cost += a[i].a*(cur - m); break;
                }
                if(v * a[i].a < a[i].b) {
                    a[i].cost += a[i].a*(cur - m); break;
                }
                else {
                    cur -= v;
                    a[i].cost += a[i].b;
                }
            }
        }
        sort(a,a+l);
        printf("Case %d\n",++kase);
        for(int i=0;i<l;i++) 
            printf("%s %d\n",a[i].name,a[i].cost);
    }
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值