Codeforces #304 (div2)
来源:互联网 发布:php网店 编辑:程序博客网 时间:2024/04/29 23:33
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 dollars does he have to borrow from his friend soldier to buy w bananas?
The first line contains three positive integers k, n, w (1 ≤ k, w ≤ 1000, 0 ≤ n ≤ 109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
3 17 4
13
AC代码如下:
//// Created by TaoSama on 2015-05-23// Copyright (c) 2015 TaoSama. All rights reserved.//#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <string>#include <set>#include <vector>using namespace std;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;const int N = 1e5 + 10;long long n, k, w;int main() {#ifdef LOCAL freopen("in.txt", "r", stdin);// freopen("out.txt","w",stdout);#endif ios_base::sync_with_stdio(0); cin >> k >> n >> w; long long sum = 0; for(long long i = 1; i <= w; ++i) sum += i * k; cout << (sum - n < 0 ? 0 : sum - n) << endl; return 0;}
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 much it's owner reached. Coolness factor can be increased by one for the cost of one coin.
For every pair of soldiers one of them should get a badge with strictly higher factor than the second one. Exact values of their factors aren't important, they just need to have distinct factors.
Colonel knows, which soldier is supposed to get which badge initially, but there is a problem. Some of badges may have the same factor of coolness. Help him and calculate how much money has to be paid for making all badges have different factors of coolness.
First line of input consists of one integer n (1 ≤ n ≤ 3000).
Next line consists of n integers ai (1 ≤ ai ≤ n), which stand for coolness factor of each badge.
Output single integer — minimum amount of coins the colonel has to pay.
41 3 1 4
1
51 2 3 2 5
2
AC代码如下:
//// Created by TaoSama on 2015-05-23// Copyright (c) 2015 TaoSama. All rights reserved.//#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <string>#include <set>#include <vector>using namespace std;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;const int N = 1e5 + 10;int n;bool vis[6005];int main() {#ifdef LOCALfreopen("in.txt", "r", stdin);//freopen("out.txt","w",stdout);#endifios_base::sync_with_stdio(0);while(cin >> n){memset(vis, false, sizeof vis);int ans = 0;for(int i = 1; i <= n; ++i){int x; cin >> x;if(vis[x]){for(int j = 1; j <= n; ++j){if(!vis[x + j]){ans += j;vis[x + j] = true;break;}}}else vis[x] = true;}cout << ans << endl;}return 0;}
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.
The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins.
You have to calculate how many fights will happen and who will win the game, or state that game won't end.
First line contains a single integer n (2 ≤ n ≤ 10), the number of cards.
Second line contains integer k1 (1 ≤ k1 ≤ n - 1), the number of the first soldier's cards. Then follow k1 integers that are the values on the first soldier's cards, from top to bottom of his stack.
Third line contains integer k2 (k1 + k2 = n), the number of the second soldier's cards. Then follow k2 integers that are the values on the second soldier's cards, from top to bottom of his stack.
All card values are different.
If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won.
If the game won't end and will continue forever output - 1.
42 1 32 4 2
6 2
31 22 1 3
-1
AC代码如下:
//// Created by TaoSama on 2015-05-23// Copyright (c) 2015 TaoSama. All rights reserved.//#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <deque>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <string>#include <set>#include <vector>using namespace std;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;const int N = 1e5 + 10;typedef pair<string, string> P;int n, k1, k2;map<P, bool> mp;int main() {#ifdef LOCAL freopen("in.txt", "r", stdin);// freopen("out.txt","w",stdout);#endif ios_base::sync_with_stdio(0); while(cin >> n) { deque<int> l, r; mp.clear(); cin >> k1; string s, t; for(int i = 1; i <= k1; ++i) { int x; cin >> x; l.push_back(x); s += char(x + '0'); } cin >> k2; for(int i = 1; i <= k2; ++i) { int x; cin >> x; r.push_back(x); t += char(x + '0'); } mp[P(s, t)] = true; bool cycle = false; int ans = 0; //cout<<s <<' '<<t<<endl; while(!l.empty() && !r.empty()) { int ll = l.front(), rr = r.front(); l.pop_front(); r.pop_front(); char cl = s[0], cr = t[0]; s.erase(0, 1); t.erase(0, 1); if(ll < rr) { r.push_back(ll); r.push_back(rr); t = t + cl + cr; } else { l.push_back(rr); l.push_back(ll); s = s + cr + cl; } //cout<< s << ' '<<t<<endl; if(mp.count(P(s, t))) { cycle = true; break; } else mp[P(s, t)] = true; ++ans; } if(cycle) cout << "-1\n"; else { cout << ans; if(l.empty()) cout << " 2\n"; else cout << " 1\n"; } } return 0;}
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 one tries to make maximum possible number of rounds. Each round consists of choosing a positive integer x > 1, such that n is divisible by x and replacing n with n / x. When n becomes equal to 1 and there is no more possible valid moves the game is over and the score of the second soldier is equal to the number of rounds he performed.
To make the game more interesting, first soldier chooses n of form a! / b! for some positive integer a and b (a ≥ b). Here by k! we denote the factorial of k that is defined as a product of all positive integers not large than k.
What is the maximum possible score of the second soldier?
First line of input consists of single integer t (1 ≤ t ≤ 1 000 000) denoting number of games soldiers play.
Then follow t lines, each contains pair of integers a and b (1 ≤ b ≤ a ≤ 5 000 000) defining the value of n for a game.
For each game output a maximum score that the second soldier can get.
23 16 3
25
</pre>AC代码如下:<pre name="code" class="cpp">//// Created by TaoSama on 2015-05-23// Copyright (c) 2015 TaoSama. All rights reserved.//#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <string>#include <set>#include <vector>using namespace std;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;const int N = 5e6;long long fact[N];int prime[N], p;bool is[N];void seive() { memset(is, true, sizeof is); for(int i = 2; i <= N; ++i) { if(is[i]) { prime[p++] = i; for(int j = i + i; j <= N; j += i) is[j] = false; } }}void init() { seive(); for(int i = 2; i <= N; ++i) { int t = i; //cout<<i<<":"<<endl; for(int j = 0; j < p; ++j) { if(prime[j] * prime[j] > t) break; while(t % prime[j] == 0) { fact[i]++; //cout<<j<<' '; t /= prime[j]; } } //cout<<endl; if(t != 1) fact[i] ++; } /*for(int i = 1; i <= 10; ++i) cout << i << ' '; cout << endl; for(int i = 1; i <= 10; ++i) cout << fact[i] << ' '; cout << endl;*/ for(int i = 2; i <= N; ++i) fact[i] += fact[i - 1];}int main() {#ifdef LOCAL freopen("in.txt", "r", stdin);// freopen("out.txt","w",stdout);#endif ios_base::sync_with_stdio(0); //time_t st = clock(); init(); int t; scanf("%d", &t); while(t--) { int x, y; scanf("%d%d", &x, &y); //cout << fact[x] << ' ' << fact[y] << endl; printf("%I64d\n", fact[x] - fact[y]); } //time_t ed = clock(); //printf("%.3fs\n", (ed - st + 0.0) / CLOCKS_PER_SEC); return 0;}
- Codeforces #304 (div2)
- Codeforces #292 (div2)
- Codeforces #290 (div2)
- Codeforces #303 (div2)
- Codeforces #305 (div2)
- Codeforces #306 (div2)
- Codeforces #307 (div2)
- Codeforces #308(div2)
- Codeforces #309(div2)
- Codeforces #309(div2)
- Codeforces #310(div2)
- Codeforces #311(div2)
- Codeforces #319(div2)
- Codeforces #320(div2)
- Codeforces #321(div2)
- 【套题】Codeforces#304(div2)
- codeforces 187 (div2)题解
- Codeforces 201(DIV2)B
- 01背包入门
- OC应用:射击游戏
- sqlserver08数据库表导入Oracle方法
- Android:使用百度地图SDK定位当前具体位置(类似QQ发表说说的选择地点功能)
- 注解解决Hibernate中should be mapped with insert="false" updatable=false
- Codeforces #304 (div2)
- 黑马程序员——OC 基础:NSString的一些用法
- 不用额外空间判断一个数是否是回文形式
- (三)Python的基本概念
- Linux - DNS - Command Dig
- 【WinCV】小白在VS下安装opencCV2.4.11及3.0
- Linux Xmodmap 键盘映射
- hihoCoder 47周 拓扑排序
- 后台开发-win8下IIS服务器服务器搭建