题目链接: http://codeforces.com/problemset/problem/546/E E. Soldier and Traveling time limit per test1 secondmemory limit per test256 megabytes 问题描述 In the country there are n cities and m bidirectional roads between them. Each city has an army. Army of…
题意 给定 n 个城市,m 条边.人只能从走相邻边相连(只能走一次)的城市. 现在给你初始城市的每一个人数,再给一组每个城市人数.询问是否可以从当前人数变换到给定人数.如果能,输入"YES"并输出方案,不能则输出"NO". http://codeforces.com/contest/546/problem/E 思路 当∑a!=∑b时,肯定不能. 建一个超级源点s和超级汇点t,s到(1~n)连一条容量为a[i]的边,(n+1~2*n)到t连一条容量为b[i]的边,再将…
题目传送门 /* 题意:b+1,b+2,...,a 所有数的素数个数和 DP+埃氏筛法:dp[i] 记录i的素数个数和,若i是素数,则为1:否则它可以从一个数乘以素数递推过来 最后改为i之前所有素数个数和,那么ans = dp[a] - dp[b]: 详细解释:http://blog.csdn.net/catglory/article/details/45932593 */ #include <cstdio> #include <algorithm> #include <cs…
题目传送门 /* 题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌 queue容器:模拟上述过程,当次数达到最大值时判断为-1 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <string> #include <stack> #include <cmath> #inc…
题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; ; const int INF = 0x3f3f3f3f; int a[MAXN]; int main(vo…
题目传送门 /* 水题:ans = (1+2+3+...+n) * k - n,开long long */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; typedef long long ll; int main(void) //Codeforces Round #304 (Div. 2) A. Soldier…
题目传送门 /* 题意:这题就是求b+1到a的因子个数和. 数学+DP:a[i]保存i的最小因子,dp[i] = dp[i/a[i]] +1;再来一个前缀和 */ /************************************************ Author :Running_Time Created Time :2015-8-1 14:08:34 File Name :B.cpp ************************************************…
D. Soldier and Number Game Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/546/problem/D Description Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the second s…
C. Soldier and Cards Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/546/problem/C Description Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are diff…
B. Soldier and Badges Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/546/problem/B Description Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how…
D. Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the…
题目链接:http://codeforces.com/problemset/problem/546/C 题解: 用两个队列模拟过程就可以了. 特殊的地方是:1.如果等大,那么两张牌都丢弃 : 2.如果操作了很多次仍不能分出胜负,则认为平手.(至于多少次,我也不知道,只能写大一点碰运气,但要防止超时) 代码如下: #include<iostream>//C - Soldier and Cards #include<cstdio> #include<cstring> #in…
D. Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the…
题目链接:http://www.codeforces.com/problemset/problem/546/A题意:一个人现在有n元,它买第i根香蕉需要i*k元,问他要买w根香蕉的话,需要问他的朋友借多少钱?C++代码: #include <iostream> using namespace std; int n, k, w; int main() { cin >> k >> n >> w; cout << max(, w*(w+)/*k-n);…
D. Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output -> Link <- 题目链接呈上: 题意:两个人玩游戏,其中一个人选一个数n给另外一个人,然后每轮选一个数x使得n能被x整除,然后用n/=x;注意x>1:问要使得另一个人得分最高,最高多少:即最多能够玩几轮n变成了1…
题意 给你a,b(1<=b<=a<=5000000)表示a!/b!表示的数,你每次可以对这个数除以x(x>1且x为这个数的因子)使他变成a!/b!/x, 问你最多可以操作多少次使这个数变成1 http://codeforces.com/problemset/problem/546/D 思路 显然要素因子分解,但直接计算a!/b!的素因子个数太慢了,可以发现实际上是计算a(a-1)(a-2)--(b+1),而这些数之积的所有素因子个数之和是等于每个数的素因子个数之和的(相当于对每一个…
B. Soldier and Badges time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has acoolness factor, which sh…
A. Soldier and Bananas   A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana). He has n dollars. How many d…
A. Soldier and Bananas 题意:有个士兵要买w个香蕉,香蕉起步价为k元/个,每多买一个则贵k元.问初始拥有n元的士兵需要借多少钱? 思路:简单题 #include<iostream> #include<cstdio> using namespace std; int main() { int k, n, w; scanf("%d%d%d", &k, &n, &w); + w)*w / ; if (tot <= n…
Break the Chocolate Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/546/problem/A Description A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so…
D. Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the…
A. Soldier and Bananas time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second…
题意:给你两个长度相同的数组,每次从两个数组中选数(也可以不选),但是不可以在同一个数组中连续选两次,问能选的最大值是多少? 题解:dp,\(dp[i][0]\)表示第\(i\)个位置不选,\(dp[i][1]\)表示第\(i\)个位置选第一个数组的数,同理\(dp[i][2]\)就是第二个,不选的话,\(dp[i][0]\)可以从上个位置的第一个和第二个的最大值转移而来,而\(dp[i][1]\)可以从上个位置的第二个数组或者不选的转移而来,\(dp[i][2]\)也是同理,具体看代码. 代码…
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate it n = int(raw_input()) s = "" a = ["I hate that ","I love that ", "I hate it","I love it"] for i in ran…
Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/output 1 s, 256 MB    x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB    x1462 C Vasya and String standard input/output 1 s, 256 MB    x1393…
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输出”#Color”,如果只有”G”,”B”,”W”就输出”#Black&White”. #include <cstdio> #include <cstring> using namespace std; const int maxn = 200; const int INF =…
 cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....       其实这个应该是昨天就写完的,不过没时间了,就留到了今天.. 地址:http://codeforces.com/contest/651/problem/A A. Joysticks time limit per test 1 second memory limit per test 256…
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard in…
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his info…
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Victor adores the sets theory. Let us remind you that a set is a group of…