【codeforces 767E】Change-free
【题目链接】:http://codeforces.com/problemset/problem/767/E
【题意】 
 
你有m个1元硬币和无限张100元纸币; 
你在第i天,需要花费ci元; 
同时在第i天,收银员有一个不高兴程度wi; 
然后如果它要找零x张纸币y枚硬币的话,它的不高兴值会为wi*(x+y) 
找的零钱会回到你的口袋里; 
问你n天的,总的最小不高兴值;
【题解】 
 
整百的部分,直接用纸币填就好了; 
则直接对ci%100考虑; 
即要直接用硬币填满ci%100,或者是先给一张100,然后让他找你钱; 
如果m>=ci; 
则直接用硬币填它,这样不会有不满意; 
m-=ci; 
然后记录如果给一张纸币的话,会增加多少不满意度; 
放入优先队列中; 
如果m< ci; 
则考虑修改之前的贪心; 
如果优先队列的第一个元素比w[i]*(100-a[i])小; 
则把之前的那一个修改成用一张纸币填; 
然后那时因为已经减去ci了,所以修改的话,硬币数直接加上100; 
而这100可以保证够把当前的ci用硬币填 
则,用硬币填就是了; 
如果不满足优先队列的第一个元素比w[i]*(100-a[i])小; 
则这个用一张纸币填; 
 
【Number Of WA】 
 
0 
 
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e5+100;
struct abc
{
    LL val,id;
    friend bool operator < (abc a,abc b)
    {
        if (a.val!=b.val)
            return a.val>b.val;
        else
            return a.id<b.id;
    }
};
LL n,m;
LL ans1[N],ans2[N],a[N],w[N];
priority_queue<abc> xiao;
int main()
{
    //Open();
    Close();//scanf,puts,printf not use
    //init??????
    cin >> n >> m;
    rep1(i,1,n)
    {
        cin >> a[i];
        ans1[i]=a[i]/100;
        a[i]%=100;
    }
    rep1(i,1,n)
        cin >> w[i];
    LL ans = 0;
    rep1(i,1,n)
    if (a[i])
    {
        if (m>=a[i])
        {
            m-=a[i];
            xiao.push(abc{w[i]*(100-a[i]),i});
            continue;
        }
        //m<a[i]
        if (xiao.empty())
        {
            m+=100-a[i];
            ans+=w[i]*(100-a[i]);
            ans2[i] = 1;
            continue;
        }
        if (xiao.top().val<w[i]*(100-a[i]))
        {
            ans2[xiao.top().id] = 1;
            ans+=xiao.top().val;
            xiao.pop();
            m+=100;
            m-=a[i];
            xiao.push(abc{w[i]*(100-a[i]),i});
        }
        else
        {
            m+=100-a[i];
            ans+=w[i]*(100-a[i]);
            ans2[i] = 1;
        }
    }
    cout << ans << endl;
    rep1(i,1,n)
        if (ans2[i])
            cout << ans1[i]+1 <<' '<<0<<endl;
        else
            cout << ans1[i] <<' '<<a[i]<<endl;
    return 0;
}
【codeforces 767E】Change-free的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
		[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ... 
- 【codeforces 779E】Bitwise Formula
		[题目链接]:http://codeforces.com/contest/779/problem/E [题意] 给你n个长度为m的二进制数 (有一些是通过位运算操作两个数的形式给出); 然后有一个未知 ... 
- 【codeforces 785E】Anton and Permutation
		[题目链接]:http://codeforces.com/problemset/problem/785/E [题意] 给你一个初始序列1..n顺序 然后每次让你交换任意两个位置上面的数字; 让你实时输 ... 
- 【codeforces 798C】Mike and gcd problem
		[题目链接]:http://codeforces.com/contest/798/problem/C [题意] 给你n个数字; 要求你进行若干次操作; 每次操作对第i和第i+1个位置的数字进行; 将 ... 
- 【52.49%】【codeforces 556A】Case of the Zeros and Ones
		time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ... 
- 【27.91%】【codeforces 734E】Anton and Tree
		time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ... 
- 【33.10%】【codeforces 604C】Alternative Thinking
		time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ... 
- 【40.17%】【codeforces 569B】Inventory
		time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ... 
- 【codeforces 757C】Felicity is Coming!
		time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ... 
随机推荐
- Matlab中的函数句柄@
			本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50699990 @是Matlab中的句柄 ... 
- 深入MNIST code测试
			本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50624471 依照教程:深入MNIST ... 
- zTree 无子节点 单击事件
			<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ... 
- apache 与 nginx 详解
			Apache与Nginx的优缺点比较 1.nginx相对于apache的优点: 轻量级,同样起web 服务,比apache 占用更少的内存及资源 抗并发,nginx 处理请求是异步非阻塞的,而apac ... 
- H3C SecPath U200-S 如何在内网使用外网IP地址访问内网服务器
			H3C SecPath U200-S 如何在内网使用外网IP地址访问内网服务器 ------------------------------------------------------------ ... 
- [Windows Server]安装系统显示“缺少计算机所需的介质驱动程序”解决方案
			1.把电脑上插着的硬盘拔了 2.重试 3.修复计算机找到dos命令行 4.然后进入我们放置解压了的系统的那个符盘,(我这里放在D盘)输入:d: 找到刚才我们解压了的系统文件,进入sourc ... 
- substring类型题目的解题模板
			https://discuss.leetcode.com/topic/30941/here-is-a-10-line-template-that-can-solve-most-substring-pr ... 
- MQ发送定时消息
			通过延时发送来发送定时消息. RocketMQ只支持固定精度时间的延时消息发送:1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h 若 ... 
- C++中 pair 的使用方法
			#include<iostream> #include<string> #include<map> using namespace std; // pair简单讲就 ... 
- 0x02 枚举、模拟、递推
			1.TYVJ1266(这站是不是已经倒闭了啊) USACO陈年老题,对于这种开关问题啊,最多只按一次,而且第一行随便按完下面的就全确定了,类似的还有固定翻转一个长度的区间,这个也是最多翻一次的而且翻的 ... 
