[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…
题目链接:http://codeforces.com/contest/1295/problem/B 题目:给定由0,1组成的字符串s,长度为n,定义t = sssssss.....一个无限长的字符串. 题目定义一个平衡值x,取t的任意前缀Q,如果Q满足cnt(0,q) - cnt(1,q) = x,即Q中0 的个数-1的个数= x,说明当前的Q是满足题意得一个前缀,问满足x的前缀有多少个, 如果x = ∞,则输出-1. input 6 10 010010 题目给定说q的长度为28,30,32是平…
题目链接:http://codeforces.com/contest/1295/problem/C 题目:给定字符串s,t.  给定一个空串z,需要按照规则把z构造成 string z == string t 的字符串. 规则:有限次从s中任取子序列p,然后进行 string z += string p的操作, s不变. 问能不能构造出p,不能输出-1,可以得话最少几次可以构造出. 大致的想法就是n倍的s字符串串联,然后剔除不必要的字符,就可以得出z, 求最少的倍数n是多少. 主要思路就是用二分…
链接:https://codeforces.com/contest/1295 A. Display The Number 贪心思路,尽可能放置更多位,如果n为奇数,消耗3去放置一个7,剩下的放1 AC代码: #include<bits/stdc++.h> #define inf 0x3f3f3f3f using namespace std; int n,m; int main(){ int t; cin>>t; while(t--){ int n; cin>>n; st…
A 0~9需要多少笔画,自取7和1,判奇偶 #include<bits/stdc++.h> using namespace std; #define ll long long #define il inline #define it register int #define lowbit(x) (x)&(-x) #define mem(a,b) memset(a,b,sizeof(a)) #define mod 1000000007 ; int n,m; int t; int main…
过了n天补的题解:D AB就不用说了 C. Obtain The String 思路挺简单的,就是贪心,但是直接贪心的复杂度是O(|s|*|t|),会超时,所以需要用到序列自动机 虽然名字很高端但是就是个数组啦(不过我自己想不到就是了) next[i][j]表示i之后第一次出现j字符的位置,用这个函数就可以把复杂度降到O(|t|) #include <cstdio> #include <cstring> using namespace std; ; char s[N], t[N];…
预处理把左集划分为大小为1~i-1时,把全部元素都移动到右集的代价,记作sum[i]. 然后枚举终态时左集的大小,更新把元素i 留在/移动到 左集的代价. 树状数组/线段树处理区间修改/区间查询 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; #define ll long long ; struct Tree{ ll minn,lazy; }tree[N<<]; ll sum[N]…
题目链接:Same GCDs 题意:给你两个数$a$,$m(1 \leq a < m \leq 10^{10})$,求有多少个$x$满足:$0 \leq x < m$且$gcd(a,m)=gcd(a+x,m)$ 思路:设$gcd(a,m)=d$,那么问题转换为求多少个$k \in [a,a+m)$满足$gcd(k,m)=d$ 两边同时除$d$,转换为求有多少$k \in [\frac{a}{d},\frac{a+m}{d})$满足$gcd(k,\frac{m}{d})=1$ 设$x=\frac…
Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec Problem Description Input Output The only line should contain the minimal number of days required for the ship to reach the point (x2,y2)(x2,y2). If it…
Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec Problem Description Input The input contains a single line consisting of 2 integers N and M (1≤N≤10^18, 2≤M≤100). Output Print one integer, the total n…