题目链接:http://codeforces.com/contest/777/problem/C C. Alyona and Spreadsheet time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output During the lesson small girl Alyona works with one famous spreadsh…
对询问按右端点排序,对每一列递推出包含当前行的单调不下降串最多向前延伸多少. 用multiset维护,取个最小值,看是否小于等于该询问的左端点. #include<cstdio> #include<vector> #include<algorithm> #include<set> using namespace std; multiset<int>S; #define INF 2147483647 struct Data { int l,r,p;…
题目传送门 /* DP:从1到最大值,dp[i][1/0] 选或不选,递推更新最大值 */ #include <cstdio> #include <algorithm> #include <cmath> #include <cstring> using namespace std; typedef long long ll; ; const int INF = 0x3f3f3f3f; ll dp[MAXN][]; ll cnt[MAXN]; ll work(…
题意:定义,对于a数组的一个子区间[l,r],f[l,r]定义为对该子区间执行f操作的值.显然,有f[l,r]=f[l,r-1] xor f[l+1,r].又定义ans[l,r]为满足l<=i<=j<=r的f[i,j]的最大值.多次询问你某些区间的ans值. ans=max(f[l,r],ans[l,r-1],ans[l+1,r]),直接递推即可. #include<cstdio> #include<algorithm> using namespace std;…
Codeforces Round #401 (Div. 2) 很happy,现场榜很happy,完全将昨晚的不悦忘了.终判我校一片惨白,小董同学怒怼D\E,离AK就差一个C了,于是我AC了C题还剩35分钟立刻开D题,不料英文苦涩难懂,懂了题意之后发现也是个水题,从后往前遍历一遍即可.然而代码速度和思维都不算很好,还有半分钟在徘徊要不要测一下样例,但又怕OJ卡了,直接交第一组就跪了,然后发现个小问题改改又直接交最后5秒然而以第一组WA结束本场CF. A  Shell Game 题意:有三个位置分别…
对第一个人的排序,然后从小到大处理,对第一个人的每枚卡片,从第二个人的卡片中选择一个大于等于它的最小的,否则选择一个当前剩下的最小的,这样可以保证负场最少. 如果选择的改成大于它的最小的,就可以保证胜场最多. 用multiset处理. #include<cstdio> #include<set> #include<algorithm> using namespace std; typedef pair<int,int> Point; Point c[1010…
题目传送门 /* 模拟递推水题 */ #include <cstdio> #include <iostream> #include <cmath> #include <algorithm> #include <cstring> #include <string> #include <map> using namespace std; + ; const int INF = 0x3f3f3f3f; int a[MAXN][M…
题目链接:http://codeforces.com/contest/777/problem/D 题解: 题意:给出n行字符串,对其进行字典序剪辑.我自己的想法是正向剪辑的,即先对第一第二个字符串进行剪辑,但是这样却不能保证前面的操作是正确的,当后面突然出现一个字典序很小的字符串,那么前面的操作将非法.这种方法错在不能预知正在操作的字符串的字典序限度.看了别人的代码,发现是反向进行剪辑的,即从倒数第一第二个字符串进行剪辑,直到第一个.因为倒数第一个的字典序必须是最大,所以倒数第二个的字典序限度已…
和FallDream dalao一起从学长那借了个小号打Div2,他切ABE我做CD,我这里就写下CD题解,剩下的戳这里 AC:All Rank:33 小号Rating:1539+217->1756 C.Alyona and Spreadsheet 题目大意:给出一个n*m的数字矩阵a,k次询问,每次给li,ri,求是否有一列的a[li][j],a[li+1][j],...a[ri][j]组成一个不下降序列.(n*m<=100,000,k<=100,000) 思路:O(n*m)扫一遍可以…
Cloud of Hashtags [题目链接]Cloud of Hashtags &题意: 给你一个n,之后给出n个串,这些串的总长度不超过5e5,你要删除最少的单词(并且只能是后缀),使得这些串是按字典序排列的. &题解: 这也是个水题,当然了,是在你能想到的情况下,然而我还是没想到. 首先你要推出一个结论:最后一行是绝对不可以删的. 你也许会想的这种情况: #c #c #a 如果删了最后一个,那么前2个c就不用删了,但这是错的,因为空字符比a还要小,你如果把a删了,那么你就必须把前面…
Alyona and Spreadsheet 这就是一道思维的题,谈不上算法什么的,但我当时就是不会,直到别人告诉了我,我才懂了的.唉 为什么总是这么弱呢? [题目链接]Alyona and Spreadsheet &题意: 给一n*m的表,之后给T个询问,每个询问是r1和r2,问从r1行到r2行(包括这2行)是否至少有一列是非递减的? &题解: 可以把给的n*m表处理一下,处理成b[i][j]数组,存的是第j列递增开始的位置是第几行. 这样,只有b中第r2行最小的小于r1就行了,否则就是…
A. Shell Game time limit per test 0.5 seconds memory limit per test 256 megabytes input standard input output standard output Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played b…
A. Shell Game time limit per test 0.5 seconds memory limit per test 256 megabytes input standard input output standard output Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played b…
题意: 给出一个序列,给出一个k,要求给出一个划分方案,使得连续区间内不同的数不超过k个,问划分的最少区间个数,输出时将k=1~n的答案都输出 比赛的时候想的有点偏,然后写了个nlog^2n的做法,T了 赛后发现有更加巧妙的做法 题解: 首先,可以贪心地想 也就是说从第一个数开始,每个区间都尽量往后选,直到不能选为止,可以证明这样是最优的 那么如果按照这个方案,实际上区间的选取都是固定的. 所以位置为i的数有可能是k=1,k=2....k=t的起点 如果当前位置是i,我们考虑如何更新答案 首先对…
从后向前枚举字符串,然后从左向右枚举位. 如果该串的某位比之前的串的该位小,那么将之前的那串截断. 如果该串的某位比之前的串的该位大,那么之前那串可以直接保留全长度. 具体看代码. #include<cstdio> #include<iostream> #include<string> using namespace std; string a[500010]; int n,lens[500010],b[500010]; int main() { // freopen(…
容易发现存在循环节. #include<cstdio> using namespace std; int n,x,a[3][6]={{0,1,2,2,1,0},{1,0,0,1,2,2},{2,2,1,0,0,1}}; int main() { scanf("%d%d",&n,&x); for(int i=0;i<=2;++i) if(a[i][n%6]==x) { printf("%d\n",i); return 0; } ret…
最近状态极差..水题不想写,难题咬不动..哎,CF的题那么简单,还搞崩了= =.真是巨菜无比. Codeforces777A 题意:略. 思路: 构造出3!次变换,然后输出就好. Code: #include <bits/stdc++.h> using namespace std; int a[6][4]={{1,2,3},{2,1,3},{2,3,1},{3,2,1},{3,1,2},{1,3,2}}; int main() { int n,x; scanf("%d",&…
B. Alyona and a tree 题目连接: http://codeforces.com/contest/739/problem/B Description Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the g…
A. Alyona and mex 题目连接: http://codeforces.com/contest/739/problem/A Description Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special. Alyona is a capricious girl so after she gets the array, she…
题目链接: http://codeforces.com/contest/740/problem/D D. Alyona and a tree time limit per test2 secondsmemory limit per test256 megabytes 问题描述 Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positiv…
E. Alyona and Triangles 题目连接: http://codeforces.com/contest/682/problem/E Description You are given n points with integer coordinates on the plane. Points are given in a way such that there is no triangle, formed by any three of these n points, which…
D. Alyona and Strings 题目连接: http://www.codeforces.com/contest/682/problem/D Description After returned from forest, Alyona started reading a book. She noticed strings s and t, lengths of which are n and m respectively. As usual, reading bored Alyona…
C. Alyona and the Tree 题目连接: http://www.codeforces.com/contest/682/problem/C Description Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every verte…
A. Alyona and Numbers 题目连接: http://www.codeforces.com/contest/682/problem/A Description After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers - the first column containing integers…
题目链接 http://codeforces.com/contest/740/problem/C 题意:有一串数字,给你m个区间求每一个区间内不含有的最小的数,输出全部中最小的那个尽量使得这个最小值最大,然后把符合条件的数字串输出,输出任意一种即可 这题只要理解题意差不多就能做出来了,很简单 由于题目要求的mex要最大(mex指着个区间中的数在0-n中缺少的最小的数字例如mex(1,2)=0,mex(0,2)=1,mex(0,1)=2) 所以尽量要从零开始递增,那么最小的mex值肯定是区间最小的…
D. Alyona and a tree Problem Description: Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive integer to every edg…
C. Alyona and mex Problem Description: Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special. Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is…
B. Alyona and flowers Problem Description: Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose several of the subarrays suggested by her mother. After that, each of the flowe…
A. Alyona and copybooks Problem Description: Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs…
B. Alyona and Mex time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any elemen…