人生第一次交互题ac! 其实比较水 容易发现如果查询的矩阵里面包含一个端点,得到的值是奇数:否则是偶数. 所以只要花2*n次查询每一行和每一列,找出其中查询答案为奇数的行和列,就表示这一行有一个端点. 令cntr表示答案为奇数的行数,cntc表示答案为奇数的列数. 那么cntr只能为0或者2,0就表示两个头在同一行,2就表示两个头在不同的行(我们已经找出这两行了) cntc亦然. 然后cntr与cntc不可能同时为0,因为两个端点不可能既在同一行又在同一列. 所以对于cntr=cntc=2的,我…
题目: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的话,就…
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…
A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A sna…
先二分一个区间,再在区间里面二分即可: 可以仔细想想,想明白很有意思的: #include<iostream> #include<cstdio> #include<algorithm> #include<cstdlib> #include<cstring> #include<string> #include<cmath> #include<map> #include<set> #include<…
记录一下第一次写交互题 题目大意:一共有1<<n个人参加一场竞标赛,需要你通过比较两人的胜场来判断谁晋级,最终获得第一名 最多1/3*2^(n+1)次询问,每次询问query(a,b),如果a胜场多返回1,如果b胜场多返回2,相同胜场返回0 找到冠军后输出"! i"(i为冠军的编号) 思路: 每次取四个人一组,因为如果这一组人进行了t轮比赛后,最终有一人胜出,那么他们的胜场将为 [ t , t , t+1 , t+2 ],而且 t 和 t 不能出现在同一组,那么他们的胜场排…
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(' ')…
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  Solved: 2xx 题目连接 http://codeforces.com/contest/525/problem/A Description After a hard day Vitaly got very hungry and he wants to eat his favorite pot…
题目链接:Codeforces Round #298 (Div. 2) A. Exam An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side…
E. Serval and Snake 对于一个矩形,如果蛇的一条边与它相交,就意味着这条蛇从矩形内穿到矩形外,或者从矩形外穿到矩形内.所以如果某个矩形的答案为偶数,意味着蛇的头尾在矩形的同一侧(内或外),否则意味着头和尾中一个在矩形内,一个在矩形外. 所以可以通过 for(int i = 2 ; i <= n ; ++i) ? i 1 n n 来询问出头和尾的横坐标.询问的答案从偶数变为奇数和从奇数变为偶数的位置就是头和尾分别的横坐标.对于纵坐标也这样做一遍. 可能存在头和尾在一条水平或者垂直…
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…
题目 CF1153E Serval and Snake 很有意思的一道交互题 做法 我们观察到,每次查询一行,当这一行仅包含一端是返回的答案是奇数 根据这个性质查询每一行每一列,我们大体能知道两端的位置 查询矩阵时也是这个道理(奇数),可以二分行和列从而得出答案 Code #include<bits/stdc++.h> typedef int LL; LL n; LL fir_1,fir_2,sec_1,sec_2; inline LL Check(LL x,LL y,LL _x,LL _y)…
冲鸭,去刷题: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…
传送门 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代…
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…
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…
A. GukiZ and Contest Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/problem/A Description Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has de…
C. Vladik and fractions 题目链接 http://codeforces.com/contest/743/problem/C 题面 Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer n he can represent fraction as a sum of three distinct posit…
A. Vladik and flights 题目链接 http://codeforces.com/contest/743/problem/A 题面 Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is…
D. Anton and Chess 题目连接: http://codeforces.com/contest/734/problem/D Description Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to…
B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6. Anton's favorite integers are 32 and 256. He decide…
A. Anton and Danik 题目连接: http://codeforces.com/contest/734/problem/A Description Anton likes to play chess, and so does his friend Danik. Once they have played n games in a row. For each game it's known who was the winner - Anton or Danik. None of th…
B. Gena's Code 题目连接: http://www.codeforces.com/contest/614/problem/B Description It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: give…
A. Link/Cut Tree 题目连接: http://www.codeforces.com/contest/614/problem/A Description Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure…