Codeforces Round #620 (Div. 2) A. Two Rabbits 题意 两只兔子相向而跳,一只一次跳距离a,另一只一次跳距离b,每次同时跳,问是否可能到同一位置 题解 每次跳相对距离减少Δ=(a+b)\Delta=(a+b)Δ=(a+b),如果总距离是Δ\DeltaΔ的倍数,就证明可以到同一位置 代码 #include<iostream> #include<cstdio> using namespace std; int main() { long N,x…
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; ]; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin>>t; while(t--){ int n; string s; cin>>n>>s; int mx=n; ;i<n;++i){…
题:https://codeforces.com/contest/1304/problem/D 题意:给定长度为n-1的只含’>'和‘<’的字符串,让你构造出俩个排列,俩个排列相邻的数字之间要满足这个字符串,找出的俩个要是最小化最长上升子序列,和最大化最长上升子序列: 分析:dilworld定理,最长下降子序列个数等于最长上升子序列的长度 先说构造最小的,LIS的长度就等于最长的连续'<'的长度加1,贪心地把最大的数放在最前面: 构造最大的就把最小的数尽可能放在前面…
E. LIS of Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/486/problem/E Description The next "Data Structures and Algorithms" lesson will be about Longest Increasing Subsequence (LIS for short) of a sequence.…
C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative…
构造一个排列,要求相邻之间的数满足给定的大小关系,然后构造出两个序列,一个序列是所有可能的序列中LIS最长的,一个所有可能的序列中LIS最短的 最短的构造方法:我们考虑所有单调递增的部分,可以发现要让他LIS最小那么就必须要让每一个部分满足前面的比后面的大 最长的构造方法:考虑单调递减的部分,每一个部分都只能选择一个,因此我们要满足后面的部分的值都比前面的大 代码是官方题解的,自己写了半天写不出来 #include <bits/stdc++.h> using namespace std; co…
A. Two Rabbits (手速题) #include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ int t; cin>>t; while(t--){ ll x,y,a,b; cin>>x>>y>>a>>b; ll sum = a+b; ){ cout<<(y-x)/sum<<endl; } else{ cou…
题:https://codeforces.com/contest/1304/problem/E 题意:给定一颗树,边权为1,m次询问,每次询问给定x,y,a,b,k,问能否在原树上添加x到y的边,a到b的路径长度等于k,注意这里的点和边都是可以重复走的: 分析:注意到点边可以重复走,我们就可以推出一个条件就是a.b之间的长度len要满足>=k: 其次当路长大于k时,我们就要判断len和k是否同奇偶,因为要到达长度len要被分为:len=k+2*i(i>=0),否则无法构造出这么一条路径 然后添…
A. Array 题目连接: http://www.codeforces.com/contest/300/problem/A Description Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: The product of all numbers in the…
A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全,最后只能很蠢的暴力,把所有的AB和BA的位置求出来,能有一对AB和BA不重叠即可. #include <bits/stdc++.h> using namespace std; ]; vector<int> ab; vector<int> ba; int main() { w…
D. Handshakes Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/problem/D Description On February, 30th n students came in the Center for Training Olympiad Programmers (CTOP) of the Berland State University. They came one…
这道题直接去构造答案即可. 对于l的二进制表示,从右到左一位一位的使其变为1,当不能再变了(再变l就大于r了)时,答案就是l. 这种方法既可以保证答案大于等于l且小于等于r,也可以保证二进制表示时的1最多. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<cmath> #include&l…
Being tired of participating in too many Codeforces rounds, Gildong decided to take some rest in a park. He sat down on a bench, and soon he found two rabbits hopping around. One of the rabbits was taller than the other. He noticed that the two rabbi…
A. Two Rabbits 思路: 很明显,如果(y-x)%(a+b)==0的话ans=(y-x)/(a+b),否则就为-1 #include<iostream> #include<algorithm> using namespace std; +; int main(){ int k; scanf("%d",&k); while(k--){ long long x,y,a,b,ans; cin>>x>>y>>a&g…
题意:构造一个\(n\)x\(n\)只含\(0\)和\(k\)个\(1\)的矩阵,统计每一行每一列\(1\)的sum,然后构造一个权值最大行和最小行的差的平方加权值最大列和最小列的差的平方的最小和(\(f(A)=(max(R)-min(R))^2+(max(C)-min(C))^2\)的最小值). 题解:假如\(k\ mod\ n=0\)的话,那么最小值一定是0,否则一定是2,直接上图吧. ​ 1.k%n=0: ​ 2.k%n!=0: 这样的话,规律应该显而易见了吧,我们沿着对角线构造,然后取余…
现在有一个长度为n的数列 n不超过4000 求出它的gcd生成set 生成方式是对<i,j> insert进去(a[i] ^ a[i+1] ... ^a[j]) i<=j 然而现在给你了set 规模m<=1000 求原数列或check不可行 可以想到set中的max数字一定是原数列中的max , min数字一定是所有数字的因子 然而这样就走不下去了,没法通过枚举n或者什么来确定是否存在 一通乱想之后想出来了奇妙的解法.. 解:最小的数字为x 那么原数列中所有的数字都是x的倍数 它们…
LCA求树上两点最短距离,如果a,b之间距离小于等于k并且奇偶性与k相同显然YES:或者可以从a先走到x再走到y再走到b,并且a,x之间距离加b,y之间距离+1小于等于k并且奇偶性与k相同也输出YES:或者从a走到y再走到x再走到b,并且总距离+1小于等于k并且奇偶性与k相同同样输出YES:否则输出NO. #define HAVE_STRUCT_TIMESPEC #include <bits/stdc++.h> using namespace std; ]; int cnt; struct e…
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin>>t; while(t--){ long long n,m; cin>>n>>m; ; ans=(n*(n+))>>;//总方案数(无论…
LCA的倍增 模板: ], depth[maxn]; int dist[maxn],head[maxn]; void add(int u,int v,int dist0){ a[tot].next=head[u]; a[tot].dist=dist0; a[tot].v=v; head[u]=tot++; } void dfs(int u,int fa,int d) { fath[u][]=fa; depth[u]=d; ;i<;i++) fath[u][i]=fath[fath[u][i-]]…
Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it. Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges…
Returning back to problem solving, Gildong is now studying about palindromes. He learned that a palindrome is a string that is the same as its reverse. For example, strings "pop", "noon", "x", and "kkkkkk" are palin…
题意:给出n,和m表示有n天,m块区域,每块区域都有一定数论的动物数量,k表示可以在这一天中观察[x,max(x+k-1,m)]的区域内的动物,有俩台相机,一台只能在偶数天用,另一台则是在奇数天用,每用一次就得在那个区域内待俩天,相邻的要是有重复的区域,该区域内的动物数只计数一次,问最多有可能的动物数目是多少 分析:因为n<=50,m<=20000,所以我们考虑一下dp[n][m],dp[i][j]表示:在第 i 天选择[j,j+k-1]区域拍摄的最大拍摄量. 因为是连续拍摄俩天,所以我们可以…
题意:有一个长度为偶数只含\(0\)和\(1\)的序列,你可以移除最多\(\frac{n}{2}\)个位置的元素,使得操作后奇数位置的元素和等于偶数位置的元素和,求新序列. 题解:统计\(0\)和\(1\)的个数,如果\(0\)的个数大于\(\frac{n}{2}\),那么直接输出\(n/2\)个\(0\),否则输出所有\(1\)(个数必须为偶). 代码: int t; int n; int a[N]; int main() { //ios::sync_with_stdio(false);cin…
题目传送门 /* 题意:在n^n的海洋里是否有k块陆地 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 输出完k个L后,之后全部输出S:) 5 10 的例子可以是这样的: LSLSL SLSLS LSLSL SLSLS SSSSS */ #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <string> usi…
题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数)为k个.求序列. 思路:1~k+1.构造序列前段,之后直接输出剩下的数.前面的构造能够依据,两项差的绝对值为1~k构造. AC代码: #include <stdio.h> #include <string.h> int ans[200010]; bool vis[100010]; i…
Codeforces Round #275 (Div. 1)A. Diverse Permutation Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/482/problem/A Description Permutation p is an ordered set of integers p1,   p2,   ...,   pn, consisting of n distinct posi…
题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; ; const int INF = 0x3f3f3f3f; int a[MAXN]; int main(void) //Codeforces Round #…
题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少步,按照这个次数之后的能否满足要求 题目读的好累:( */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <cmath>…
题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况讨论一下 */ /************************************************ * Author :Running_Time * Created Time :2015-8-6 0:23:37 * File Name :B.cpp *****************…
题目传送门 /* 题意:删除若干行,使得n行字符串成递增排序 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 */ /************************************************ Author :Running_Time Created Time :2015-8-3 10:49:53 File Name :C.cpp *************************************************/ #in…