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 对于一个矩形,如果蛇的一条边与它相交,就意味着这条蛇从矩形内穿到矩形外,或者从矩形外穿到矩形内.所以如果某个矩形的答案为偶数,意味着蛇的头尾在矩形的同一侧(内或 ...
随机推荐
- linux软件管理 源码包
源码包安装位置 安装在指定位置当中,一般是 /usr/local/软件名/ 注意: 需要指定安装路劲为了便于卸载,因为源码包的是没有卸载命令的,它的的卸载方式就是把对应安装文件夹删除了. 所以如果 ...
- decode encode
https://blog.csdn.net/crylearner/article/details/38521685,python常用的十进制.16进制.字符串.字节串之间的转换
- redis-cluster配置
为什么要用redis-cluster 1.并发问题 redis官方生成可以达到 10万/每秒,每秒执行10万条命令假如业务需要每秒100万的命令执行呢? 2.数据量太大 一台服务器内存正常是16~25 ...
- http协议文件与数据上传、及上传图片io流错误
package com.smartdoer.utils; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; im ...
- Android : 跟我学Binder --- (4) 驱动情景分析
目录: Android : 跟我学Binder --- (1) 什么是Binder IPC?为何要使用Binder机制? Android : 跟我学Binder --- (2) AIDL分析及手动实现 ...
- linux c++ curl 根据IP地址获得当前网络的所在的地理位置
注意: 可能每个电脑的默认中文编码格式不同,有时会出现乱码,需要对返回内容进行编码转换,或者换成可指定编码格式的接口.如 搜狐IP地址查询接口(可设置编码):http://pv.sohu.com/c ...
- SharePoint Framework 基于团队的开发(一)
博客地址:http://blog.csdn.net/FoxDave SharePoint Framework是新的用来构建SharePoint自定制的开发模型,它专注于客户端开发并用热门的开源工具gu ...
- 判断是不是微信浏览器和QQ内置浏览器
is_weixn() { let ua = navigator.userAgent.toLowerCase(); if (ua.match(/MicroMessenger/i) == "mi ...
- SpringMVC + MyBatis分库分表方案
mybatis作为流行的ORM框架,项目实际使用过程中可能会遇到分库分表的场景.mybatis在分表,甚至是同主机下的分库都可以说是完美支持的,只需要将表名或者库名作为动态参数组装sql就能够完成.但 ...
- 认识:人工智能AI 机器学习 ML 深度学习DL
人工智能 人工智能(Artificial Intelligence),英文缩写为AI.它是研究.开发用于模拟.延伸和扩展人的智能的理论.方法.技术及应用系统的一门新的技术科学. 人工智能是对人的意识. ...