D. String Game time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty…
D. String Game time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty…
D. String Game time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty…
二分要删除几个,然后暴力判定. #include<cstdio> #include<cstring> using namespace std; int a[200010],n,m; char s1[200010],s2[200010]; bool cant[200010]; bool check(int x) { memset(cant,0,sizeof(cant)); for(int i=1;i<=x;++i) cant[a[i]]=1; int j=1; for(int…
待补 A #include <bits/stdc++.h> using namespace std; int n; int main() { int __; scanf("%d", &__); while(__ -- ) { scanf("%d", &n); if(n == 1) printf("0\n"); else if(n == 2) printf("1\n"); else if(n == 3…
题目链接:http://codeforces.com/contest/675/problem/C 给你n个bank,1~n形成一个环,每个bank有一个值,但是保证所有值的和为0.有一个操作是每个相邻的bank之间可以转钱,让你用最少的操作使每个bank的值为0. 一开始没什么思路,看了一下别人的题解,果然还是还是native... 要是让操作次数变少,首先划分和为0的区间个数要尽量多,比如一个区间的长度为k,那么他操作次数为k - 1,所以总的操作次数就是(n - 区间的个数). 那么要算出区…
https://codeforces.com/contest/1065 题意 给你a,b,让你找尽量多的自然数,使得他们的和<=a,<=b,用在a和b的自然数不能重复 思路 假如只有一个数a让你去找,问题就很简单了,就是找到一个x,使得x尽量大,且x*(x+1)/2<=a,意味着答案就是1~x 我的思路是从1开始累加,加到一个不能再加的数时,向后退一个数,加上n-sum(1~a[i-1])(ps:a[i+1]为不能再加的数) 错误贪心思想:假如加到不能再加,同样是只能再加一个数了,不如把…
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other. Galya doesn't know…
题意:给出一个串,只包含 ( ? ) 三种符号,求出有多少个子串是完美匹配的. ( ) ? ) => ( ) ( ) 完美匹配( ( ) ? => ( ( ) )完美匹配? ? ? ? => ( ) ( ) => ( ( ) ) 算一种子串 思路:看代码. #include<bits/stdc++.h> using namespace std; #define int long long signed main(){ string str; cin>>str…
题意:给你一个只含有\(0\)和\(1\)的字符串,每次操作可以将\(0\)改成\(1\)或\(1\)改成\(0\),问最少操作多少次,使得子序列中不含有\(010\)和\(101\). 题解:仔细想一想不难发现,构造后的字符串要么全是\(1\)和\(0\),要么就是\(000....111\)和\(111...000\),我们对\(0\)求一个前缀和,判断一下这些情况,更新最小值即可. 代码: #include <iostream> #include <cstdio> #incl…