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/ ...
随机推荐
- KVM基本实现原理
KVM 虚拟化技术概述 http://blog.csdn.net/yearn520/article/details/6461047 KVM 虚拟化技术在 AMD 平台上的实现 1.http://www ...
- vue 开发过程中遇到的问题
1. gitlab团队协作开发 2. element ui 问题集锦 3. 使用vue和ElementUI快速开发后台管理系统
- HDU 5985 概率
n种硬币各有cnt[i]枚,每轮下其有p[i]概率保留,问各种硬币只有它存活到最后一轮的概率. 设k轮后i硬币存活概率$a[i][k]=(1-p^k_i)^{cnt[i]}$ 则最后只有第i种硬币存活 ...
- Python json转字符串的一些细节
要调PHP那边的接口,php那边一直都校验不过,很是郁闷.没办法,只能让人把发送成功的代码拿过来看,不过是php写的,步骤都是一样: php端: 1. json对象转json字符串. 2. 对json ...
- ZigBee介绍
ZigBee网络 什么是ZigBee技术 Zigbee在中国被译为"紫蜂",是一种基于IEEE802.15.4协议的最近发展起来的一种短距离无线通信技术,功耗低,被业界认为是最有可 ...
- 2014年最佳的10款 PHP 开发框架
PHP去年发生了翻天覆地的变化.似乎每个人都有一个想法一个好的框架应该是什么样子,但话又说回来,没有多少面积制品类型的框架或框架的最终实际使用在不同的生产项目. 你知道哪个框架选择为您的生产计划吗?你 ...
- Trying to get property of non-object
原文:http://www.jb51.net/article/29878.htm 总结:判断为空用 if(isset($v)){}代替if($v == null){}
- Linux基础操作-分区概念
开启Linux系统前添加一块大小为20G的SCSI硬盘 开启系统,右击桌面,打开终端 为新加的硬盘分区,一个主分区大小为10G,剩余空间给扩展分区,在扩展分区上划分两个逻辑分区,大小各5G 进入分区工 ...
- JavaScript 金额、数字、千分位、千分位、保留几位小数、舍入舍去、支持负数
JavaScript 金额.数字 千分位格式化.保留指定位数小数.支持四舍五入.进一法.去尾法 字段说明: number:需要处理的数字: decimals:保留几位小数,默认两位,可不传: dec_ ...
- socket系统调用
SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol) { int retval; struct socket *sock; in ...