题意 : 有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…
题意: 问一个数组中是否存在至少长为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…
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…