C. Permutation Cycle   time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output For a permutation P[1... N] of integers from 1 to N, function f is defined as follows: Let g(i) be the minimum positi…
C. Permutation Cycle time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output For a permutation P[1... N] of integers from 1 to N, function f is defined as follows: Let g(i) be the minimum positive…
靠这把上了蓝 A. Palindromic Supersequence time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a string A. Find a string B, where B is a palindrome and A is a subsequence of B. A subseq…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] p[i] = p[p[i]]一直进行下去 在1..n的排列下肯定会回到原位置的. 即最后会形成若干个环. g[i]显然等于那个环的大小. 即让你形成若干个环. 每个环的大小只能为A或B 则相当于问Ax+By=n是否有解. 可以枚举x然后看看n-A*x能否被B整除. 构造x个长度为A的环,y个长度为B的环就好了 [代码] #include <bits/stdc++.h> using namespace std; const in…
B. Recursive Queries   time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Let us define two functions f and g on positive integer numbers. You need to process Q queries. In each query, you wi…
占坑,明天写,想把D补出来一起写.2/20/2018 11:17:00 PM ----------------------------------------------------------我是分割线------------------------------------------------------- 我来了,本来打算D题写到一起的,但是有新的东西要写,D就单独写一篇,这里写A,B,C: 开启智障模式:(看我咸鱼突刺的厉害( • ̀ω•́ )✧)   2/21/2018 10:46:…
2018-02-19 A. Palindromic Supersequence time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a string A. Find a string B, where B is a palindrome and A is a subsequence of B. A su…
[链接] 我是链接,点我呀:) [题意] 让你在树上找一个序列. 这个序列中a[1]=R 然后a[2],a[3]..a[d]它们满足a[2]是a[1]的祖先,a[3]是a[2]的祖先... 且w[a[1]]<=w[a[2]]<=w[a[3]].... 且要求这个序列的长度最长 (且a[1]和a[2]的简单路径之间不能有大于等于a[1]的点 (也就是能取就取 [题解] 考虑一个naive的思路. 定义一个next[i]数组,表示i往上最近的权值大于i的节点所在的位置. 则我们每次输入2 R X的…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 写个记忆化搜索. 接近O(n)的复杂度吧 [代码] #include <bits/stdc++.h> using namespace std; const int N = 1e6; int g[N+10]; int pre[N+10][20]; int f(int x){ int temp = 1; while (x){ if (x%10!=0) temp*=(x%10); x/=10; } return temp; } in…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 字符串倒着加到原串右边就好 [代码] #include <bits/stdc++.h> using namespace std; int main(){ #ifdef LOCAL_DEFINE freopen("rush_in.txt", "r", stdin); #endif ios::sync_with_stdio(0),cin.tie(0); string s; cin >&…
A. A Serial Killer time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his power…
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potentia…
题目链接:http://codeforces.com/contest/776/problem/D D. The Door Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Moriarty has trapped n people in n distinct rooms in a hotel. Some room…
前四题比较水,E我看出是欧拉函数傻逼题,但我傻逼不会,百度了下开始学,最后在加时的时候A掉了 AC:ABCDE Rank:182 Rating:2193+34->2227 终于橙了,不知道能待几天 A.A Serial Killer 题目大意:一开始给你两个字符串,每次给你当前两个串中的一个和一个新的串,用新的串换掉旧的,每次输出当前的串.(次数<=1000) 思路:二逼题 #include<iostream> using namespace std; int main() { s…
再来回顾一下2-SAT,把每个点拆点为是和非两个点,如果a能一定推出非b,则a->非b,其他情况同理. 然后跑强连通分量分解,保证a和非a不在同一个分量里面. 这题由于你建完图发现都是双向边,所以用并查集亦可. #include<cstdio> #include<vector> #include<cstring> using namespace std; vector<int>G[200010],rG[200010],vs; bool used[200…
处理出前缀和,枚举k的幂,然后从前往后枚举,把前面的前缀和都塞进map,可以方便的查询对于某个右端点,有多少个左端点满足该段区间的和为待查询的值. #include<cstdio> #include<map> using namespace std; typedef long long ll; map<ll,int>cnts; int n,m,e; ll a[100010],ans; ll b[1001]; int main() { // freopen("c…
Moriarty has trapped n people in n distinct rooms in a hotel. Some rooms are locked, others are unlocked. But, there is a condition that the people in the hotel can only escape when all the doors are unlocked at the same time. There are m switches. E…
Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value ai. Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous se…
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry. He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1. Watson…
感觉自己做有关区间的题目方面的思维异常的差...有时简单题都搞半天还完全没思路,,然后别人提示下立马就明白了...=_= 题意:给一个含有n个元素的数组和k,问存在多少个区间的和值为k的次方数. 题解:先处理出前缀和sum[i].然后扫一遍这个前缀和数组:对于每个sum[i],从k的0次方开始枚举,检查map[ sum[i]-k^m ]是否大于0,,即之前是否出现过和值为sum[i]-k^m的前缀和:如果出现过和值为sum[i]-k^m的前缀和,则说明在前缀i和 前缀和值为sum[i]-k^m的…
[Codeforces 1208D]Restore Permutation (树状数组) 题面 有一个长度为n的排列a.对于每个元素i,\(s_i\)表示\(\sum_{j=1,a_j<a_i}^i a_j\).即前面比它小的元素的值之和. 给出\(s_1,s_2 \dots s_n\),求a 分析 考虑如何求\(a_n\),\(s_n\)实际上表示的是1~n中比\(a_n\)小的所有数的和,可以直接求出\(a_n\) 然后我们可以倒序求\(a_i\),求到\(a_i\)的时候,我们已经知道\(…
[Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和) E. Permutation Separation time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a permutat…
A - Palindromic Supersequence /* 题目大意:给出一个串,构造一个包含该串的回文串 */ #include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int N=10010; char s[N]; int main(){ scanf("%s",s); int n=strlen(s); for(int i=n-1;…
Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5 + 5; int a[N] ; int n, T; char s[N] ; int main() { cin >> T; whil…
Educational Codeforces Round 64 (Rated for Div. 2)题解 题目链接 A. Inscribed Figures 水题,但是坑了很多人.需要注意以下就是正方形.圆以及三角形的情况,它们在上面的顶点是重合的. 其余的参照样例判断一下就好了了.具体证明我也不会 代码如下: Code #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5 +…
\(Educational\ Codeforces\ Round\ 85\ (Rated\ for\ Div.2)\) \(A. Level Statistics\) 每天都可能会有人玩游戏,同时一部分人会过关,玩游戏的人数和过关的人数会每天更新,问记录的数据是否没有矛盾 //#pragma GCC optimize("O3") //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<…
Educational Codeforces Round 117 (Rated for Div. 2) A. Distance https://codeforces.com/contest/1612/problem/A 题目给出的条件是 距离为曼哈顿距离,而曼哈顿距离等价于步长. 由题目的一半条件,可以得到步长和为AB步长,各自步长为AB步长的一半. 所以显然可以推出: \[1.如果和为奇数则,不存在\\ 2.如果都为偶数,显然只需要取步长一半即可\\ \] //原始代码 #include<bi…
Educational Codeforces Round 129 (Rated for Div. 2) A-D A 题目 https://codeforces.com/contest/1681/problem/A 题解 思路 知识点:贪心. 先手的一方拥有大于等于对方最大牌的牌即可获胜,所以考虑取两组牌各自的最大值进行比较. 时间复杂度 \(O(n)\) 空间复杂度 \(O(1)\) 代码 #include <bits/stdc++.h> #define ll long long using…
Codeforces Round #792 (Div. 1 + Div. 2) A-E A 题目 https://codeforces.com/contest/1684/problem/A 题解 思路 知识点:数学. 显然长度大于等于3的数字串的最小数位是完全可以通过这些操作留到最后. 长度等于2的数字串只可能是个位数字. 时间复杂度 \(O(n)\) 空间复杂度 \(O(n)\) 代码 #include <bits/stdc++.h> using namespace std; int mai…
Educational Codeforces Round 128 (Rated for Div. 2) A-C+E A 题目 https://codeforces.com/contest/1680/problem/A 题解 思路 知识点:思维. 如果 \([l1,r1],[l2,r2]\) 有交集可以是相同的数字,那么取 \(min(l1,l2)\) :如果 \([l1,r1],[l2,r2]\) 没有交集,说明最大值最小值不能是相同的数字,那么取 \(l1+l2\) . 直接判断端点可能太多,…