uva 11729

---恢复内容开始---

题意: 有n个部下,第i个部下需要话bi分钟交代任务,他会单独执行ji分钟完成任务,你需要选择交代任务的时间顺序,尽早的完成任务。 传送门:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2829 解题思路: 贪心算法; 代码:

---恢复内容结束---

题意: 有n个部下,第i个部下需要话bi分钟交代任务,他会单独执行ji分钟完成任务,你需要选择交代任务的时间顺序,尽早的完成任务。 传送门:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2829 解题思路: 贪心算法; 代码: #include #include #include using namespace std; struct job{ int j,b; bool operator < (const job& x) const{ //运算符重载 return j > x.j; } };

int main(){
int n,b,j,kase = 1;
while(scanf("%d",&n) ==1 && n){
vector v;
for(int i=0;i<n;i++){
scanf("%d%d",&b ,&j);v.push_back(job{j,b});
}
sort(v.begin(),v.end());
int s=0;
int ans=0;
for(int i = 0; i < n ;i++){
s += v[i].b;
ans = max(ans, s+v[i].j);
}
printf("Case %d: %d\n",kase++, ans);
}
return 0;
}

posted on 2015-08-07 11:31  闵豪  阅读(89)  评论(0)    收藏  举报

导航