标签:
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789
1 /* 2 Doing Homework again 3 扣分最多的先安排,安排在没有任务的那天 4 */ 5 #include <iostream> 6 #include <algorithm> //void sort( RandomIt first, RandomIt last, Compare comp ); 7 using namespace std; 8 #define MAX_num 1005 9 10 struct homework 11 { 12 int day; 13 int score; 14 }homework[MAX_num]; 15 bool cmp(struct homework a, struct homework b) 16 { 17 return a.score > b.score ? 1 : 0; 18 } 19 int main() 20 { 21 int T; 22 cin >> T; 23 while (T--) 24 { 25 int i, visit[MAX_num] = { 0 }, homework_num = 0, score = 0, max_score = 0; 26 cin >> homework_num; 27 for (i = 0; i < homework_num; i++) 28 cin >> homework[i].day; 29 for (i = 0; i < homework_num; i++) 30 { 31 cin >> homework[i].score; 32 max_score += homework[i].score; 33 } 34 sort(homework, homework + homework_num, cmp); 35 for (i = 0; i < homework_num; i++) 36 { 37 int d = homework[i].day; 38 for (; d >= 1; d--) 39 { 40 if (visit[d] == 0) 41 break; 42 } 43 if (visit[d] == 0 && d > 0) //是否可以安排这天 44 { 45 visit[d] = 1; 46 score += homework[i].score; 47 } 48 } 49 cout << (max_score - score) << endl; //最后被扣的最少分数 50 } 51 52 return 0; 53 }
标签:
原文地址:http://www.cnblogs.com/ht-beyond/p/4377671.html