10670 - Work Reduction(水题)

来源:互联网 发布:淘宝自己开店套现 编辑:程序博客网 时间:2024/06/06 13:23

对于每一个代理。

我们直接模拟就行了,看看是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
原创粉丝点击