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 ...
随机推荐
- maven小项目注册服务(三)--web模块
java的web应用打包方式一般为war它和jar的区别就是包含了更多的资源和文件,如JSP文件,静态资源文件,servlet等等.war包的核心就WEB-INF文件夹下必须有一个web.xml 的配 ...
- volicity语法学习和总结
Velocity是一个基于java的模板引擎(template engine).它允许任何人仅仅简单的使用模板语言(template language)来引用由java代码定义的对象.当Velocit ...
- 如何使java中double类型不以科学计数法表示
在java中,把一个double或者BigDecimal的小数转换为字符串时,经常会用科学计数法表示,而我们一般不想使用科学计数法,可以通过:DecimalFormat a = new Decimal ...
- 二维树状数组(水题) POJ1195
前段时间遇到线段树过不了,树状数组却过了的题.(其实线段树过得了的) 回忆了下树状数组. 主要原理,还是二进制位数,每一项的和表示其为它的前((最后一位1及其后)的二进制数)和,可从二进制图来看.(用 ...
- bzoj1564
嗯,这是一道简单题 注意二叉搜索树的子树中序一定是连续的 又因为取值修改是任意的并且修改代价与权值无关 不难想到把权值离散化,然后按找数据值排序,然后dp f[i][j][w]表示从i~j的节点构成一 ...
- CodeForces 489C (贪心) Given Length and Sum of Digits...
题意: 找出m位且各个数位数字之和为s的最大和最小整数,不包括前导0(比如说003是非法的),但0是可以的. 分析: 这题是用贪心来做的,同样是m位数,前面的数字越大这个数就越大. 所以写一个can( ...
- BZOJ 1610 连线游戏
BZOJ不允许除以0. #include<iostream> #include<cstdio> #include<cstring> #include<cstd ...
- ubuntu12.04下txt文件乱码如何解决
:gsettings set org.gnome.gedit.preferences.encodings auto-detected "['UTF-8','GB18030','GB2312' ...
- Linux busybox mount -a fstab
/*********************************************************************** * Linux busybox mount -a fs ...
- Java [Leetcode 319]Bulb Switcher
题目描述: There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off ...