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的更多相关文章

  1. 【Codeforces】Codeforces Round #551 (Div. 2)

    Codeforces Round #551 (Div. 2) 算是放弃颓废决定好好打比赛好好刷题的开始吧 A. Serval and Bus 处理每个巴士最早到站且大于t的时间 #include &l ...

  2. Codeforces Round #551 (Div. 2) 题解

    CF1153A 直接做啊,分类讨论即可 #include<iostream> #include<string.h> #include<string> #includ ...

  3. Codeforces Round #551 (Div. 2) D. Serval and Rooted Tree (树形dp)

    题目:http://codeforces.com/contest/1153/problem/D 题意:给你一棵树,每个节点有一个操作,0代表取子节点中最小的那个值,1代表取子节点中最大的值,叶子节点的 ...

  4. 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 ...

  5. Codeforces Round #551 (Div. 2) E 二分 + 交互

    https://codeforces.com/contest/1153/problem/E 题意 边长为n的正方形里面有一条蛇,每次可以询问一个矩形,然后会告诉你蛇身和矩形相交有几部分,你需要在最多2 ...

  6. Codeforces Round #551 (Div. 2) D 树形dp

    https://codeforces.com/contest/1153/problem/D 题意 一颗有n个点的数,每个点a[i]为0代表取子节点的最小,1代表取最大,然后假设树上存在k个叶子,问你如 ...

  7. Codeforces Round #551 (Div. 2)

    传送门 B. Serval and Toy Bricks 题意: 有一些规格相同的方块摆放在 n×m 的矩阵 h 中,h[i][j]代表第 (i,j) 个矩阵摆放的方块的高度: 现给你三个视图: 正视 ...

  8. Codeforces Round #551 (Div. 2) D. Serval and Rooted Tree (树形dp)

    题目链接 题意:给你一个有根树,假设有k个叶子节点,你可以给每个叶子节点编个号,要求编号不重复且在1-k以内.然后根据节点的max,minmax,minmax,min信息更新节点的值,要求根节点的值最 ...

  9. Codeforces Round #551 (Div. 2) EF Solution

    E. Serval and Snake 对于一个矩形,如果蛇的一条边与它相交,就意味着这条蛇从矩形内穿到矩形外,或者从矩形外穿到矩形内.所以如果某个矩形的答案为偶数,意味着蛇的头尾在矩形的同一侧(内或 ...

随机推荐

  1. Jmeter对HTTP请求压力测试、并发测试的简单使用方法

    对于服务器性能测试这块的经验更是少得可以忽略.迫使不得不让我们去尝试了解测试的知识. 首先我们的需求场景如下: 服务器硬件:(只有一台) 系统:Windows 2003 WebServer:Tomca ...

  2. tensorFlow(五)深层神经网络

    TensorFlow基础见前博客 上实例: MNIST 数据集介绍 MNIST 是一个手写阿拉伯数字的数据集. 其中包含有 60000 个已经标注了的训练集,还有 10000 个用于测试的测试集. 本 ...

  3. jQuery键盘敲击事件,换键的话换键码就可以

    $("body").keyup(function () { if (event.which == 13){ $("#Btn_login").trigger(&q ...

  4. [ZJOI2007]最大半联通子图

    这个题,翻译一下题面,就是一个连通图,找他的最长链的数量... 所以说方法就比较明显了:tarjan缩点+拓扑+DP 注意也是本题唯一坑点,拓扑DP的时候要考虑重复边的情况... 呆码: #inclu ...

  5. MySQL:数据查询

    数据查询 一.基本查询语句 1.语法:写一行 select{*<字段列表>}//查询的字段,多个字段用逗号分开 from<表1>,<表2>…//数据表名 {//可选 ...

  6. OLAP了解与OLAP引擎——Mondrian入门

    一.  OLAP的基本概念 OLAP(On-Line Analysis Processing)在线分析处理是一种共享多维信息的快速分析技术:OLAP利用多维数据库技术使用户从不同角度观察数据:OLAP ...

  7. 2019-04-15-day032-多进程介绍

    内容回顾 基于原生socket的udp协议实现将client端发送过来的消息放到字典中 字典的key是所有客户端的地址,value是一个列表 io :输入输出, 输入到内存,向内存输入 从内存中向外( ...

  8. day 12 名称空间和闭包函数

    函数嵌套 按照函数的两个阶段分为: 嵌套调用:在一个函数内部调用另一个函数 嵌套定义:在一个函数内部定义另一个函数 名称空间(namespace):存储名字的内存区域 名称空间的分类: 内置名称空间: ...

  9. Ubuntu 17.10 安装Caffe(cpu)并配置Matlab接口

    (1)安装依赖: sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-ser ...

  10. Javascript Canvas验证码

    用Canvas画的验证码,效果图如下 1.验证码的JS代码,保存到一个名称是validatedCode.js的文件内,代码如下: (function(window,document){ functio ...