转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Vasily the Bear and Sequence Vasily the bear has got a sequence of positive integers a1, a2, ..., an. Vasily the Bear wants to write out several numbers on a piece of paper so that the beauty…
题目链接:http://codeforces.com/problemset/problem/336/C 题目意思:给出一个递增的正整数序列 a1, a2, ..., an,要求从中选出一堆数b1, b2, ..., bk,这堆数进行完按位&运算之后(b1 and b2 and ... and bk),能被2v整除.除此,还要求所选中的这堆数是两两不同的,&之后要最大,换句话来说,v 要尽可能最大,如果找到最大的v的方法有多种,即在 a1, a2, ..., an 中有很多种不同的组合 &a…
C. Vasily the Bear and Sequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasily the bear has got a sequence of positive integers a1, a2, ..., *a**n*. Vasily the Bear wants to write o…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Vasily the Bear and Beautiful Strings Vasily the Bear loves beautiful strings. String s is beautiful if it meets the following criteria: String s only consists of characters 0 and 1, at that…
A. Increasing Sequence 题目连接: http://www.codeforces.com/contest/11/problem/A Description A sequence a0, a1, ..., at - 1 is called increasing if ai - 1 < ai for each i: 0 < i < t. You are given a sequence b0, b1, ..., bn - 1 and a positive integer…
题目链接:http://codeforces.com/problemset/problem/336/A 好简单的一条数学题,是8月9日的.比赛中没有做出来,今天看,从pupil变成Newbie了,那个伤心啊----不是分数的缘故,而是心态!!!昨晚一直卡机,网页很久才打得开,35min才进入比赛页面,接着做的时候又非常浮躁,静不下心来,提交时再次卡机,临20多min才提交成功,于是罢想!!心态真不好!!!这是第一次做题做得那么糟糕,要端正心态才行,遇到什么紧急情况都要冷静,保持清醒的头脑. 题意…
题意: 给出n,m,g,求好串的个数 0 <= n,m <= 10^5,n + m >= 1,0 <= g <= 1 好串的定义: 1.只由0,1组成,并且恰好有n个0,m个1 2.串的value = g 串的value的计算方式: 每次将最后2个字符替换,直至串的长度为1,该字符就是串的value 00 -> 1,   01,11,10 -> 0 solution: 首先,总方案数 = C(n + m, m) m = 0时,特殊判断 设f(n,m)为n个0,m个…
HDU5014Number Sequence(贪心) 题目链接 题目大意: 给出n,然后给出一个数字串,长度为n + 1, 范围在[0, n - 1].然后要求你找出另外一个序列B,满足上述的要求,而且使得t = A0^B0 + Ai + 1 ^ Bi + 1 + ... + An ^ Bn 最大. 解题思路: 对于一个数字进行异或,要求结果最大的话,那么取这个数字的二进制互补数字是最好的情况,而且能够发现每次找到一个数字和相应的互补的数字都会是一段区间.就这样一段一段区间的去寻找每一个点相应的…
(CodeForces - 5C)Longest Regular Bracket Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output This is yet another problem dealing with regular bracket sequences. We should remind you t…
[题解]Cut the Sequence(贪心区间覆盖) POJ - 3017 题意: 给定一大堆线段,问用这些线段覆盖一个连续区间1-x的最小使用线段的数量. 题解 考虑一个这样的贪心: 先按照左端点排序,若左端点一样则谁长谁在前.现在判无解就方便了,记录一下前缀max即可.然后现在要最小化选择. 记录一个最右端点\(R\),一个暴力的办法是暴力循环判断所有线段是否满足条件,这样显然超时,你决定优化一下常数,所以你记录一下从哪个线段开始才\(l_i \ge R\).你以为你是常数优化,其实你复…
C. Bear and String Distance 题目连接: http://www.codeforces.com/contest/628/problem/C Description Limak is a little polar bear. He likes nice strings - strings of length n, consisting of lowercase English letters only. The distance between two letters is…
题目链接 https://www.luogu.org/problemnew/show/CF336C 分析 一个比较妙的贪心 我们要让最后\(and\)起来的数被\(2^k\)整除且\(k\)最大,我们不妨从后往前枚举\(k\),同时运用贪心的思路,对于二进制第\(k\)为1的数,我们想让最后得到的数除第\(k\)位外都为0,当然是\(and\)越多越好 代码 #include <cstdio> #include <cstdlib> #include <cstring>…
水题,注意数据范围即可 #include <iostream> #include <algorithm> #include <utility> using namespace std; typedef pair<int,int> Point; int main(){ int x,y; cin >> x >>y; Point a,b; if((x>0 && y > 0) || (x < 0 &&…
这场CF,脑子乱死啊...C题,搞了很长时间,结束了,才想到怎么做.B题,没看,D题,今天看了一下,很不错的组合题. 如果n和m都挺多的时候 以下情况都是变为1,根据偶数个0,最后将会为1,奇数个0,最后变为0,以1开头,全都是0. 0 1.. 0 0 0 1.... 0 0 0 0 0 1.... 总的情况是C(n+m,m),算1也可以算出来.注意m = 1的时候特判,0的时候,我也全写的特判. 10^5的组合数,用费马小定理求逆元.看了下题解,题解直接来了个逆元.. inv(a) = a^(…
题目链接 给一个字符串, 由( ) 以及? 组成, 将?换成( 或者 ) 组成合法的括号序列, 每一个?换成( 或者 ) 的代价都不相同, 问你最小代价是多少, 如果不能满足输出-1. 弄一个变量num, 如果是( 那么num++,如果是)那么num--. 如果碰到?, 那么先将这个地方弄成), 然后把make_pair(b-a, i)加到一个队列里面.a是换成左括号的值, b是换成右括号的值, i是这个位置的坐标. 如果遇到num小于0的情况, 那么就将队首元素取出, 将这个位置换成左括号.…
Description 给出一个括号序列,中间有一些问号,将第i个问号换成左括号代价是a[i],换成右括号代价是b[i],问如果用最少的代价将这个括号序列变成一个合法的括号序列 Input 第一行一个括号序列,假设其中有m个问号,则之后输入m行,每行两个整数a[i]和b[i]表示把第i个问号换成左括号或右括号的代价(括号序列长度不超过5e4,1<=a[i],b[i]<=1e6) Output 如果不存在一种合理的替换方案使得该序列变成一个合法的括号序列则输出-1,否则输出最小代价和替换后的合法…
Least Cost Bracket Sequence CodeForces - 3D 题目描述 This is yet another problem on regular bracket sequences. A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example,…
hdu4915 Parenthese sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 82    Accepted Submission(s): 25 Problem Description bobo found an ancient string. The string contains only three c…
B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are n people who plan to move…
题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory limit per test 256 megabytes 问题描述 Manao's friends often send him new songs. He never listens to them right away. Instead, he compiles them into a play…
E. Ants in Leaves 题目连接: http://www.codeforces.com/contest/622/problem/E Description Tree is a connected graph without cycles. A leaf of a tree is any vertex connected with exactly one other vertex. You are given a tree with n vertices and a root in t…
Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要找一个最小的点集,使得满足这n个区间的条件 Input n 然后li,ri,ci Output 输出最小点集大小 Sample Input 5 3 7 3 8 10 3 6 8 1 1 3 1 10 11 1 Sample Output 6 Hint 题意 题解: 线段树+二分+贪心 首先我们贪心一…
B. Sail 题目连接: http://www.codeforces.com/contest/298/problem/B Description The polar bears are going fishing. They plan to sail from (sx, sy) to (ex, ey). However, the boat can only sail by wind. At each second, the wind blows in one of these directio…
F. Doomsday Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/F Description Doomsday comes in t units of time. In anticipation of such a significant event n people prepared m vaults in which, as they think, it will…
A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/problem/A Description You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square r…
A. Exams Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/A Description Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera…
题目链接:http://codeforces.com/problemset/problem/462/B Appleman has n cards. Each card has an uppercase letter written on it. Toastman must choose k cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards…
题目链接:hdu_5783_Divide the Sequence 题意: 给你一个数列,让你分尽可能多的段,并且保证每一段的前缀和都不小于0 题解: 从后往前xjb贪心就行了 #include<cstdio> ; int a[N]; int main() { int n; while(~scanf("%d",&n)) { ;i<=n;i++)scanf("%d",a+i); ,ans=; ;i--) { sum+=a[i]; )ans++…
http://codeforces.com/contest/798/problem/D http://blog.csdn.net/yasola/article/details/70477816 对于二维的贪心我们可以先让它变成其中一维有序,这样只需要重点考虑另一维,就会简单很多. 首先,对于题目要求的选择元素之和两倍大与所有元素之和,我们可以转化为选择元素之和大于剩下的.然后我们可以将下标按照a从大到小排序.然后选择第一个,之后每两个一组,选择b大的一个,如果n是偶数再选择最后一个. 至于这样写…
B. Game of the Rows time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to brin…