Codeforces Round #551 (Div. 2) 算是放弃颓废决定好好打比赛好好刷题的开始吧 A. Serval and Bus 处理每个巴士最早到站且大于t的时间 #include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ')…
冲鸭,去刷题:http://codeforces.com/contest/1153/problem/C C. Serval and Parenthesis Sequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Serval soon said goodbye to Japari kindergarten, and b…
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…
突然发现上一场没有写,那就补补吧 本来这场应该5题的,结果一念之差E fail了 A. Serval and Bus 基本数学不解释,假如你没有+1 -1真的不好意思见人了 #include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> using namespace std; con…
题目:http://codeforces.com/contest/1153/problem/D 题意:给你一棵树,每个节点有一个操作,0代表取子节点中最小的那个值,1代表取子节点中最大的值,叶子节点的话就是自己置一个值,有k个子节点,那么每个子节点的值范围 就是1-k,1-k只能用一次 思路:贪心不好取,我肯定是要排列完才知道当前的值是哪个,但是我可以知道当前节点应该是取子节点中排名第几的那个,从而推出根节点1的排名,然后再输出就行,因为是要从 子节点那里递归上来,所以我们采取树形dp #inc…
A. Serval and Bus time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output It is raining heavily. But this is the first day for Serval, who just became 3 years old, to go to the kindergarten. Unfort…
B. Serval and Toy Bricks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Luckily, Serval got onto the right bus, and he came to the kindergarten on time. After coming to kindergarten, he fo…
题目链接 题意:给你一个有根树,假设有k个叶子节点,你可以给每个叶子节点编个号,要求编号不重复且在1-k以内.然后根据节点的max,minmax,minmax,min信息更新节点的值,要求根节点的值最大. 解法:考虑树形dp,若当前节点是nownownow,我们可以假设编号最大的一些数分布在当前节点的子节点中,显然,若当前节点为叶子节点,那么这个这个编号就是最大的.然后往上回溯,假设当前节点取得是maxmaxmax,那么就从子节点中取最大的数为当前节点的答案,如果取得是minminmin的话,就…
人生第一次交互题ac! 其实比较水 容易发现如果查询的矩阵里面包含一个端点,得到的值是奇数:否则是偶数. 所以只要花2*n次查询每一行和每一列,找出其中查询答案为奇数的行和列,就表示这一行有一个端点. 令cntr表示答案为奇数的行数,cntc表示答案为奇数的列数. 那么cntr只能为0或者2,0就表示两个头在同一行,2就表示两个头在不同的行(我们已经找出这两行了) cntc亦然. 然后cntr与cntc不可能同时为0,因为两个端点不可能既在同一行又在同一列. 所以对于cntr=cntc=2的,我…
yyb大佬的博客 这线段期望好神啊... 还有O(nlogn)FFTO(nlogn)FFTO(nlogn)FFT的做法 Freopen大佬的博客 本蒟蒻只会O(n2)O(n^2)O(n2) CODE #include <bits/stdc++.h> using namespace std; const int mod = 998244353; typedef long long LL; const int MAXN = 4005; inline void add(int &x, int…
CF1153A 直接做啊,分类讨论即可 #include<iostream> #include<string.h> #include<string> #include<stdio.h> #include<algorithm> #include<math.h> #include<vector> #include<queue> #include<map> #include<set> usin…
传送门 B. Serval and Toy Bricks 题意: 有一些规格相同的方块摆放在 n×m 的矩阵 h 中,h[i][j]代表第 (i,j) 个矩阵摆放的方块的高度: 现给你三个视图: 正视图:给出 m 个数据,第 i 个数据 f[ i ] 代表第 i 列方块的最大高度: 左视图:给出 n 个数据,第 i 个数据 l[ i ] 代表第 i 行方块的最大高度: 俯视图:给出 n×m 个数据,只有两个取值,第(i,j)个数据 top[ i ][ j ] 为0代表第(i,j)处无方块,为1代…
E. Serval and Snake 对于一个矩形,如果蛇的一条边与它相交,就意味着这条蛇从矩形内穿到矩形外,或者从矩形外穿到矩形内.所以如果某个矩形的答案为偶数,意味着蛇的头尾在矩形的同一侧(内或外),否则意味着头和尾中一个在矩形内,一个在矩形外. 所以可以通过 for(int i = 2 ; i <= n ; ++i) ? i 1 n n 来询问出头和尾的横坐标.询问的答案从偶数变为奇数和从奇数变为偶数的位置就是头和尾分别的横坐标.对于纵坐标也这样做一遍. 可能存在头和尾在一条水平或者垂直…
https://codeforces.com/contest/1153/problem/E 题意 边长为n的正方形里面有一条蛇,每次可以询问一个矩形,然后会告诉你蛇身和矩形相交有几部分,你需要在最多2019询问中知道蛇的头和尾 题解 假如相交奇数部分,那么头和尾一定有一个在矩形里面,假如为偶数部分,头和尾都在里面或者都不在 利用上述性质,对每一行进行询问即(1,1)(i,n) (999次) 假如存在头尾不在同一行,则对列进行两次二分就可以分别找到头和尾(2*10次) 假如头尾在同一行,那么就要从…
https://codeforces.com/contest/1153/problem/D 题意 一颗有n个点的数,每个点a[i]为0代表取子节点的最小,1代表取最大,然后假设树上存在k个叶子,问你如何将1~k分配给叶子节点使得根节点最大 题解 实际上最后只有一个值能到达根,我们需要计算没用的叶子节点数量 min:相当于将子节点叶子数量相加 max:相当于将子节点叶子数量取最小 ans=叶子数-sz[1]+1 代码 #include<bits/stdc++.h> #define MAXN 30…
#define HAVE_STRUCT_TIMESPEC#include <bits/stdc++.h>using namespace std;int val[300007],num[300007],ans=0;vector<int>v[300007];void dfs(int u){ if(v[u].size()==0){ num[u]=1; ans++; return; } int tmp=0; for(int i=0;i<v[u].size();i++){ int vv…
题目地址:CF1153C Serval and Parenthesis Sequence 思路:贪心 如果有解,那么 \(s_0 = (\) && \(s_{n-1} = )\) && \(n % 2 = 0\) . 如果有解,那么 \(s_1\) ~ \(s_{n-2}\) 为一个合法的括号序列. 那么已知的 \((\) 和 \()\) 个数不能超过一半 接下来贪心:如果有解,那么一定有一组解是把 \(?\) 中左边一部分填成 \((\) ,右边一部分填成 \()\) ,…
2016湖南省赛----G - Parenthesis (括号匹配)   Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of length n and q questions. The i-th question is whether P remains balanced after p ai and p bi  swapped. Note that questions are individual so that they hav…
Serval and Parenthesis Sequence 题目链接(点击) Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is…
Codeforces Round #529 (Div. 3) 题目传送门 题意: 给你由左右括号组成的字符串,问你有多少处括号翻转过来是合法的序列 思路: 这么考虑: 如果是左括号 1)整个序列左括号个数比右括号多 2 2)在这个位置之前,所有位置的前缀左括号个数都不少于前缀右括号个数 3)在这个位置和这个位置之后,在修改后所有位置的前缀左括号个数减去前缀右括号个数大于2 (这里这么想,把左变成右,左-1,右+1) 右括号也是这样 代码: #include<bits/stdc++.h> usi…
Codeforces Round #529(Div.3)个人题解 前言: 闲来无事补了前天的cf,想着最近刷题有点点怠惰,就直接一场cf一场cf的刷算了,以后的题解也都会以每场的形式写出来 A. Repeating Cipher 传送门 题意:第一个字母写一次,第二个字母写两次,依次递推,求原字符串是什么 题解:1.2.3.4,非常明显的d=1的等差数列,所以预处理一个等差数列直接取等差数列的每一项即可 代码: #include<bits/stdc++.h> using namespace s…
题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60949 ....看不懂 设dp[i][j][l]表示前i位,左括号-右括号=j,匹配到l了 状态转移,枚举下一个要填的括号,用next数组求状态的l,分别转移 代码 #include<bits/stdc++.h> using namespace std; const int maxn = 207;…
Codeforces Round #556 (Div. 1) A. Prefix Sum Primes 给你一堆1,2,你可以任意排序,要求你输出的数列的前缀和中质数个数最大. 发现只有\(2\)是偶质数,那么我们先放一个\(2\),再放一个\(1\),接下来把\(2\)全部放掉再把\(1\)全部放掉就行了. #include<iostream> #include<cstdio> using namespace std; inline int read() { int x=0;bo…
A. IQ Test 模拟. B. Pipeline 贪心. C. Lucky Permutation 每4个数构成一个循环. 当n为偶数时,n=4k有解:当n为奇数时,n=4k+1有解. D. Shifting 本质相当于每次把每段的首个数字移动到下段的首部. E. Main Sequence 括号匹配. D. Tourists 对于每个询问\(q\)来说,被墙的挡住的位置满足\(l_i\le x\le r_i,t_i\le q+x\),即\(max\{l_i,t_i-q\}\le x \le…
A. Even Subset Sum Problem 题意 给出一串数,找到其中的一些数使得他们的和为偶数 题解 水题,找到一个偶数或者两个奇数就好了 代码 #include<iostream> #include<cstdio> #include<cstring> #define def 110 using namespace std; long a[def]; int main() { long _,ans0,ans1,ans2,n,i; for(scanf(&quo…
Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题解 A - Distance and Axis B - Ternary Sequence C - Mere Array D - Maximum Distributed Tree E - Divide Square F - Reverse and Swap A - Distance and Axis…
 cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....       其实这个应该是昨天就写完的,不过没时间了,就留到了今天.. 地址:http://codeforces.com/contest/651/problem/A A. Joysticks time limit per test 1 second memory limit per test 256…
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard in…
Codeforces Round #110 (Div. 2) C. Message 题意 给两个长度不超过2000的字符串\(s,u\),仅由小写字母构成. 找出\(s\)的一个子串\(t\),通过3种操作变换成字符串\(u\): 在首或尾添加一个字符; 删除首或尾的一个字符; 改变某个位置的字符. 求最小的操作步数. 思路 因为删除.插入的代价和修改的代价一样,显然找出和\(u\)长度一样的子串\(t\)可以求得最小代价. 显然\(u\)可以只匹配\(s\)的一个前缀或后缀,可以通过在\(s\…
Vasiliy's Multiset 题目链接: http://codeforces.com/contest/706/problem/D Description Author has gone out of the stories about Vasiliy, so here is just a formal task description. You are given q queries and a multiset A, initially containing only integer…