标签:des style os io for art div ar
Description
Input
Output
Sample Input
3 3 3 3 3 10 5 1 3 1 3 1 6 2 3 7 1 4 6 4 2 4 3 3 2 1 7 6 5 4
Sample Output
0 3 5
题意:每个作业都有规定要完成的时间,和超时的扣分,求最小的扣分
思路:贪心排序,然后每个都从最远的时间开始做,标记处理
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1005;
struct Node {
int day, cost;
} node[maxn];
int n;
int f[maxn];
int cmp(Node a, Node b) {
return a.cost < b.cost;
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &node[i].day);
if (node[i].day > n)
node[i].day = n;
}
int sum = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &node[i].cost);
sum += node[i].cost;
}
sort(node, node+n, cmp);
memset(f, 0, sizeof(f));
for (int i = n-1; i >= 0; i--)
for (int j = node[i].day; j >= 1; j--)
if (!f[j]) {
f[j] = 1;
sum -= node[i].cost;
break;
}
printf("%d\n", sum);
}
return 0;
}HDU - 1789 Doing Homework again,布布扣,bubuko.com
HDU - 1789 Doing Homework again
标签:des style os io for art div ar
原文地址:http://blog.csdn.net/u011345136/article/details/38226795