题意: 问一个数组中是否存在至少长为3的回文子数组(按下标排列,可不连续). 思路: 找三个相同数或两个不连续的相同数. #include <bits/stdc++.h> using namespace std; const int M=5500; void solve(){ int last[M]={0},cnt[M]={0}; int n;cin>>n; int a[n+1];for(int i=1;i<=n;i++) cin>>a[i]; for(int i…
题意 : 有n个高度,可以使任一高度加二任意次,问最终n个高度可否相同. 思路: 因为添加的2x1的方块不可旋转,只需考虑所有高度是否为同一奇偶性即可. #include <bits/stdc++.h> using namespace std; void solve(){ int n;cin>>n; int a[n],sum=0; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<n;i++) sum+=a[i]&a…
1324A - Yet Another Tetris Problem(思维) 题意 给一个数组,每一个数组中的元素大小表示在竖直方向的方块数量,元素相邻怎竖直方向的方块也相邻,类似于俄罗斯方块当底层被堆满的时候,那么那一层可以被消去,然后我们可以在任意一个元素(数列)上 + 2 两个小方块,可以放任意多次数,问最终能不能通过这些操作能不能把所有的小方块消去. 思路 思路:我们可以先把底层的能消除的消除,如果消除之后 所给的数组元素中还有奇数,那么无论怎么 操作 都不能 消除完 代码 #inclu…
problem A /* * Author: RoccoShi * Time: 2020-06-07 19:37:51 */ #include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while(t--){ int n, x, y, ans = 0; cin >…
题意: n 个点 n - 1 条边的树,问每个点所在所有子树中白黑点数目的最大差. 思路: 白点先由下至上汇集,后由上至下分并. #include <bits/stdc++.h> using namespace std; const int M=220000; vector<vector<int>> e(M); int n,a[M]; void dfs1(int u,int pre){ for(int v:e[u]){ if(v!=pre){ dfs1(v,u); a[…
题意: 每天有 h 小时,有一序列 an,每次可以选择 ai 或 ai - 1 小时后睡觉,问从 0 次 0 时开始,最多在 l ~ r 时间段入睡多少次. 思路: 如果此时可达,计算此时可达的时间点及其是否位于 l ~ r 区间. #include <bits/stdc++.h> using namespace std; const int M=2200; int dp[M][M]; int main() { int n,h,l,r;cin>>n>>h>>…
题意: 有长为n的a,b两序列,问满足ai+aj>bi+bj(i<j)的i,j对数. 思路: 移项得:(ai-bi)+(aj-bj)>0,i<j即i!=j,用c序列保存所有ai-bi的值,排序,若左右数之和大于0,则右数与二数间的数之和都大于0,计入结果后移动右指针,否则移动左指针. Tips: c[i]+c[j]和ans可能会超范围 #include <bits/stdc++.h> using namespace std; typedef long long ll;…
题意: 有一个每个单元标明移动方向的长为n的序列,每次移动不能超过距离k,问能够从0移动到n+1的k的最小值. 思路: k=最长连续L序列长度+1. #include <bits/stdc++.h> using namespace std; void solve(){ string s;cin>>s; int mx=1,n=s.size(); for(int i=0;i<n;i++){ int len=1; while(i<n&&s[i]=='L') +…
题目连接:http://codeforces.com/contest/798/problem/C C. Mike and gcd problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has a sequence A = [a1, a2, ..., an] of length n. He considers…
E. Mike and Geometry Problem 题目连接: http://www.codeforces.com/contest/689/problem/E Description Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's define f([l, r]) = r - l + 1 to…
B. Far Relative's Problem 题目连接: http://www.codeforces.com/contest/629/problem/B Description Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of…
任意门:http://codeforces.com/contest/689/problem/E E. Mike and Geometry Problem time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Mike wants to prepare for IMO but he doesn't know geometry, so…
A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the s…
题目链接:http://codeforces.com/contest/742/problem/B B. Arpa's obvious problem and Mehrdad's terrible solution time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are some beautiful girls in…
A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has a string s consisting of only lowercase English letters. He wants to change exactly onecharacter from the st…
题意:n个人,在规定时间范围内,找到最多有多少对男女能一起出面. 思路:ans=max(2*min(一天中有多少个人能出面)) #include<iostream> #include<string> #include<algorithm> #include<cstdlib> #include<cstdio> #include<set> #include<map> #include<vector> #includ…
B. Arpa’s obvious problem and Mehrdad’s terrible solution time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are some beautiful girls in Arpa’s land as mentioned before. Once Arpa came u…
E. Little Girl and Problem on Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A little girl loves problems on trees very much. Here's one of them. A tree is an undirected connected g…
E. Mike and Geometry Problem time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry pro…
如果一开始就满足题意,不用变换. 否则,如果对一对ai,ai+1用此变换,设新的gcd为d,则有(ai - ai+1)mod d = 0,(ai + ai+1)mod d = 0 变化一下就是2 ai mod d = 0 2 ai+1 mod d = 0 也就是说,用两次变换之后,gcd至少扩大2倍,于是,最优方案就是我们将所有的奇数都变成偶数. 只需要找出所有奇数段,答案就是sigma([奇数段的长度/2]+(奇数段的长度 mod 2 ==1 ?)). #include<cstdio> #i…
题目链接:传送门 题目大意:给你n个区间,求任意k个区间交所包含点的数目之和. 题目思路:将n个区间都离散化掉,然后对于一个覆盖的区间,如果覆盖数cnt>=k,则数目应该加上 区间长度*(cnt与k的组合数) ans=ans+(len*C(cnt,k))%mod; #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <algorith…
题目中给出的函数具有周期性,总可以移动到第一个周期内,当然,a<b则无解. 假设移动后在上升的那段,则有a-2*x*n=b,注意限制条件x≥b,n是整数,则n≤(a-b)/(2*b).满足条件的x≥(a-b)/(2*n) 假设在下降的那段,2*x-(a-2*x*n)=b,n+1≤(a+b)/(2*b),x≥(a+b)/(2*(n+1)) 两者取最小值 #include<bits/stdc++.h> using namespace std; int main() { int a,b; sc…
                                                                       C. A Problem about Polyline                                                                                time limit per test 1 second                                            …
[链接]h在这里写链接 [题意]     给你一个金额N,和硬币的类型总数M;     (完全背包),然后问你组成N的方案数.     使得,用这些硬币组成价值为N的金额的方案数为A;     现在A已知,让你求出一组合法的N,M以及每个硬币的面值. [题解] 只要面值为1和面值为2. 做个完全背包.就能发现这两个能够覆盖到所有的方案数. [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/stdc++.h> using namespace std; long l…
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…
题意: 给出一个移动序列,可以无效化一些指令,问可以移动到多少不同位置. 思路: 第一印象是统计左右指令数目,后来发现左右指令数目和即字符串长度. #include <bits/stdc++.h> using namespace std; int main() { int n;cin>>n; cout<<n+1<<endl; return 0; }…
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate it n = int(raw_input()) s = "" a = ["I hate that ","I love that ", "I hate it","I love it"] for i in ran…
Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/output 1 s, 256 MB    x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB    x1462 C Vasya and String standard input/output 1 s, 256 MB    x1393…
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输出”#Color”,如果只有”G”,”B”,”W”就输出”#Black&White”. #include <cstdio> #include <cstring> using namespace std; const int maxn = 200; const int INF =…
 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…