Codeforces Round #280 (Div. 2)

来源:互联网 发布:像素数据技术 编辑:程序博客网 时间:2024/05/01 07:23

比赛链接:http://codeforces.com/contest/492



A. Vanya and Cubes
time limit per test
1 second
memory limit per test
256 megabytes

Vanya got n cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of1 cube, the second level must consist of 1 + 2 = 3 cubes, the third level must have1 + 2 + 3 = 6 cubes, and so on. Thus, thei-th level of the pyramid must have1 + 2 + ... + (i - 1) + i cubes.

Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes.

Input

The first line contains integer n (1 ≤ n ≤ 104) — the number of cubes given to Vanya.

Output

Print the maximum possible height of the pyramid in the single line.

Sample test(s)
Input
1
Output
1
Input
25
Output
4
Note

Illustration to the second sample:


公式预处理,水


#include <iostream>#define ll long longusing namespace std;int const MAX   = 1e4+5;ll  a[MAX];int main(){    ll n;    for(int i = 0; i <= MAX; i++)        a[i] = i * (i + 1) * (i + 2) / 6;    cin >> n;    int ans = 0;    for(int i = 0; i <= MAX - 1; i++)    {        if(a[i] <= n && a[i + 1] >= n)        {            if(a[i + 1] == n)                ans = i + 1;            else                ans = i;            break;        }    }    cout << ans << endl;}




B. Vanya and Lanterns
time limit per test
1 second
memory limit per test
256 megabytes

Vanya walks late at night along a straight street of lengthl, lit byn lanterns. Consider the coordinate system with the beginning of the street corresponding to the point0, and its end corresponding to the pointl. Then the i-th lantern is at the pointai. The lantern lights all points of the street that are at the distance of at mostd from it, where d is some positive number, common for all lanterns.

Vanya wonders: what is the minimum light radius d should the lanterns have to light the whole street?

Input

The first line contains two integers n, l (1 ≤ n ≤ 1000,1 ≤ l ≤ 109) — the number of lanterns and the length of the street respectively.

The next line contains n integersai (0 ≤ ai ≤ l). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street.

Output

Print the minimum light radius d, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed10 - 9.

Sample test(s)
Input
7 1515 5 3 7 9 14 0
Output
2.5000000000
Input
2 52 5
Output
2.0000000000
Note

Consider the second sample. At d = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit.


每个区间比一下,注意端点


#include <cstdio>#include <algorithm>using namespace std;int a[1005];int main(){    int l, n;    scanf("%d %d", &n, &l);    for(int i = 0; i < n; i++)        scanf("%d", &a[i]);    sort(a, a + n);    int mi = -1;    for(int i = 0; i < n - 1; i++)        mi = max(mi, a[i + 1] - a[i]);    double ans = mi * 1.0 / 2;    double x1 = a[0] - 0;    double x2 = l - a[n - 1];    if(ans < x1)        ans = x1;    if(ans < x2)        ans = x2;    printf("%.10lf\n", ans);}




C. Vanya and Exams
time limit per test
1 second
memory limit per test
256 megabytes

Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at leastavg. The exam grade cannot exceed r. Vanya has passed the exams and got gradeai for thei-th exam. To increase the grade for the i-th exam by 1 point, Vanya must writebi essays. He can raise the exam grade multiple times.

What is the minimum number of essays that Vanya needs to write to get scholarship?

Input

The first line contains three integers n, r, avg (1 ≤ n ≤ 105,1 ≤ r ≤ 109,1 ≤ avg ≤ min(r, 106)) — the number of exams, the maximum grade and the required grade point average, respectively.

Each of the following n lines contains space-separated integersai andbi (1 ≤ ai ≤ r,1 ≤ bi ≤ 106).

Output

In the first line print the minimum number of essays.

Sample test(s)
Input
5 5 45 24 73 13 22 5
Output
4
Input
2 5 45 25 2
Output
0
Note

In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point.

In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.


排序贪心


#include <cstdio>#include <cstring>#include <algorithm>#define ll long longusing namespace std;int const MAX = 1E5 + 5;struct Info{    ll a, b;}info[MAX];bool cmp(Info x, Info y){    return x.b < y.b;}int main(){    ll n, r, avg, ans = 0, sum = 0;    scanf("%I64d %I64d %I64d", &n, &r, &avg);    for(int i = 0; i < n; i++)    {        scanf("%I64d %I64d", &info[i].a, &info[i].b);        sum += info[i].a;    }    sort(info, info + n, cmp);    ll need = n * avg - sum > 0 ? n * avg - sum : 0;    for(int i = 0; i < n; i++)    {        if(r - info[i].a > need)        {            ans += info[i].b * need;            break;        }        else        {            ans += (r - info[i].a) * info[i].b;            need -= (r - info[i].a);        }    }    printf("%I64d\n", ans);}




