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 对于一个矩形,如果蛇的一条边与它相交,就意味着这条蛇从矩形内穿到矩形外,或者从矩形外穿到矩形内.所以如果某个矩形的答案为偶数,意味着蛇的头尾在矩形的同一侧(内或 ...
随机推荐
- app性能测试指标
性能测试在软件的质量保证中起着重要的作用,它包括的测试内容丰富多样.中国软件评测中心将性能测试概括为三个方面:应用在客户端性能的测试.应用在网络上性能的测试和应用在服务器端性能的测试.通常情况下,三方 ...
- leetcode python 010
#实现正则表达式匹配并支持'.'和'*'.#''匹配任何单个字符.#'*'匹配前面元素的零个或多个.#匹配应覆盖整个输入字符串(非部分).##Some examples:##isMatch(" ...
- 组队项目,Main队伍
本小组经过讨论,决定做的项目为----厨娘 分组情况: 1.界面设计:胡骏 2.前段,界面代码实现:梅庆 3.后台.逻辑处理:唐正奎.张军洪.袁成杰 4.数据库的建立与存写:张军洪.蒋利平 厨娘——需 ...
- nginx——控制 Nginx 并发连接数
1. 限制单个 IP 的并发连接数 .... http { include mime.types; default_type application/octet-stream; sendfile on ...
- 剑指Offer 51. 构建乘积数组 (数组)
题目描述 给定一个数组A[0,1,...,n-1],请构建一个数组B[0,1,...,n-1],其中B中的元素B[i]=A[0]*A[1]*...*A[i-1]*A[i+1]*...*A[n-1].不 ...
- s21day11 python笔记
s21day11 python笔记 一.函数小高级 函数名可以当作变量来使用 #示例一: def func(): print(123) func_list = [func, func, func] # ...
- 熟悉基本的Linux文件系统命令
修改配置是以后工作中必然经历的,要做好基础工作,两天的学习也说明了在Linux系统中修改配置的重要性,多看多学习. 每周总结学习和经验到网站上,坚持1w个小时,加油! Linux的安装环境 cen ...
- Web.xml详解分析
一.首先了解项目加载的优先级 首先可以肯定的是,加载顺序与它们在 web.xml 文件中的先后顺序无关.即不会因为 filter 写在 listener 的前面而会先加载 filter. 最终得出的结 ...
- js··事件捕捉
给一个元素绑定事件,普通写法是 obj.onclick=function(){} 这就相当于给obj的onclick属性赋值是一个道理. obj.onclick=function(){} 这种写法有一 ...
- PythonStudy——比较运算符 Comparison operator
1.运算结果为bool类型 print(3 > 5) Output: False 2.可以连比 num = 10 print(1 < num < 20)# 与之上的等价写法是: pr ...