[题目链接]:http://codeforces.com/contest/805/problem/D [题意] 给你一个字符串; 里面只包括a和b; 让你把里面的"ab"子串全都去掉; 方式是, 每次操作可以把"ab"替换成为"bba"; 直到整个字符串里面没有"ab"子串为止 [题解] 从ab开始 ab->bba 左边再加一个a的话 即aab 就相当于在bba左边加了一个a abba -> bbaba bbbba…
传送门:http://codeforces.com/contest/805/problem/D 对于一个由‘a’.‘b’组成的字符串,有如下操作:将字符串中的一个子串“ab”替换成“bba”.当字符串中不含有子串“ab”时,任务完成.求完成任务的最小操作次数(mod109+7). 最终,字符串的形式为: bbb...baaa...a 可以考虑寻找规律: a. i)“ab”→“bba”, ii)“aab”→“abba”→“bbaba”→“bbbbaa”, iii)“aaab”→“aabba”→“a…
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 统计叶子节点个数m 把每条和叶子节点相邻的边权设置成s/cnt就可以了 这样答案就是2*s/m(直径最后肯定是从一个叶子节点开始,到另外一个叶子节点结束) 证明: 设dis(i,j)表示节点i和节点j之间的权值和 设a[1],a[2]..a[m]是m个叶子节点 则 \(max(dis(a[i],a[j])) >= ∑\frac{dis(a[i],a[j]) }{ \frac{m*(m-1)}{2|} }\) 即\(\frac{m*(m-1…
题目链接:http://codeforces.com/contest/805/problem/D 题意:只有一个操作就是将ab变成bba直到不能变为止,问最少边几次. 题解:这题可以多列几组来找规律,事实上是可以递推的,递推可得到一个式子 a[n]=2*a[n-1]+1,然后化成通项公式. a[n]+1=2*(a[n-1]+1),a[n]+1=2^n,a[n]=2^n-1; 然后就可以解决b前面有几个a的问题了,ab=2^1-1,aab=2^2-1, #include <iostream> #…
题意: 给定一串字符串,将所有“ab”的子串替换为“bba”,询问多少次操作后没有子串“ab”. 分析: 观察可得,将“ab”替换为“bba”有两种结果. ①a移到了b的后面 ②增加了一个b 而且最终的结果一定是前面全是b,后面全是a. 所以可以猜想从后往前数,设置一个B_cnt, 每当碰到一个b, 就b_cnt++, 碰到A, 就先加上一个b_cnt(因为每替换一次会将a移动后一格,所以要替换b_cnt次),再将b_cnt*2(多出b_cnt个b). #include <cstdio> #i…
805D - Minimum number of steps 思路:简单模拟,a每穿过后面一个b,b的个数+1,当这个a穿到最后,相当于把它后面的b的个数翻倍.每个a到达最后的步数相当于这个a与它后面已经到达最后的a之间的b的个数,只要从后面往前扫,记录b的个数,每遇到一个a,把b的个数加入答案,并且b的个数翻倍. 代码: #include<bits/stdc++.h> using namespace std; const int INF=0x3f3f3f3f; ; ; int main()…
D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of s…
http://codeforces.com/contest/805/problem/D D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output We have a string of letters 'a' and 'b'. We want to perform some opera…
D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of s…
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=2000),问满足[数列长度是k && 数列中每一个元素arr[i]在1~n之间 && 数列中元素可以重复]的数列有多少个?结果对10^9+7取余 解题思路:dp[i][j]表示长度是j,最后一位是i的种数 if(kk%i==0) dp[kk][j+1]+=dp[i][j] #inc…
cf劲啊 原题: We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring,…
D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of s…
[题目链接]:http://codeforces.com/contest/514/problem/A [题意] 允许你把每个数字翻转 ->x变成9-x 然后问你能够变成的最小的数字是什么; 不能出现前导0,且最后必须是正数; [题解] 第一个数字是9的话不能变; 其他数字; 大于等于5就翻转 这样就不会出现前导0了,也就不会出现为0的情况了: (这题不允许翻转之后第一位数字为0,然后把前导0去掉) [Number Of WA] 3 [完整代码] #include <bits/stdc++.h&…
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the second soldier. Then the second…
[题目链接]:http://codeforces.com/contest/768/problem/C [题意] 给你n个数字; 让你每次把这n个数字排序; 然后对奇数位的数字进行异或操作,然后对新生成的序列再重复上述操作总共k次; 问最后的序列的最小值和最大值分别是多少; [题解] 可以用计数排序来搞; 因为数字最大为1000; 所以将近O(K*1000)的复杂度; 完全可以的; 每次从小到大(0到1000(枚举数字; 然后根据该数字的个数判断该数字有几个数字要进行异或,几个数字保持原样. 然后…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that described the meth…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output 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…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones. Once he thought ab…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output After Vitaly was expelled from the university, he became interested in the graph theory. Vitaly especially liked the cycles of an odd length in w…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable. In total the table A…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Soon a school Olympiad in Informatics will be held in Berland, n schoolchildren will participate there. At a meeting of the jury of the Olympiad…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different types of chemicals. E…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Recently Maxim has found an array of n integers, needed by no one. He immediately come up with idea of changing it: he invented positive integer…
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output Anton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph. There are n vertices in the tree, e…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network - for each…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A g…
time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds:…