Codeforces Round #213 (Div. 1) B - Free Market 思维+背包 好题
思路:这个题怎么说呢,迷惑性很大,题目里说了交换了两个集合的时候如果有相同元素不能交换,感觉如果没
这句话能很快写出来, 其实当交换的两个集合有重复元素的时候只要交换那些不重复的就好啦,这样就相当于能
交换两个有交的集合,那么对于两个集合S1, S2我们不需要去考虑有没有交只需要考虑sumS1 + d >= sumS2是否
满足条件。所以求个背包从前往后贪心就好啦。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long
using namespace std; const int N = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-; int n, d, c[N], all, day;
bitset<> dp; int main() {
scanf("%d%d", &n, &d);
dp[] = ;
for(int i = ; i <= n; i++) {
int x; scanf("%d", &x);
dp |= dp << x;
}
while() {
int nxt = -;
for(int i = all+; i <= all+d && i <= ; i++) {
if(dp[i]) {
nxt = i;
}
}
if(nxt == -) break;
day++; all = nxt;
}
printf("%d %d\n", all, day);
return ;
} /*
*/
Codeforces Round #213 (Div. 1) B - Free Market 思维+背包 好题的更多相关文章
- Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)
Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...
- Codeforces Round #213 (Div. 2) A. Good Number
#include <iostream> #include <vector> using namespace std; int main(){ ; cin >> n ...
- Codeforces Round #213 (Div. 2) B. The Fibonacci Segment
#include <iostream> #include <algorithm> #include <vector> using namespace std; in ...
- Codeforces Round #373 (Div. 2) C. Efim and Strange Grade 水题
C. Efim and Strange Grade 题目连接: http://codeforces.com/contest/719/problem/C Description Efim just re ...
- Codeforces Round #310 (Div. 2) B. Case of Fake Numbers 水题
B. Case of Fake Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- Codeforces Round #309 (Div. 2) B. Ohana Cleans Up 字符串水题
B. Ohana Cleans Up Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/554/pr ...
- Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks 字符串水题
A. Kyoya and Photobooks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- Codeforces Round #353 (Div. 2) C. Money Transfers (思维题)
题目链接:http://codeforces.com/contest/675/problem/C 给你n个bank,1~n形成一个环,每个bank有一个值,但是保证所有值的和为0.有一个操作是每个相邻 ...
- Codeforces Round #185 (Div. 2) A. Whose sentence is it? 水题
A. Whose sentence is it? Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...
随机推荐
- 科学计算三维可视化---Mayavi入门(Mayavi管线)
一:Mayavi管线 mlab.show_pipeline() #显示管线层级,来打开管线对话框 (一)管线中的对象scene Mayavi Scene:处于树的最顶层的对象,他表示场景,配置界面中可 ...
- python---函数补充(变量传递),语句执行顺序(入栈顺序)
一:函数补充 默认作为函数参数的数据,是浅拷贝传递.不是和C等语言一样,产生一个临时变量. class T: def __init__(self,num): print(id(num)) self.n ...
- 两个button之间的间距如何去掉
在外层加上一个父元素,设置font-size:0;即可. 两个按钮之间的间距如何去掉
- Mongodb 笔记03 查询、索引
查询 1. MongoDB使用find来进行查询.find的第一个参数决定了要返回哪些文档,这个参数是一个文档,用于指定查询条件.空的查询会匹配集合的全部内容.要是不指定查询,默认是{}. 2. 可以 ...
- bzoj千题计划109:bzoj1019: [SHOI2008]汉诺塔
http://www.lydsy.com/JudgeOnline/problem.php?id=1019 题目中问步骤数,没说最少 可以大胆猜测移动方案唯一 (真的是唯一但不会证) 设f[i][j] ...
- Overfitting & Regularization
Overfitting & Regularization The Problem of overfitting A common issue in machine learning or ma ...
- sql 2012之后分页查询速度问题
一.SQL Server 2012使用OFFSET/FETCH NEXT分页,比SQL Server 2005/2008中的RowNumber()有显著改进.今天特地作了简单测试,现将过程分享如下: ...
- @Resource,@Autowired,@Inject3种注入方式
概况 @Resource,@Autowired,@Inject 这3种都是用来注入bean的,它们属于不同的程序中. ANNOTATION PACKAGE SOURCE @Resource javax ...
- Exp3:MAL_免杀原理与实践
目录 1.实验环境 2.实践内容 2.1 msfvenom 2.1.1 msfvenom直接生成 2.1.2 msfvenom 编码一次 2.1.3 msfvenom 编码多次 2.2 Veil_ev ...
- CentOS 6 / RHEL 6配置bonding 4模式
实现bond 802.3ad or 4 模式:(IEEE 802.3ad), 方式:创建一个整合的组,这个组会共享网速和网络双工(duplex)设置.模式 4 会根据 IEEE 802.3ad 标准使 ...