Educational Codeforces Round 34

来源:互联网 发布:雪梨开的淘宝店店名 编辑:程序博客网 时间:2024/06/05 00:44

原题链接:http://codeforces.com/contest/903

A. Hungry Student Problem

time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output
Ivan’s classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.

CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly x chunks. Now he wonders whether he can buy exactly this amount of chicken.

Formally, Ivan wants to know if he can choose two non-negative integers a and b in such a way that a small portions and blarge ones contain exactly x chunks.

Help Ivan to answer this question for several values of x!

Input
The first line contains one integer n (1 ≤ n ≤ 100) — the number of testcases.

The i-th of the following n lines contains one integer xi (1 ≤ xi ≤ 100) — the number of chicken chunks Ivan wants to eat.

Output
Print n lines, in i-th line output YES if Ivan can buy exactly xi chunks. Otherwise, print NO.

Example
input
2
6
5
output
YES
NO
Note
In the first example Ivan can buy two small portions.

In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.

题意:暴力枚举即可。

#include<bits/stdc++.h>using namespace std;int main (){    int t; cin >>t;    while (t--){        int x; cin >> x;        for (int i = 0; i < 100; i++){            if ((x - 3*i) /7*7 == (x-3*i)) {                    printf("YES\n");                    break;            }            else {                if (x - 3* i < 0) {                    printf("NO\n");                    break;                }            }        }    }}

B. The Modcrab

time limit per test 1 second
memory limit per test 256 megabytes
inputstandard input
outputstandard output
Vova is again playing some computer game, now an RPG. In the game Vova’s character received a quest: to slay the fearsome monster called Modcrab.

After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has h2 health points and an attack power of a2. Knowing that, Vova has decided to buy a lot of strong healing potions and to prepare for battle.

Vova’s character has h1 health points and an attack power of a1. Also he has a large supply of healing potions, each of which increases his current amount of health points by c1 when Vova drinks a potion. All potions are identical to each other. It is guaranteed that c1 > a2.

The battle consists of multiple phases. In the beginning of each phase, Vova can either attack the monster (thus reducing its health by a1) or drink a healing potion (it increases Vova’s health by c1; Vova’s health can exceed h1). Then, if the battle is not over yet, the Modcrab attacks Vova, reducing his health by a2. The battle ends when Vova’s (or Modcrab’s) health drops to 0 or lower. It is possible that the battle ends in a middle of a phase after Vova’s attack.

Of course, Vova wants to win the fight. But also he wants to do it as fast as possible. So he wants to make up a strategy that will allow him to win the fight after the minimum possible number of phases.

Help Vova to make up a strategy! You may assume that Vova never runs out of healing potions, and that he can always win.

Input
The first line contains three integers h1, a1, c1 (1 ≤ h1, a1 ≤ 100, 2 ≤ c1 ≤ 100) — Vova’s health, Vova’s attack power and the healing power of a potion.

The second line contains two integers h2, a2 (1 ≤ h2 ≤ 100, 1 ≤ a2 < c1) — the Modcrab’s health and his attack power.

Output
In the first line print one integer n denoting the minimum number of phases required to win the battle.

Then print n lines. i-th line must be equal to HEAL if Vova drinks a potion in i-th phase, or STRIKE if he attacks the Modcrab.

The strategy must be valid: Vova’s character must not be defeated before slaying the Modcrab, and the monster’s health must be 0 or lower after Vova’s last action.

If there are multiple optimal solutions, print any of them.

Examples
input
10 6 100
17 5
output
4
STRIKE
HEAL
STRIKE
STRIKE
input
11 6 100
12 5
output
2
STRIKE
STRIKE
Note
In the first example Vova’s character must heal before or after his first attack. Otherwise his health will drop to zero in 2 phases while he needs 3 strikes to win.

In the second example no healing needed, two strikes are enough to get monster to zero health and win with 6 health left.

题意:RPG模拟题。就是打一个怪,给你你的攻击力,血量以及草药能恢复的血量,然后给你怪的攻击力和血量。每一回合你先攻击,问最短最少什么时候能干掉怪物。小模拟,小模拟。题目保证怪比能被打死(真惨TAT)。

