http://blog.youkuaiyun.com/dgq8211/article/details/7538060
题目链接:Click here~~
题意:
有 n 门作业,每门作业都有自己的截止期限,当超过截止期限还没有完成作业,就会扣掉相应的分数。问如何才能使扣分最少。
解题思路:
把 n 门作业按分数从大到小排序,然后每次都把作业安排在离它的截止期限最近的一天,并把此天标记为已用,若不能安排,则扣分。
- #include <stdio.h>
- #include <string.h>
- #include <algorithm>
- using namespace std;
- struct T
- {
- int score,date;
- }A[1005];
- bool cmp(const T& s1,const T& s2)
- {
- return s1.score > s2.score;
- }
- int main()
- {
- int z,n,ans;
- bool in[1005];
- scanf("%d",&z);
- while(z--)
- {
- memset(in,0,sizeof(in));
- ans = 0;
- scanf("%d",&n);
- for(int i=0;i<n;i++)
- scanf("%d",&A[i].date);
- for(int i=0;i<n;i++)
- scanf("%d",&A[i].score);
- sort(A,A+n,cmp);
- for(int i=0;i<n;i++)
- {
- int j;
- for(j = A[i].date;j >= 1;j--)
- {
- if(!in[j])
- {
- in[j] = true;
- break;
- }
- }
- if(!j)
- ans += A[i].score;
- }
- printf("%d\n",ans);
- }
- return 0;
- }