按照顺序来。

Median Sum

大意:

给你一个集合,求其所有非空子集的权值的中位数。

某集合的权值即为其元素之和。

1 <= n <= 2000

解:

集合配对,每个集合都配对它的补集。

最大的那个没有配对,所以求(原集合的权值 + 1) >> 1,不小于这个的第一个即为所求。

用bitset实现可行性背包。

 #include <cstdio>
#include <bitset> const int N = ; std::bitset<N * N> bt; int a[N]; int main() {
int n, tot = ;
scanf("%d", &n);
for(int i = ; i <= n; i++) {
scanf("%d", &a[i]);
}
for(int i = ; i <= n; i++) {
bt |= (bt << a[i]);
bt[a[i]] = ;
tot += a[i];
}
tot = (tot + ) >> ;
while(bt[tot] == ) {
tot++;
}
printf("%d", tot);
return ;
}

AC代码


No Need

大意:

输入 N 个数字和 K 。

如果对于所有包含 Ai ,且和不小于 K 的集合,去掉 Ai 后和还不小于 K ,那么 Ai 就是 no need 的。

问有多少个元素是 no need 的。

1 <= n, k <= 5000

解:

no need 的一定是连续最小的一段,证明如下:

若 x need,且 y > x

对于每个包含 x 且 >= K 的集合,去掉 x 一定小于 K 。

若此集合包含 y ,则去掉 y 也小于 K 。

若此集合不包含 y ,则把 x 换成 y 即可。

这样证明了所有含x的集合。

对于某些把 y 换成 x 就会小于 K 的集合,

把 y 换成 0 也小于 K 。

证毕。

然后二分check。

check函数用上一题的思想,对于 x ,只要去掉 x 的集合和没有在[k - x, k)之间的,x 即为 no need

若 x >= k,单 x 元素即为所求,x 为 need。

 #include <cstdio>
#include <bitset>
#include <algorithm> const int N = ; std::bitset<N> bt; int n, a[N], k; inline bool check(int x) {
if(a[x] >= k) {
return ;
}
bt.reset();
for(int i = ; i <= n; i++) {
if(i == x) {
continue;
}
if(a[i] > N - ) {
break;
}
bt |= (bt << a[i]);
bt.set(a[i]);
}
for(int i = k - a[x]; i < k; i++) {
if(bt[i]) {
return ;
}
}
return ;
} int main() {
scanf("%d%d", &n, &k);
for(int i = ; i <= n; i++) {
scanf("%d", &a[i]);
}
std::sort(a + , a + n + );
int l = , r = n, mid;
while(l < r) {
mid = (l + r + ) >> ;
if(check(mid)) {
r = mid - ;
}
else {
l = mid;
}
}
if(r == && check()) {
r = ;
}
printf("%d", r);
return ;
}

AC代码


すぬけ君の塗り絵 / Snuke's Coloring

大意:

在 n * m 的区域中,输入 k 个黑格子的位置(x,y)。
对于每个 3 * 3 的区域,会包含 0 到 9 个黑格子。
求包含 0 ~ 9 个黑格子的 3 * 3 的区域各有多少个?

1 <= m, n <= 10 ^ 9

0 <= k <= 10 ^ 5

解:

每个黑格子只会对 9 个 3 * 3 的区域产生影响。

注意map的用法: it -> second

 #include <cstdio>
#include <map>
#include <algorithm> typedef long long LL; const int N = ; struct A {
int x, y;
A(int x = , int y = ) {
this->x = x;
this->y = y;
}
bool operator < (const A &d) const {
if(x == d.x) {
return y < d.y;
}
return x < d.x;
}
bool operator == (const A &d) const {
return x == d.x && y == d.y;
}
}a[N * ]; std::map<A, int> mp; int ans[]; int main() {
int m, n, k;
scanf("%d%d%d", &n, &m, &k);
for(int i = , x, y; i <= k; i++) {
scanf("%d%d", &x, &y);
for(int j = ; j < ; j++) {
for(int k = ; k < ; k++) {
if(x + j > n || y + k > m || x + j < || y + k < ) {
continue;
}
mp[A(x + j, y + k)]++;
}
}
}
std::map<A, int>::iterator it = mp.begin();
int tot = ;
for(; it != mp.end(); it++) {
tot++;
ans[it->second]++;
}
printf("%lld\n", 1ll * (m - ) * (n - ) - 1ll * tot);
for(int i = ; i <= ; i++) {
printf("%d\n", ans[i]);
}
return ;
}

AC代码


Largest Smallest Cyclic Shift

大意:

给定 n 个 a , m 个 b, k 个 c

求所组成的字符串的最小循环表示法的最大字典序。

解(结论):把这些一个一个的字符放入multiset,每次取字典序最大最小的合并放回去。

最后的即为所求。

 #include <cstdio>