#include<bits/stdc++.h>using namespace std;int a[1000000];int main (){    int h1,a1,c1; cin >> h1 >> a1 >> c1;    int h2,a2; cin >> h2 >> a2;    int cnt = 0;    while (1){        if (h2 - a1 <= 0) {            a[cnt++] = 1;            break;        }        else if (h2 - a1 > 0){            if (h1 -a2 > 0){                h2 = h2 -a1;                h1 = h1 -a2;                a[cnt++] = 1;            }            else {                a[cnt++] = 2; //medical                h1 += c1;                h1 -= a2;            }        }    }    cout << cnt <<endl;    for (int i = 0; i < cnt; i++){        if (a[i] == 1) cout << "STRIKE" << endl;        else cout << "HEAL" << endl;    }    return 0;}

C. Boxes Packing

time limit per test 1 second
memory limit per test 256 megabytes
inputstandard input
outputstandard output
Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.

Mishka can put a box i into another box j if the following conditions are met:

i-th box is not put into another box;
j-th box doesn’t contain any other boxes;
box i is smaller than box j (ai < aj).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.

Help Mishka to determine the minimum possible number of visible boxes!

Input
The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got.

The second line contains n integers a1, a2, …, an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.

Output
Print the minimum possible number of visible boxes.

Examples
input
3
1 2 3
output
1
input
4
4 2 4 3
output
2
Note
In the first example it is possible to put box 1 into box 2, and 2 into 3.

In the second example Mishka can put box 2 into box 3, and box 4 into box 1.

题意:小盒子可以放进比它大盒子,求这些盒子最后变成几个无法再组装的盒子。
思路:寻找“众数” ,就是拿个数字出现的次数最多。
比赛的使用离散化写的,感觉写的有点蠢。。想在想想可以用map也能做。总之这道题的思路非常广,还有堆也能过。

#include<bits/stdc++.h>using namespace std;const int maxn=100000;int a[maxn];int b[maxn];int n;int cnt[100000];int main (){    int m = 0;    cin>>n;    for(int i=1;i<=n;++i){        scanf("%d",&a[i]);        b[++m]=a[i];    }    sort(b+1,b+1+m);    for(int i=1;i<=n;++i)    cnt[lower_bound(b+1,b+1+m,a[i])-b]++;    int maxx = -1;    for (int i = 1; i <= 5000; i++) if (maxx < cnt[i]) maxx = cnt[i];    cout << maxx << endl;    return 0;}

D. Almost Difference

time limit per test 2 seconds
memory limit per test 256 megabytes
inputstandard input
outputstandard output
Let’s denote a function

You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.

Input
The first line contains one integer n (1 ≤ n ≤ 200000) — the number of elements in a.

The second line contains n integers a1, a2, …, an (1 ≤ ai ≤ 109) — elements of the array.

Output
Print one integer — the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.

Examples
input
5
1 2 3 1 3
output
4
input
4
6 6 5 5
output
0
input
4
6 6 4 4
output
-8
Note
In the first example:

d(a1, a2) = 0;
d(a1, a3) = 2;
d(a1, a4) = 0;
d(a1, a5) = 2;
d(a2, a3) = 0;
d(a2, a4) = 0;
d(a2, a5) = 0;
d(a3, a4) =  - 2;
d(a3, a5) = 0;
d(a4, a5) = 2.

题意:题意容易理解。求出每一对i,j(i <= j),如果差值大于1就贡献y-x的值,否则不计数。
思路1:是我比赛的时候想到的。维护一个后缀和+map,从前往后不断算出该点的贡献。

#include<bits/stdc++.h>using namespace std;typedef long double ld;const int maxn=201000;ld a[maxn];ld sum[maxn];map<int,int> mp;int main (){    int t; cin >> t;    ld ans = 0;    int m = 0;    for (int i = 1; i <= t; i++){        cin >> a[i];        mp[a[i]]++;    }    for (int i = t; i > 0; i--){        sum[i] = sum[i+1]+a[i];    }    for (int i = 1; i < t; i++){        ans += sum[i+1] - a[i]*(t-i);        ans = ans - mp[a[i]+1] + mp[a[i]-1];        mp[a[i]]--;    }     cout << fixed << setprecision(0) << ans << '\n' ;     return 0;}

赛后总结: 移动的真的lj,在自习室空无一人,最后十分钟居然断网了???十分钟,我连D都没交上去。赛后交上去过了是最气的,睡觉前看了看,第一页都开始都被hack了,不出所料,1000+ 的 AC 被hack到 100+,爆long long 太刺激了。
顺手学习了以下long double 的妙用,收获不少,上分50+还是很舒服的(●ˇ∀ˇ●)。

有什么不懂欢迎留言。
如有不足敬请批评指正!这里是yyy_3y!