cf之路,1,Codeforces Round #345 (Div. 2)
Posted weeping
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cf之路,1,Codeforces Round #345 (Div. 2)相关的知识,希望对你有一定的参考价值。
cf之路,1,Codeforces Round #345 (Div. 2)
ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度。所以做了round#345连试试水的深浅。。。。。
其实这个应该是昨天就写完的,不过没时间了,就留到了今天。。
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at a1 percent and second one is charged at a2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger).
Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops.
Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent.
The first line of the input contains two positive integers a1 and a2 (1 ≤ a1, a2 ≤ 100), the initial charge level of first and second joystick respectively.
Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.
3 5
6
4 4
5
In the first sample game lasts for 6 minute by using the following algorithm:
- at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%;
- continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%;
- at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%;
- continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%;
- at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%;
- at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%.
After that the first joystick is completely discharged and the game is stopped.
题目大意:是给你两个(控制棒)电量a,b,并且只有一个充电器,每分钟的开始只能给一个充电;如果某分钟开始时,a没充电则电量减2,b充电则电量加1.如果a 或b等于0时则游戏结束(可以推出a=b=1时游戏也结束)。
现在让你求这个游戏能玩多久。
思路,对a,b比大小,使a>=b;每次给b充电,a不充,然后ab比大小使a>b,一直循环到游戏结束条件触发
#include <iostream> #include <algorithm> #include <cstdio> #include <cmath> #include <cstring> #include <queue> #include <stack> #include <map> #include <vector> using namespace std; int main (void) { int a, b, t,time=0; cin >> a >> b; if (a < b) { t = a; a = b; b = t; } while (a && b) { if (b == 1 && a == 1) { break; } a -= 2; b++; if (a < b) { t = a; a = b; b = t; } time++; } cout<<time<<endl; return 0; }
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 ≤ i ≤ n - 1), such that ai + 1 > ai.
The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of painting.
The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai means the beauty of the i-th painting.
Print one integer — the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.
5
20 30 10 50 40
4
4
200 100 100 200
2
In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200.
题目大意是给你一个数列a[n],按某种方式排列后,a[i]<a[i+1]时,happy time+1,求happy time的最大值
思路:先对数组从小到大排序,然后遍历,遍历时如果数字相同的则只记录一次,把剩下的相同的数放数组头部(因为数组头已经不需要再用了),并记录压入数组头的数,不同的数则为此次的happytime数。然后重复上诉过程,直到压入数组的个数为0时结束,最后的happytime和即为答案;
#include <iostream> #include <algorithm> #include <cstdio> #include <cmath> #include <cstring> #include <queue> #include <stack> #include <map> #include <vector> using namespace std; int a[1010]; int main (void) { int n, temp, num = 0, tot=0; cin>>n; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } while (n) { sort(a, a + n); num = 0; temp = a[0]; for (int i = 1; i < n; i++) { if (temp == a[i]) { a[num++] = temp; } temp = a[i]; } tot += n - num -1; n = num; } cout<<tot<<endl; return 0; }
以上是关于cf之路,1,Codeforces Round #345 (Div. 2)的主要内容,如果未能解决你的问题,请参考以下文章
CF #1354 Educational Codeforces Round 87
Codeforces Round #563 (Div. 2)/Codeforces1174
题解 Codeforces Round #616 (Div. 2) (CF1291)
[CF977X]Codeforces Round #479 (Div. 3)