[Codeforces 17C] Balance】的更多相关文章

codeforces 17C Balance 题意 给定一个串,字符集{'a', 'b', 'c'},操作是:选定相邻的两个字符,把其中一个变成另一个.可以做0次或者多次,问最后可以生成多少种,使得任意一种字符和其他字符的个数相差都不超过1. 题解 一个生成串压缩之后必定都是初始串的子序列,那么只要能枚举所有子序列,其他的很好搞定. 对于枚举的每个子序列,如果它是由初始串最早能生成的产生,那么肯定不会重. 基于这一点,f(i, a, b, c)表示当前由初始串1~i生成子序列,三个字符分别的个数…
Brief Introduction: 给定一个仅由abc组成的字符串,每个字符可以向左右延展,求最终新的平衡字符串的个数. Algorithm: 关键点在于变换前后字符串中字符的相对位置不会发生改变 也就是说,将前后字符串unique后,B是A的子序列 问题转化为求A得子序列数 这样直接使用dp[cur][i][j][k] 配合 next[i][char] 转移即可 不过在实际实现中可以不用unique,直接在原字符串上转移也是同样的效果 Code: #include <bits/stdc++…
UVa 1625 color length https://blog.csdn.net/Dylan_Frank/article/details/52261424 https://www.cnblogs.com/jerryRey/p/4740944.html Uva-1375 The Best Name for Your Baby(未解决) https://blog.csdn.net/u014258433/article/details/69070747 CodeForces - 17C Bala…
Codeforces17A 题意: 有一种素数会等于两个相邻的素数相加 如果在2~n的范围内有至少k个这样的素数,就YES,否则就NO; 思路: 采用直接打表,后面判断一下就好了.那个预处理素数表还是满赞的~~ 不多说,上code-----. #include<bits/stdc++.h> #include<string.h> using namespace std; typedef long long LL; typedef unsigned long long ULL; con…
Codeforces 7E #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <map> using namespace std; map<string,int> Map; int KASE; string Str,t; ]; inline int Get(int l,int r) { ; ;i>=l;i-…
C. Balance 题目链接 http://codeforces.com/contest/17/problem/C 题面 Nick likes strings very much, he likes to rotate them, sort them, rearrange characters within a string... Once he wrote a random string of characters a, b, c on a piece of paper and began…
C. Balance time limit per test 3 seconds memory limit per test 128 megabytes input standard input output standard output Nick likes strings very much, he likes to rotate them, sort them, rearrange characters within a string... Once he wrote a random…
C. Sum Balance Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to reorder the numbers. There are…
这题写起来真的有点麻烦,按照官方题解的写法 先建图,然后求强连通分量,然后判断掉不符合条件的换 最后做dp转移即可 虽然看起来复杂度很高,但是n只有15,所以问题不大 #include <iostream> #include <fstream> #include <vector> #include <set> #include <map> #include <bitset> #include <algorithm> #in…
Description 题库链接 给你 \(k\) 个盒子,第 \(i\) 个盒子中有 \(n_i\) 个数,第 \(j\) 个数为 \(x_{i,j}\).现在让你进行 \(k\) 次操作,第 \(i\) 次操作要求从第 \(i\) 个盒子中取出一个元素(这个元素最开始就在该盒子中),放入任意一个你指定的盒子中,要求经过 \(k\) 次操作后 所有盒子元素个数和最开始相同: 所有盒子元素总和相等 询问是否存在一种操作方式使之满足,若存在,输出任意一种方案即可. \(1\leq k\leq 15…
给你一个数列,有一个操作,将一段数字变成其和除以个数,求字典序最小的那一个,分析知,求字典序最小,就是求一个不下降序列,但我们此时有可以更改数字的操作,已知已经不下降的序列不会因为操作而变的更小,只有右边的数比左边的数小的时候才需要操作,那我们可以维护一个单调栈,依次加入数字,栈顶就是当前最右的数字,再维护一个长度信息,这样,每次加入一个数就能判断是否需要操作了,若需要操作,就更新长度和数字进行即可 #include<bits/stdc++.h> using namespace std; #d…
题目链接 题目大意 维护一个集合的mex,每次有三种操作: '+' x:将数 x 插入集合中 '-' x:将数 x 移除集合 '?' k:询问满足mex的数是k的倍数 既集合中未出现的数中最小的数可以整除k 题目思路: 其实如果只维护操作1,3是比较容易的,只需要每次记录数是否在集合中,并且在每次查询的时候记录下本次数k的答案(每次倍增的查询即可),以便下次查询的时候不必重复查询. 而现在因为有了 减 操作,所以导致了原先的答案有可能会被他影响.所以我们可以将这种影响记录下来用于查询经过减操作后…
Vanya and Scales Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 552C Description Vanya has a scales for weighing loads and weights of masses w0, w1, w2, ..., w100 grams where w is some…
C. Load Balancing 题目连接: http://www.codeforces.com/contest/609/problem/C Description In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server:…
C. Vanya and Scales Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/552/problem/C Description Vanya has a scales for weighing loads and weights of masses w0, w1, w2, ..., w100 grams where w is some integer not less than 2 (…
C. Subsequences Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem/C Description For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is guaranteed tha…
B. Restaurant Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem/B Description A restaurant received n orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the i-th order…
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem/A Description Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x tha…
B. Strip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/problem/B Description Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right. Now Alexandra wants to split it into some pieces (p…
A. Fight the Monster Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/problem/A Description A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attr…
A. Warrior and Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/594/problem/A Description In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this…
C. Edo and Magnets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/594/problem/C Description Edo has got a collection of n refrigerator magnets! He decided to buy a refrigerator and hang the magnets on the door. The shop ca…
D. Max and Bike Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/problem/D Description For months Maxim has been coming to work on his favorite bicycle. And quite recently he decided that he is ready to take part in a cy…
B. Pasha and Phone Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/problem/B Description Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of ex…
A. Vitaly and Night Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/problem/A Description One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly de…
D. Mr. Kitayuta's Colorful Graph Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/506/problem/D Description Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered…
B. Anton and Lines Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/593/problem/B Description The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforc…
A. 2Char Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/593/problem/A Description Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinc…
D. Happy Tree Party Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/593/problem/D Description Bogdan has a birthday today and mom gave him a tree consisting of n vertecies. For every edge of the tree i, some number xi was w…
C. Graph Reconstruction Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/problem/C Description I have an undirected graph consisting of n nodes, numbered 1 through n. Each node has at most two incident edges. For each pa…