[Codeforces 10E] Greedy Change
Brief Introduction:
给你一些种类的硬币,用最少的硬币数表示X
求最小的使贪心算法错误的X
Algorithm:
一道论文题,《A Polynomial-time Algorithm for the Change-making Problem》
证明先挖个坑,以后再填
感性猜想,我们可以构建出这样一个算法:
对于一种币值A,我们找出一个略大于A仅用币值不小于B且小于A的货币表示的值X,使得贪心算法在使用A后要用更多零碎的货币
这样,只要枚举A、B,找出最小的这样的值即可。存在性问题论文中也有证明。
Code:
#include <bits/stdc++.h> using namespace std; int n,dat[],res=-; int main()
{
cin >> n;
for(int i=;i<=n;i++) cin >> dat[i]; for(int i=;i<=n;i++)
for(int j=i+;j<=n;j++)
{
int cnt1=,cnt2=,W=dat[i]-,t; for(int k=i+;k<=j;k++) //非贪心做法
cnt1+=(W/dat[k]),W%=dat[k]; t=W=dat[i]--W+dat[j];
for(int k=;k<=n;k++) //贪心做法
cnt2+=(W/dat[k]),W%=dat[k]; if(cnt1<cnt2 && (res==- || res>t)) res=t;
}
cout << res;
return ;
}
Review:
多看结论题
[Codeforces 10E] Greedy Change的更多相关文章
- Greedy Change
Greedy Change time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces 1132G Greedy Subsequences [线段树]
洛谷 Codeforces 看到题解那么少就来发一篇吧-- 思路 看完题目一脸懵逼,感觉无从下手. 莫名其妙地想到笛卡尔树,但笛卡尔树好像并没有太大作用. 考虑把笛卡尔树改一下:每个点的父亲设为它的右 ...
- [cf10E]Greedy Change
对于$w$的表示方案,可以用序列描述,即$x_{i}$表示第$i$种货币的数量 贪心策略得到的方案即是(对应序列)字典序最大的方案,并定义最优策略得到的方案为在最小化货币总数的基础上,(对应序列)字典 ...
- Codeforces Round #376 (Div. 2) C题 Socks(dsu+graphs+greedy)
Socks Problem Description: Arseniy is already grown-up and independent. His mother decided to leave ...
- codeforces C. New Year Ratings Change 解题报告
题目链接:http://codeforces.com/problemset/problem/379/C 题目意思:有n个users,每个user都有自己想升的rating.要解决的问题是给予每个人不同 ...
- Mass Change Queries Codeforces - 911G
https://codeforces.com/contest/911/problem/G 没想到线段树合并还能这么搞.. 对每个权值建一个线段树(动态开点),如果权值为k的线段树上第i位为1,那么表示 ...
- Codeforces Round #598 (Div. 3) A. Payment Without Change 水题
A. Payment Without Change You have a coins of value n and b coins of value 1. You always pay in exac ...
- Educational Codeforces Round 40 G. Castle Defense (二分+滑动数组+greedy)
G. Castle Defense time limit per test 1.5 seconds memory limit per test 256 megabytes input standard ...
- Codeforces.472F.Design Tutorial: Change the Goal(构造 线性基 高斯消元)
题目链接 \(Description\) 给定两个长为\(n\)的数组\(x_i,y_i\).每次你可以选定\(i,j\),令\(x_i=x_i\ \mathbb{xor}\ x_j\)(\(i,j\ ...
随机推荐
- MySQL使用笔记(三)表的操作
By francis_hao Dec 11,2016 表的操作 表的操作有创建表.查看表.删除表和修改表 创建表 创建表之前要在某个数据库中. mysql> create table ta ...
- 使用babel把es6代码转成es5代码
第一步:创建一个web项目 使用命令:npm init 这个命令的目的是生成package.json. 执行第二步中的命令后生成的package.json的文件的内容是: { "name&q ...
- 基于MapReduce的手机流量统计分析
1,代码 package mr; import java.io.IOException; import org.apache.commons.lang.StringUtils; import org. ...
- bzoj1036: [ZJOI2008]树的统计Count link-cut-tree版
题目传送门 这 算是link-cut-tree裸题啊 不过以前好像没有写过单点修改.............. #include<cstdio> #include<cstring&g ...
- [转]如何整理Linux磁盘碎片,竟与Windows的方式大不同 返回操作系统首页
Linux 系统永远不需要整理磁盘碎片的神话相信很多人都听说过.由于 Linux 采用了优秀的日志文件系统(ext2.ext3.ext4, btrfs等),在绝大多数情况下确实是不需要进行磁盘碎片整理 ...
- MySQL 进阶(待发布)
视图 存储过程 触发器 基本函数
- php常用的系统函数
字符串函数 strlen:获取字符串长度,字节长度 substr_count 某字符串出现的次数 substr:字符串截取,获取字符串(按照字节进行截取) mb_strlenmb_substr str ...
- MATLAB规划问题——线性规划和非线性规划
1.线性规划 求线性规划问题的最优解有两种方法,一种方法是使用linprog命令,另一种是使用optimtool工具箱,下面分别介绍这两种方法. ①linprog命令 一般情况下,Linprog命令的 ...
- 开放API端口SIGN算法详细设计
开放API端口SIGN算法详细设计 前言 在app开放接口api的设计中,避免不了的就是安全性问题,因为大多数接口涉及到用户的个人信息以及一些敏感的数据,所以对这些接口需要进行身份的认证,那么这就需要 ...
- Fedora27安装宝塔linux面板出现/usr/lib/rpm/redhat/redhat-hardened-cc1找不到的错误
执行下面的命令: sudo dnf install redhat-rpm-config 就可以解决你的问题了