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 ...
随机推荐
- office开发心得——基于模板开发
这几天正在写一个小程序,但用到生成word表格和Excel表格.到网上查了一些资料,发现如果生成表格模板相对比较固定即可把其制作成模板,需要设置什么格式可以直接在模板中设置,而程序仅需替换相应的内容即 ...
- 基于SMB协议的共享文件读写 博客分类: Java
基于SMB协议的共享文件读写 博客分类: Java 一.SMB协议 SMB协议是基于TCP-NETBIOS下的,一般端口使用为139,445. 服务器信息块(SMB)协议是一种IBM协议,用于在计 ...
- MVC运行原理
Global.asax Global.asax 文件,有时候叫做 ASP.NET 应用程序文件,提供了一种在一个中心位置响应应用程序级或模块级事件的方法.你可以使用这个文件实现应用程序安全性以及其它一 ...
- PCL—低层次视觉—点云分割(RanSaC)
点云分割 点云分割可谓点云处理的精髓,也是三维图像相对二维图像最大优势的体现.不过多插一句,自Niloy J Mitra教授的Global contrast based salient region ...
- 浏览器 怪异模式(Quirks Mode) 与 标准模式(Standards Mode)
浏览器 怪异模式(Quirks Mode) 与 标准模式(Standards Mode) 怪异模式,浏览器使用自己的方式解析渲染页面,在不同的浏览器就会显示不同的样式.标准模式,浏览器使用W3C的标准 ...
- WCF学习笔记之地址
1.统一资源标识(URI) URI全称是Uniform Resource Identifier(统一资源标识),唯一地标识一个网络资源的同时也标识资源所处的位置以及访问方式(资源访问所用的网络协议). ...
- Fragment 和 FragmentActivity的使用(二)
今天继续完成剩下的学习部分,现在项目很多地方使用viewpager来提供滑动,今天记录学习viewpager配合fragment的显示,增加一个CallLogsFragment配合之前SMSLis ...
- HTML页面导出为Word
protected void btnExport_Click(object sender, EventArgs e) { string strFileName = DateTime.Now.ToStr ...
- UVa 1103 (利用连通块来判断字符) Ancient Messages
本题就是灵活运用DFS来求连通块来求解的. 题意: 给出一幅黑白图像,每行相邻的四个点压缩成一个十六进制的字符.然后还有题中图示的6中古老的字符,按字母表顺序输出这些字符的标号. 分析: 首先图像是被 ...
- Linux find xargs rm .orig
/********************************************************************* * Linux find xargs rm .orig * ...