#include <set>
#include <iostream> using std::string; std::multiset<string> s; int main() {
int n;
scanf("%d", &n);
for(int i = ; i <= n; i++) {
s.insert("a");
}
scanf("%d", &n);
for(int i = ; i <= n; i++) {
s.insert("b");
}
scanf("%d", &n);
for(int i = ; i <= n; i++) {
s.insert("c");
}
while(s.size() > ) {
string a = *s.begin();
string b = *(--s.end());
s.erase(s.begin());
s.erase(--s.end());
s.insert((string)(a + b));
}
std::cout << *s.begin();
return ;
}

AC代码


Popping Balls

不会...

DP题组的更多相关文章

  1. Codeforces Round #369 (Div. 2)---C - Coloring Trees (很妙的DP题)

    题目链接 http://codeforces.com/contest/711/problem/C Description ZS the Coder and Chris the Baboon has a ...

  2. 4817 江哥的dp题d

    4817 江哥的dp题d  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 已知1-N的排列P的LIS(最长上 ...

  3. 4809 江哥的dp题c

    4809 江哥的dp题c  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 有两个数x,y,一开始x=1,y= ...

  4. 4816 江哥的dp题b

    4816 江哥的dp题b  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 给出两个1-N的随机排列A,B.若 ...

  5. 4815 江哥的dp题a

    4815 江哥的dp题a  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 给出一个长度为N的序列A(A1,A ...

  6. HDU 2577 How to Type(dp题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2577 解题报告:有一个长度在100以内的字符串,并且这个字符串只有大写和小写字母组成,现在要把这些字符 ...

  7. codevs4817 江哥的dp题d

    4817 江哥的dp题d  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 黄金 Gold [题目描述] Description 已知1-N的排列P的LIS(最长上升子序列)不超 ...

  8. 古韵之乞巧 题解 dp题

    [noip模拟赛1]古韵之乞巧   描述 闺女求天女,更阑意未阑. 玉庭开粉席,罗袖捧金盘. 向月穿针易,临风整线难. 不知谁得巧,明旦试相看. ——祖咏<七夕> 女子乞巧,是七夕的重头戏 ...

  9. cf1061c 普通dp题

    题解见https://blog.csdn.net/godleaf/article/details/84402128 这一类dp题是可以压缩掉一维空间的,本题枚举a1到an,枚举到ai时枚举ai的每个约 ...

随机推荐

  1. input type=date时,时间数据回填,报错The specified value "2019-0404-18" does not conform to the required format, "yyyy-MM-dd".

    <input autocomplete id="start-time" name="start_time" type="date" c ...

  2. day 7-6 GIL,死锁,递归锁与信号量,Event,queue,

    摘要: 1.死锁与递归锁 2.信号量 3.Event 4.Timer 5.GIL 6.Queue 7.什么时候该用多线程和多进程 一. 死锁与递归锁 所谓死锁: 是指两个或两个以上的进程或线程在执行过 ...

  3. leetcode:Roman to Integer and Integer to Roman

    2015-06-03 罗马数字以前接触过I到VIII比较多,直到遇见这个题目才知道更详细.阿拉伯数字和罗马数字之间的转换最重的是了解罗马数字的规则. 罗马数字规则:(总结) 1, 罗马数字共有7个,即 ...

  4. MySQL最大连接数设置

    在使用MySQL数据库的时候,经常会遇到这么一个问题,就是“Can not connect to MySQL server. Too many connections”-mysql 1040错误,这是 ...

  5. elasticsearch介绍,安装,安装错误解决及相应插件安装

    一.elasticsearch介绍 1.简介(使用的是nosql,更新比mongodb慢): ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎, ...

  6. APP测试重点(转载)

      1.安装卸载测试: app在不同的操作系统(安卓和ios),不同的版本,不同的机型上是否都能安装成功: 在安装过程中,突然断网或网络不好,是否给出有好的提示,网络恢复之后是否能正常下载: 在安装过 ...

  7. $mount(“#app”)手动挂载

    没有el属性时,证明vue还没绑定到特定的dom上,需要延迟加载,则使用.$mount("")进行手动挂载 https://blog.csdn.net/longzhoufeng/a ...

  8. Vue学习目录

    前面的话 近年来,前端框架发展火热,新的框架和名词不停地出现在开发者眼前,而且开发模式也产生了一定的变化.目前来看,前端MVVM框架的出现给开发者带来了不小的便利,其中的代表就有Angular.js. ...

  9. hdu-2328(暴力枚举+kmp)

    题意:给你n个字符串,问你这n个串的最长公共子串 解题思路:暴力枚举任意一个字符串的所有子串,然后暴力匹配,和hdu1238差不多的思路吧,这里用string解决的: 代码: #include< ...

  10. .net core 2.0 数据访问-迁移

    将用于进行迁移的 Entity Framework Core NuGet包 添加到`.csproj`文件 <ItemGroup> <DotNetCliToolReference In ...