Information
- ID
- 94
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 3
- Tags
- # Submissions
- 102
- Accepted
- 55
- Uploaded By
#include<stdio.h>
//最开始把这道题理解错了,题目说的是比赛总共n个时段,每个游戏都要在
//ti的时段之前完成,最开始当成时间去了,我说每个都一个小时内完成不刚好就可以全部完成吗
//就没有排序的意义了,但是时段不一样,这个时段被占用了就不能再使用了
//想要被扣的钱最少,很明显的贪心算法,让最贵的排在最前先去完成
typedef struct activity{
int t;//游戏的完成期限
int cost;//游戏的完成时间
}act;
act array[600];
int book[600];
int main(){
int m,n;
act temp;
int flag;
int x;
scanf("%d",&m);//一开始奖励给参赛者的钱
scanf("%d",&n);//n个小游戏也就是n个时段
for(int i=0; i<n; i++){
scanf("%d",&array[i].t);//每个游戏规定的时段
}
for(int i=0; i<n; i++){
scanf("%d",&array[i].cost);//每个游戏对应的花费
}
for(int i=0; i<n-1; i++){
for(int j=0; j<n-i-1; j++){
if(array[j+1].cost>array[j].cost){
temp = array[j+1];
array[j+1] = array[j];
array[j] = temp;
}
}
}
for(int i=0; i<n; i++){
if(!book[array[i].t])//如果这个时段没有被占用则直接使用
{
book[array[i].t] = 1;//将这个时段标记为1
}
else{//如果这个时段已经被占用则选取这个时段以内的
x = array[i].t;//4
x--;//3
while(book[x] == 1 && x>=1 ){
x--;
}
if(x){
book[x] = 1;
}
else{
m-=array[i].cost;
}
}
}
printf("%d\n",m);
}
By signing up a 追梦算法网 universal account, you can submit code and join discussions in all online judging services provided by us.