Codeforces Round #551 (Div. 2) A-E
A. Serval and Bus
- 算出每辆车会在什么时候上车, 取min即可
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<iostream>
#define ll long long
#define M 101
#define mmp make_pair
using namespace std;
int read() {
int nm = 0, f = 1;
char c = getchar();
for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
return nm * f;
}
int ans[M], n, t;
int main() {
n = read(), t = read();
for(int i = 1; i <= n; i++)
{
int a = read(), b = read();
while(a < t) a += b;
ans[i] = a;
}
int minn = 0x3e3e3e3e, pl = 0;
for(int i = 1; i <= n; i++) if(ans[i] < minn) minn = ans[i], pl = i;
cout << pl << "\n";
return 0;
}
B. Serval and Toy Bricks
- 贪心每个位置假如能放, 就放横看数看的较小值
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<iostream>
#define ll long long
#define M 110
#define mmp make_pair
using namespace std;
int read() {
int nm = 0, f = 1;
char c = getchar();
for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
return nm * f;
}
int a[M][M], h[M], l[M];
int main() {
int x = read(), y = read(), z = read();
for(int i = 1; i <= y; i++) h[i] = read();
for(int i = 1; i <= x; i++) l[i] = read();
for(int i = 1; i <= x; i++) for(int j = 1; j <= y; j++) a[i][j] = read();
for(int i = 1; i <= x; i++) for(int j = 1; j <= y; j++) if(a[i][j]) a[i][j] = min(l[i], h[j]);
for(int i = 1; i <= x; i++) {
for(int j = 1; j <= y; j++) cout << a[i][j] << " ";
cout << "\n";
}
return 0;
}
C. Serval and Parenthesis Sequence
- 转化成第一个括号一定要和最后一个括号匹配, 对于2到n-1位置的串进行构造即可
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<iostream>
#define ll long long
#define M 300010
#define mmp make_pair
using namespace std;
int read() {
int nm = 0, f = 1;
char c = getchar();
for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
return nm * f;
}
char s[M];
int n;
int main() {
n = read();
scanf("%s", s + 1);
if(n & 1) return 0 * puts(":(");
if(s[1] == ')' || s[n] == '(') return 0 * puts(":(");
s[1] = '(', s[n] = ')';
int tot = n - 2, a = 0, b = 0, c;
for(int i = 2; i < n; i++) {
if(s[i] == '(') a++;
else if(s[i] == ')') b++;
else c++;
}
if(a > tot / 2 || b > tot / 2) return 0 * puts(":(");
a = tot / 2 - a;
for(int i = 2; i < n; i++) {
if(s[i] == '?') {
if(a) s[i] = '(', a--;
else s[i] = ')';
}
}
int cnt = 0;
for(int i = 2; i < n; i++) {
if(s[i] == '(') cnt++;
else cnt--;
if(cnt < 0) return 0 * puts(":(");
}
puts(s + 1);
return 0;
}
D. Serval and Rooted Tree
- 树形dp, 考虑dp每颗子树的影响, 最大值的话选择影响最小的, 最小值的话影响求和
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<iostream>
#define ll long long
#define M 300010
#define mmp make_pair
using namespace std;
int read() {
int nm = 0, f = 1;
char c = getchar();
for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
return nm * f;
}
int n, ver[M], fa[M], k, f[M];
vector<int> to[M];
bool cmp(int a, int b) {
return f[a] < f[b];
}
void dfs(int now) {
for(int i = 0; i < to[now].size(); i++) {
int vj = to[now][i];
dfs(vj);
}
if(to[now].size() == 0) {
f[now] = 1;
return;
}
sort(to[now].begin(), to[now].end(), cmp);
if(ver[now]) {
f[now] = f[to[now][0]];
} else {
for(int i = 0; i < to[now].size(); i++) f[now] += f[to[now][i]];
}
}
int main() {
n = read();
for(int i = 1; i <= n; i++) ver[i] = read();
for(int i = 2; i <= n; i++) fa[i] = read(), to[fa[i]].push_back(i);
for(int i = 2; i <= n; i++) if(to[i].size() == 0) k++;
dfs(1);
cout << k - f[1] + 1<< "\n";
return 0;
}
E. Serval and Snake
- 先枚举找到边界, 然后二分找位置
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<iostream>
#define ll long long
#define M 101
#define mmp make_pair
using namespace std;
bool rev = false;
vector<int>row, col;
int ask(int x1, int y1, int x2, int y2) {
if(rev) {
swap(x1, y1);
swap(x2, y2);
}
cout << "? " << x1 + 1 << ' ' << y1 + 1 << ' ' << x2 + 1 << ' ' << y2 + 1 << endl;
int res;
cin>>res;
return res;
}
void answer(int x1, int y1, int x2, int y2) {
if(rev) {
swap(x1, y1);
swap(x2, y2);
}
cout << "! " << x1 + 1 << ' ' << y1 + 1 << ' ' << x2 + 1 << ' ' << y2 + 1 << endl;
}
int main() {
int n;
cin>>n;
for(int i = 0; i < n; i++) {
int res = ask(i, 0, i, n - 1);
if(res % 2 == 1)row.push_back(i);
res = ask(0, i, n - 1, i);
if(res % 2 == 1)col.push_back(i);
}
vector<pair<int, int> >ans;
if(row.size() == 2 && col.size() == 2) {
for(int x:row)for(int y:col) {
if(ask(x, y, x, y) % 2 == 1) {
ans.push_back(mmp(x, y));
}
}
answer(ans[0].first, ans[0].second, ans[1].first, ans[1].second);
return 0;
}
if(row.size() == 0) {
rev = true;
swap(row, col);
}
int ok = n - 1, ng = - 1;
while(ok - ng>1) {
int t = (ok + ng)/2;
if(ask(0, 0, row[0], t) % 2 == 1)ok = t;
else ng = t;
}
answer(row[0], ok, row[1], ok);
return 0;
}
Codeforces Round #551 (Div. 2) A-E的更多相关文章
- 【Codeforces】Codeforces Round #551 (Div. 2)
Codeforces Round #551 (Div. 2) 算是放弃颓废决定好好打比赛好好刷题的开始吧 A. Serval and Bus 处理每个巴士最早到站且大于t的时间 #include &l ...
- Codeforces Round #551 (Div. 2) 题解
CF1153A 直接做啊,分类讨论即可 #include<iostream> #include<string.h> #include<string> #includ ...
- Codeforces Round #551 (Div. 2) D. Serval and Rooted Tree (树形dp)
题目:http://codeforces.com/contest/1153/problem/D 题意:给你一棵树,每个节点有一个操作,0代表取子节点中最小的那个值,1代表取子节点中最大的值,叶子节点的 ...
- C. Serval and Parenthesis Sequence 【括号匹配】 Codeforces Round #551 (Div. 2)
冲鸭,去刷题:http://codeforces.com/contest/1153/problem/C C. Serval and Parenthesis Sequence time limit pe ...
- Codeforces Round #551 (Div. 2) E 二分 + 交互
https://codeforces.com/contest/1153/problem/E 题意 边长为n的正方形里面有一条蛇,每次可以询问一个矩形,然后会告诉你蛇身和矩形相交有几部分,你需要在最多2 ...
- Codeforces Round #551 (Div. 2) D 树形dp
https://codeforces.com/contest/1153/problem/D 题意 一颗有n个点的数,每个点a[i]为0代表取子节点的最小,1代表取最大,然后假设树上存在k个叶子,问你如 ...
- Codeforces Round #551 (Div. 2)
传送门 B. Serval and Toy Bricks 题意: 有一些规格相同的方块摆放在 n×m 的矩阵 h 中,h[i][j]代表第 (i,j) 个矩阵摆放的方块的高度: 现给你三个视图: 正视 ...
- Codeforces Round #551 (Div. 2) D. Serval and Rooted Tree (树形dp)
题目链接 题意:给你一个有根树,假设有k个叶子节点,你可以给每个叶子节点编个号,要求编号不重复且在1-k以内.然后根据节点的max,minmax,minmax,min信息更新节点的值,要求根节点的值最 ...
- Codeforces Round #551 (Div. 2) EF Solution
E. Serval and Snake 对于一个矩形,如果蛇的一条边与它相交,就意味着这条蛇从矩形内穿到矩形外,或者从矩形外穿到矩形内.所以如果某个矩形的答案为偶数,意味着蛇的头尾在矩形的同一侧(内或 ...
随机推荐
- jvm-垃圾收集
概述 说起垃圾收集,大部分人都把这项技术当做Java语言的伴生产物.其实,GC主要就是考虑完成三件事情: 哪些内存需要回收 什么时候回收 如何回收. 经过半个多世纪的发展,目前内存的动态分配与内存的回 ...
- cocos2d-x学习笔记(斗地主代码)
满足百度百科上的出牌规则,电脑可以随着玩家出牌. 百度网盘地址:链接: https://pan.baidu.com/s/1eRLpvJ8 提取密码: tf8w
- 《JavaScript Dom 编程艺术》读书笔记-第5章
上一篇随笔中记录了用JavaScript建一个基础图片库,但实际上还有很多地方可以改进.第五章将逐步进行改进,这一章里需要明白的道理是达到目标的过程和达到目标同样重要~ 第五章:最佳实践 5.1 过去 ...
- 2/18 (pycharm 快捷键、循环、join语句)
Alt + Enter 快速修正 Ctrl + / 行注释/取消行注释 Ctrl + Shift + / 块注释 Ctrl + Alt + I 自动缩进 CTRL + D 复制选定的区域或 ...
- 2017年4月7日16:18:17 java8 常用记录
List<String> customerUids = customerTagModel.stream().map(CustomerTagModel::getCustomerUid) ...
- openFileDialog的使用
这两天应用了一下openFileDialog,做的是上传的功能,在打开页面的时候进行的一系列操作虽说远远没有asp.net的上传控件好使,但是学习起来也是蛮还用的,下面是一个简单的应用 //点击浏览按 ...
- Linux分区知识及企业场景分区76
文件系统就相当于装修一样.这个硬盘拿过来了,分完区了,没有格式化. 没有格式化就相当于没有装修.[分区]不是必须的. 如果没有文件系统就不能放数据,文件系统可以理解为一个软件, 它的实现形式是软件,这 ...
- CDMA码片序列问题
要想知道到底是怎么算的 建议看见这篇博客的任何一位去先看一下这篇博客:https://blog.csdn.net/dog250/article/details/6420427 在CDMA中.每一个比特 ...
- python学习之路04——列表和字典
列表和字典 python中的可变数据类型有:列表和字典 不可变类型:数字,字符串,元组 今天先讲列表和字典 一.列表 1.概念: 变量:使用变量存储数据,但是,变量存储数据每次只能存储一个数据 问题: ...
- 2分钟理解文件IO -我对文件IO的理解与实验对比
本文介绍了不同的IO方式以及他们之间的效率比较 1.一次读取写入单个字节(读取400M的文件浪费了很久,等了很久没读取完成,证明其效率很差) public class CopyFileDemo { p ...