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…
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…
Codeforces Round #402 (Div. 2) A. 日常沙比提 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; inline int read(){ ,f=; ; c=getchar();} +c-'; c=getchar();} return x*f; }…
Codeforces Round #402 (Div. 2) A. Pupils Redistribution 模拟大法好.两个数列分别含有n个数x(1<=x<=5) .现在要求交换一些数使得两个数列含有某个数字的个数相同,求最少交换次数. int v1[N],v2[N]; int main() { int n; while(~scanf("%d",&n)) { int x; memset(v1,0,sizeof(v1)); memset(v2,0,sizeof(v…
D. String Game Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya th…
A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In Berland each high school student is characterized by academic performance — integer value between 1 and 5. In hig…
Problem A: 题目大意: 给定两个数列\(a,b\),一次操作可以交换分别\(a,b\)数列中的任意一对数.求最少的交换次数使得任意一个数都在两个序列中出现相同的次数. (\(1 \leq a_i,b_i \leq 5 , 1 \leq n \leq 100\)) 题解: 直觉告诉我这么搞就行了 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typed…
2017.2.26 CF D2 402 这次状态还算能忍吧……一路不紧不慢切了前ABC(不紧不慢已经是在作死了),卡在D,然后跑去看E和F——卧槽怎么还有F,早知道前面做快点了…… F看了看,不会,弃 E看了看,不会,弃 D看了看,不会……没法再弃了.想了好久发现可以二分答案(浪费30min) 过了D以后去看F,发现果然还是不会(浪费20min) 之后看E,思路跑偏浪费20min+ 此时时间还剩大约20min,终于想到了E可能是正解的做法,开始拼手速,各种调试,终于调过了样例,而时间只剩10s了…
这一场的表现可以用"全程智障"4个字,生动传神地描述出来. About 写题: A. 写了一堆if比较大小, 这很勤勉.(绝对值君对自己の存在感为0表示很难过.) B. 题,直接读错...对着第二个样例疯狂思考人生. C. 又写出一堆划水的if.没必要的分类讨论太多. D. 搞这个题时,我表现得相当活跃,忽而写dp, 忽而写set,忽而用set维护dp. 代码突突突了150+行,成功地把一个二分答案的水题,搞得跟div1E一样. About 技能: 1. 尺取二分得加技能点啦! 2.…
哎,今天第一次打div1 感觉头脑很不清醒... 看到第一题就蒙了,想了好久,怎么乱dp,倒过来插之类的...突然发现不就是一道sb二分吗.....sb二分看了二十分钟........ 然后第二题看了一下,感觉太码农了不可做,然后就cd逛一逛. 突然觉得c可做,就做了一下,交上去wa了,发现有情况没考虑. 这下又滚回了b,结果又没写完...... gg  2040 -83 ->1957 -----------------------------------------------我似分割线啊 A…
A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In Berland each high school student is characterized by academic performance — integer value between 1 and 5. In hig…
好长时间没有打Codeforces了,今天被ysf拉过去打了一场. lrd也来参(nian)加(ya)比(zhong)赛(sheng) Problem A: 我去,这不SB题吗.. 用桶统计一下每个数出现的数目. 对位相减然后除二加起来 最后除二输出就行了. 具体为什么我也没想,直觉告诉我这么做就可以了. 然后他就pretest passed了 Problem B: for循环到k扫一遍就行了吧. 立马写了个上去 Wrong answer on pretest 2 没开long long !!!…
A题卡壳了,往离线倒着加那方面想了会儿,后来才发现方向错了,二十多分钟才过掉,过了B后做D,想法好像有点问题,最后只过两题,掉分了,差一点回紫. AC:AB Rank:173 Rating:2227-23->2204 A.String Game 题目大意:给出字符串A和B,保证B是A的子序列,给出一个长度为A串长度的排列,问按排列的顺序删掉A串中字符,最多删几个使得B任然是A的子序列.(A串长度<=200,000) 思路:发现答案满足单调性,二分删几个,O(n)check一下B还是不是A的子序…
题意:交互题:存在一个至少有一个0和一个1的长度为n的二进制串,你可以进行最多15次询问,每次给出一个长度为n的二进制串,系统返回你此串和原串的海明距离(两串不同的位数).最后要你找到任意一个0的位置和任意一个1的位置. 先问n个0,返回你的原串中是1的数量,记为X.然后将任意一位改成1,倘若答案增量为1,那么你改动的那位在原串中是0,反之,那位是1. 不失一般性地,我们假设你改动的那一位在原串中是0,你就要去找1的位置. 就不断二分缩小区间,每次将当前区间划分成左右两部分l,m m+1,r.如…
当m>=n时,显然答案是n: 若m<n,在第m天之后,每天粮仓减少的量会形成等差数列,只需要二分到底在第几天,粮仓第一次下降到0即可. 若直接解不等式,可能会有误差,需要在答案旁边扫一下. 注意二分上界的确定,不能太小也不能太大. #include<cstdio> #include<iostream> using namespace std; typedef long long ll; ll n,m; int main(){ cin>>n>>m;…
D. Game with modulo time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output This is an interactive problem. Vasya and Petya are going to play the following game: Petya has some positive integer num…
傻逼二分 #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; ll a[100010],b[100010],sum; int n,m; bool check(int x){ for(int i=1;i<=n;++i){ b[i]=a[i]+(ll)i*(ll)x; } sum=0; sort(b+1,b+n+1); for(int i=1;i<=x;++i){ s…
暴搜 #include<cstdio> #include<algorithm> using namespace std; int n,K,Div=1,a[21],m,ans=100; bool vis[21]; void calc(int now) { int t=0; bool flag=0; for(int i=m;i>=1;--i) if(!vis[i]) { if((!flag) && a[i]==0) return; t=t*10+a[i]; fla…
一次交换,会让Group A里面的某个数字的数量-1,另一个数字的数量+1:对Group B恰好相反. 于是答案就是xigma(i=1~5,numA[i]-numB[i]>0)(numA[i]-numB[i])/2,如果这个值无法被2整除,则无解,或者如果这个值不等于xigma(i=1~5,numA[i]-numB[i]<0)(-numA[i]+numB[i])/2的话,也无解. 或者如果某个值在两组中出现的总次数无法被2整除,也无解. #include<cstdio> using…
Description Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the w…
Description Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10k. For example, if k = 3, in the…
按位考虑,每个变量最终的赋值要么是必为0,要么必为1,要么和所选定的数相同,记为2,要么和所选定的数相反,记为3,一共就这四种情况. 可以预处理出来一个真值表,然后从前往后推导出每个变量的赋值. 然后从高位到低位考虑,如果某一位,对于所有变量而言,2的数量大于等于3的数量,就把所选定的数的该位记为0,否则记为1,就能满足和最小.反之就能满足和最大. #include<cstdio> #include<string> #include<iostream> #include…
按照b[i]-a[i],对物品从大到小排序,如果这个值大于零,肯定要立刻购买,倘若小于0了,但是没买够K个的话,也得立刻购买. #include<cstdio> #include<algorithm> using namespace std; struct Point { int x,y; }a[200010]; int n,K,ans; bool cmp(const Point &a,const Point &b) { return a.y-a.x>b.y-…
Description In Berland each high school student is characterized by academic performance — integer value between 1 and 5. In high school 0xFF there are two groups of pupils: the group A and the group B. Each group consists of exactly n students. An a…
Description Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi. Not all of sellers are…
题意: Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t an…
// Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停下来,竖直走. // 问走到终点的最短时间 // 思路: // 1.贪心来做 // 2.我觉的二分更直观 // 可以抽象成:一条射线与凸边行相交,判断交点.二分找切点 #include <bits/stdc++.h> using namespace std; #define LL long lon…
题目传送门 /* 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 */ #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ; ; const int INF = 0x3f3f3f3f; int a[MAXN][MAXN]; int mn_r[MAXN]; int mn_c[MAXN]; bool is_prim…