您的位置:首页 > Web前端

[河南省ACM省赛-第三届] BUYING FEED (nyoj 248)

2015-04-01 21:05 411 查看
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define N 352
/*
重量*单价+重量*距离 = 重量*(距离+单价) 预处理单价
贪心:优先买价格低的
*/
struct Node {
int p;// p = (单价+距离)
int w;
}c
;

bool cmp(Node a, Node b)
{
return a.p != b.p ? a.p < b.p : a.w > b.w;
}

int main()
{
freopen("d:\\in.txt", "r", stdin);
int t;
int K, E, n;
scanf("%d", &t);
while(t--) {
scanf("%d%d%d", &K, &E, &n);
int a, b;
for(int i=0; i<n; i++){
scanf("%d%d%d", &a, &c[i].w, &b);
c[i].p = E-a+b;
}
sort(c, c+n, cmp);
int res = 0, totw = 0;
for(int i=0; i<n; i++){
if(totw >= K) break;
if(totw+c[i].w > K)
res += c[i].p*(K-totw);
else
res += c[i].p*c[i].w;
totw += c[i].w;
}
printf("%d\n", res);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: