Codeforces 377
简单说一下。
A
搜索出任意一个剩余细胞个数的联通块。剩下的填X。
B
二分加贪心加数据结构。
/*
* Problem:
* Author: Shun Yao
*/ #include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <time.h> #include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#include <bitset>
#include <utility>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> //using namespace std; const int MAXN = 100010, MAXM = 100010; int n, m, s, a[MAXM], ai[MAXM], b[MAXN], c[MAXN], bc[MAXN]; bool cmpa(int x, int y) {
return a[x] < a[y];
} bool cmpb(int x, int y) {
return b[x] < b[y];
} class cmpc {
public:
bool operator () (int x, int y) {
return c[x] > c[y];
}
} ; bool check(int x) {
std::priority_queue<int, std::vector<int>, cmpc> pq;//小根堆
int i, j = n, k = 0;
for (i = m; i >= 1; i -= x) {
while (j >= 1 && b[bc[j]] >= a[ai[i]]) {
pq.push(bc[j]);
--j;
}
if (pq.empty())
return 0;
k += c[pq.top()];
pq.pop();
if (k > s)
return 0;
}
return 1;
} void output(int x) {
puts("YES");
std::priority_queue<int, std::vector<int>, cmpc> pq;
int i = m, j = n, k, ans[MAXM];
while (i >= 1) {
while (j >= 1 && b[bc[j]] >= a[ai[i]]) {
pq.push(bc[j]);
--j;
}
for (k = 1; k <= x && i >= 1; ++k, --i)
ans[ai[i]] = pq.top();
pq.pop();
}
for (i = 1; i <= m; ++i)
printf("%d ", ans[i]);
} int main(/*int argc, char **argv*/) {
int i, l, r, mid; scanf("%d%d%d", &n, &m, &s);
for (i = 1; i <= m; ++i) {
scanf("%d", a + i);
ai[i] = i;
}
for (i = 1; i <= n; ++i) {
scanf("%d", b + i);
bc[i] = i;
}
for (i = 1; i <= n; ++i)
scanf("%d", c + i);
std::sort(ai + 1, ai + m + 1, cmpa);
std::sort(bc + 1, bc + n + 1, cmpb);
if (!check(m))
printf("NO");
else {
l = 1;
r = m;
while (l < r) {
mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
output(r);
} fclose(stdin);
fclose(stdout);
return 0;
}
C
贪心,dp,位运算。
/*
* Problem: C. Captains Mode
* Author: Shun Yao
*/ #include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <time.h> #include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#include <bitset>
#include <utility>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> //using namespace std; int n, m, a[111], d[21], p[1048577], f[1048577];
char c[21]; int main(/*int argc, char **argv*/) {
int i, j, x, y; scanf("%d", &n);
for (i = 1; i <= n; ++i)
scanf("%d", a + i);
std::sort(a + 1, a + n + 1, std::greater<int>());
scanf("%d", &n);
for (i = 1; i <= n; ++i)
scanf(" %c %d", c + i, d + i);
m = (1 << n) - 1;
p[0] = 0;
for (i = 1; i <= m; ++i)
p[i] = p[i >> 1] + (i & 1);
f[m] = 0;
for (i = m - 1; i >= 0; --i) {
f[i] = d[x = p[i] + 1] == 2 ? INT_MAX : INT_MIN;
for (j = 1; j <= n; ++j) {
y = 1 << (j - 1);
if (i & y || f[i ^ y] == INT_MAX || f[i ^ y] == INT_MIN)
continue;
if (d[x] == 1) {
if (c[x] == 'p')
f[i] = std::max(f[i], f[i ^ y] + a[j]);
else
f[i] = std::max(f[i], f[i ^ y]);
} else {
if (c[x] == 'p')
f[i] = std::min(f[i], f[i ^ y] - a[j]);
else
f[i] = std::min(f[i], f[i ^ y]);
}
}
}
printf("%d", f[0]); fclose(stdin);
fclose(stdout);
return 0;
}
D
官方做法是把l,v,r看成平面上的矩形。用线段树求出重叠数最多的部分。
E
仔细分析一下,很明显是维护一个下凸,用单调栈即可。
Codeforces 377的更多相关文章
- Codeforces 377 A Maze【DFS】
题意:给出n*m的矩阵,矩阵由'.'和'#'组成,再给出k,表示需要在'.'处加k堵墙,使得剩下的'.'仍然是连通的 先统计出这个矩阵里面总的点数'.'为sum 因为题目说了一定会有一个解,所以找到一 ...
- Codeforces #377 Div2
打得还不错的一场CF,题目质量也很高,今后还要继续努力 A题: 题意:给定一个数k,让其乘一个最小的数,使乘得以后的数要不被10整除,要不减去r以后被10整除,求这个最小的数 #include < ...
- Codeforces Round #377 (Div. 2) D. Exams
Codeforces Round #377 (Div. 2) D. Exams 题意:给你n个考试科目编号1~n以及他们所需要的复习时间ai;(复习时间不一定要连续的,可以分开,只要复习够ai天 ...
- Codeforces Round #377 (Div. 2)D(二分)
题目链接:http://codeforces.com/contest/732/problem/D 题意: 在m天中要考k个课程, 数组a中有m个元素,表示第a[i]表示第i天可以进行哪门考试,若a[i ...
- Codeforces Round #377 (Div. 2) E. Sockets
http://codeforces.com/contest/732/problem/E 题目说得很清楚,每个电脑去插一个插座,然后要刚好的,电脑的power和sockets的值相同才行. 如果不同,还 ...
- Codeforces Round #377 (Div. 2) D. Exams 贪心 + 简单模拟
http://codeforces.com/contest/732/problem/D 这题我发现很多人用二分答案,但是是不用的. 我们统计一个数值all表示要准备考试的所有日子和.+m(这些时间用来 ...
- Codeforces Round #377 (Div. 2) 被坑了
http://codeforces.com/contest/732/problem/B 题目要求任意两个连续的日子都要 >= k 那么如果a[1] + a[2] < k,就要把a[2]加上 ...
- Codeforces Round #377 (Div. 2)A,B,C,D【二分】
PS:这一场真的是上分场,只要手速快就行.然而在自己做的时候不用翻译软件,看题非常吃力非常慢,还有给队友讲D题如何判断的时候又犯了一个毛病,一定要心平气和,比赛也要保证,不要用翻译软件做题: Code ...
- Codeforces Round #377 (Div. 2)
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; in ...
随机推荐
- 【转载】git/github初级运用自如
之前了解过github,并在上面看了一些项目的源代码,于是自己也在github上创建了账户,希望以后有机会也把自己的项目托管在上面去.但是前提你要先了解git/github,下面的内容是从我的好基友虫 ...
- 07-语言入门-07-A Famous Music Composer
题目地址: http://blog.csdn.net/sevenmit/article/details/8231994 描述 Mr. B is a famous music composer. On ...
- 在Ubuntu上为Android系统的Application Frameworks层增加硬件访问服务(老罗学习笔记5)
在数字科技日新月异的今天,软件和硬件的完美结合,造就了智能移动设备的流行.今天大家对iOS和Android系统的趋之若鹜,一定程度上是由于这两个系统上有着丰富多彩的各种应用软件.因此,软件和硬件的关系 ...
- Codeforces Round #204 (Div. 2) C
写了一记忆化 TLE了 把double换成long long就过了 double 这么耗时间啊 #include <iostream> #include<cstdio> #i ...
- autofac meta
http://kevincuzner.com/2014/05/19/extreme-attributed-metadata-autofac/ http://stackoverflow.com/ques ...
- poj3207 Ikki’s Story IV – Panda’s Trick
2-SAT. tarjan缩点.强连通分量的点要选一起选. #include<cstdio> #include<algorithm> #include<cstring&g ...
- Form验证(转)
代码写 N 久了,总想写得别的.这不,上头说在整合两个项目,做成单一登录(Single Sign On),也有人称之为“单点登录”.查阅相关文档后,终于实现了,现在把它拿出来与大家一起分享.或许大家会 ...
- SJ9012: IE6 IE7 不支持 JSON 对象
标准参考 JSON 是一种数据交换格式,RFC 4627 对 JSON 进行了详细描述. 根据 ECMA-262(ECMAScript)第 5 版中描述,JSON 是一个包含了函数 parse 和 s ...
- Jquery 弹出提示框输入插件 apprise 修改中文按钮以及使用说明
apprise的使用非常简单,引入js脚本和css <script type="text/javascript" src="/js/apprise-1.5.fu ...
- UVA 11478 Halum(用bellman-ford解差分约束)
对于一个有向带权图,进行一种操作(v,d),对以点v为终点的边的权值-d,对以点v为起点的边的权值+d.现在给出一个有向带权图,为能否经过一系列的(v,d)操作使图上的每一条边的权值为正,若能,求最小 ...