码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces 767E(贪心)

时间:2017-02-28 00:26:09      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:amp   stream   http   priority   typedef   indicator   using   close   ret   

CodeForces 767E

题意:有100元的纸币和1元的硬币,某同学有无限多的纸币和 m 个硬币,并决定接下来的 n 天去食堂每天花费 c[i] 元。已知食堂大叔在第 i 天找零 x 元的话,不满意度会增加 w[i],问最小不满意度。

题解:按顺序先直接使用手上有的硬币,当手上硬币剩余为负数的时候,说明前面一定会出现有一天需要多使用一张纸币,取的策略就是取前面的代价 w[i]*(100-a[i]%100) 最少的一次,然后手里剩余硬币 +100。用优先队列维护即可。

(代码略挫)

技术分享
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <algorithm>
 5 #include <queue>
 6 using namespace std;
 7 typedef long long LL;
 8 struct node{
 9     LL id,val;
10     bool operator<(const node &a)const{
11         return val>a.val;
12     }
13 };
14 LL n,m;
15 LL c[100005];
16 LL w[100005];
17 LL vis[100005];
18 LL ans;
19 int main(){
20     scanf("%lld%lld",&n,&m);
21     for(LL i=1;i<=n;i++)
22         scanf("%lld",&c[i]);
23     for(LL i=1;i<=n;i++)
24         scanf("%lld",&w[i]);
25     priority_queue<node> q;
26     for(LL i=1;i<=n;i++){
27         if(c[i]%100==0) continue;
28         q.push((node){i,w[i]*(100-c[i]%100)});
29         m-=c[i]%100;
30         if(m<0){
31             if(!q.empty()){
32                 vis[q.top().id]=1;
33                 ans+=q.top().val;
34                 q.pop();
35                 m+=100;
36             }
37         }
38     }
39     printf("%lld\n",ans);
40     for(LL i=1;i<=n;i++){
41         if(vis[i]){
42             printf("%lld %lld\n",c[i]/100+1,0);
43         }
44         else{
45             printf("%lld %lld\n",c[i]/100,c[i]%100);
46         }
47     }
48 
49     return 0;
50 }
Psong

 

CodeForces 767E(贪心)

标签:amp   stream   http   priority   typedef   indicator   using   close   ret   

原文地址:http://www.cnblogs.com/N-Psong/p/6476863.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!