D. Vanya and Computer Game
time limit per test
2 seconds
memory limit per test
256 megabytes

Vanya and his friend Vova play a computer game where they need to destroyn monsters to pass a level. Vanya's character performs attack with frequencyx hits per second and Vova's character performs attack with frequencyy hits per second. Each character spends fixed time to raise a weapon and then he hits (the time to raise the weapon is1 / x seconds for the first character and 1 / y seconds for the second one). Thei-th monster dies after he receivesai hits.

Vanya and Vova wonder who makes the last hit on each monster. If Vanya and Vova make the last hit at the same time, we assume that both of them have made the last hit.

Input

The first line contains three integers n,x,y (1 ≤ n ≤ 105,1 ≤ x, y ≤ 106) — the number of monsters, the frequency of Vanya's and Vova's attack, correspondingly.

Next n lines contain integersai (1 ≤ ai ≤ 109) — the number of hits needed do destroy thei-th monster.

Output

Print n lines. In thei-th line print word "Vanya", if the last hit on thei-th monster was performed by Vanya, "Vova", if Vova performed the last hit, or "Both", if both boys performed it at the same time.

Sample test(s)
Input
4 3 21234
Output
VanyaVovaVanyaBoth
Input
2 1 112
Output
BothBoth
Note

In the first sample Vanya makes the first hit at time1 / 3, Vova makes the second hit at time1 / 2, Vanya makes the third hit at time 2 / 3, and both boys make the fourth and fifth hit simultaneously at the time1.

In the second sample Vanya and Vova make the first and second hit simultaneously at time1.


二分一下


#include <cstdio>int main() {    int n, x, y, a, r = 0;      scanf("%d %d %d", &n, &x, &y);    for(int i = 0; i < n; ++i)     {        scanf("%d", &a);        a = a % (x + y);        long long L = 0, R = 1e15, mid, res;        while(L <= R)         {            mid = (L + R) >> 1;            if(mid / x + mid / y >= a)             {                res = mid;                R = mid - 1;            }            else                 L = mid + 1;        }        if((res % y == 0) && (res % x) == 0)             printf("Both\n");        else if(res % x == 0)             printf("Vova\n");        else             printf("Vanya\n");    }}




E. Vanya and Field
time limit per test
2 seconds
memory limit per test
256 megabytes

Vanya decided to walk in the field of size n × n cells. The field contains m apple trees, thei-th apple tree is at the cell with coordinates(xi, yi). Vanya moves towards vector(dx, dy). That means that if Vanya is now at the cell(x, y), then in a second he will be at cell. The following condition is satisfied for the vector:, where is the largest integer that divides botha andb. Vanya ends his path when he reaches the square he has already visited.

Vanya wonders, from what square of the field he should start his path to see as many apple trees as possible.

Input

The first line contains integers n, m, dx, dy(1 ≤ n ≤ 106,1 ≤ m ≤ 105,1 ≤ dx, dy ≤ n) — the size of the field, the number of apple trees and the vector of Vanya's movement. Nextm lines contain integersxi, yi (0 ≤ xi, yi ≤ n - 1) — the coordinates of apples. One cell may contain multiple apple trees.

Output

Print two space-separated numbers — the coordinates of the cell from which you should start your path.If there are several answers you are allowed to print any of them.

Sample test(s)
Input
5 5 2 30 01 21 32 43 1
Output
1 3
Input
2 3 1 10 00 11 1
Output
0 0
Note

In the first sample Vanya's path will look like: (1, 3) - (3, 1) - (0, 4) - (2, 2) - (4, 0) - (1, 3)

In the second sample: (0, 0) - (1, 1) - (0, 0)


(0, 0)经过n次必然会回到(0, 0),按向量划分


#include <iostream>#include <cstring>#define ll long longusing namespace std;int const MAX = 1e6 + 5;ll re[MAX], c[MAX];int main(){    ll n, m, dx, dy, x, y, res = 0, tmp;    cin >> n >> m >> dx >> dy;    re[0] = 0;    memset(c, 0, sizeof c);    for(int i = 1; i < n; i++)        re[(i * dx) % n] = (i * dy) % n;    for(int i = 0; i < m; i++)    {        cin >> x >> y;        tmp = (n + y - re[x]) % n;        c[tmp] ++;        if(c[tmp] > c[res])             res = tmp;    }    cout << 0 << " " << res << endl;}


0 0
原创粉丝点击