Codeforces Round #280 (Div. 2)

A. Vanya and Cubes

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 of 1 cube, the second level must consist of 1 + 2 = 3 cubes, the third level must have 1 + 2 + 3 = 6 cubes, and so on. Thus, the i-th level of the pyramid must have 1 + 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

题意:水题,问最多能摆多高。
代码清单:
#include<iostream>
using namespace std;

int main() {
    int n,sum=0;
    cin>>n;
    for(int i=1;;i++) {
        if(sum+i*(i+1)/2>n) {
            cout<<i-1<<endl;
            break;
        }
        else sum+=i*(i+1)/2;
    }return 0;
}


B. Vanya and Lanterns

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vanya walks late at night along a straight street of length l, lit by n lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point l. Then the i-th lantern is at the point ai. The lantern lights all points of the street that are at the distance of at most d 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 integers ai (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 exceed 10 - 9.

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

题意:水题,求灯照半径的最小值。
代码清单:
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

int main() {
    int n,l,a[1005];
    cin>>n>>l;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    double dis=a[0];
    for(int i=1;i<n;i++) dis=max(dis,((double)(a[i]-a[i-1]))/2);
    dis=max(dis,double(l-a[n-1]));
    printf("%.9lf\n",dis);
    return 0;
}


C. Vanya and Exams

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade ai for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write bi 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 integers ai and bi (1 ≤ ai ≤ r, 1 ≤ bi ≤ 106).

Output

In the first line print the minimum number of essays.

Sample test(s)
Input
5 5 4
5 2
4 7
3 1
3 2
2 5
Output
4
Input
2 5 4
5 2
5 2
Output
0
题意:贪心题,每次拿文章数少的。
代码清单:
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

struct edge {
    ll x;
    ll y;
}a[100005];

bool cmp(edge a,edge b) {
    return a.y<b.y;
}

int main() {
    ll n,r,avg,b,c;
    cin>>n>>r>>avg;
    ll sum=n*avg;
    ll s=0,ans=0;
    for(int i=0;i<n;i++) {
        cin>>c>>b;
        s+=c;
        a[i].x=r-c;
        a[i].y=b;
    }
    sort(a,a+n,cmp);
    if(s<sum) {
        for(int i=0;i<n;i++) {
            if(s+a[i].x<sum) {
                s+=a[i].x;
                ans+=a[i].x*a[i].y;
            }
            else {
                ans+=(sum-s)*a[i].y;
                break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


D. Vanya and Computer Game

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vanya and his friend Vova play a computer game where they need to destroy n monsters to pass a level. Vanya's character performs attack with frequency x hits per second and Vova's character performs attack with frequency y hits per second. Each character spends fixed time to raise a weapon and then he hits (the time to raise the weapon is 1 / x seconds for the first character and 1 / y seconds for the second one). The i-th monster dies after he receives ai 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 integers ai (1 ≤ ai ≤ 109) — the number of hits needed do destroy the i-th monster.

Output

Print n lines. In the i-th line print word "Vanya", if the last hit on the i-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 2
1
2
3
4
Output
Vanya
Vova
Vanya
Both
Input
2 1 1
1
2
Output
Both
Both
题意:此题就是以一分钟内两人的子弹数为一个周期,标记当前是哪颗子弹即可。(ps:刚开始看错了题意想了一个多小时也是醉了...)
代码清单:
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll vis[2000000+5];
int main() {
    ll n,x,y,m;
    cin>>n>>x>>y;
    ll sx=y,sy=x;
    for(ll i=1;i<=(x+y);i++) {
        if(sx<sy) {
            vis[i]=1;
            sx+=y;
        }
        else if(sx>sy) {
            vis[i]=2;
            sy+=x;
        }
        else {
            vis[i]=vis[i+1]=3;
            i++; sx+=y; sy+=x;
        }
    }
    vis[0]=3;
    while(n--) {
        cin>>m;
        m%=(x+y);
        if(vis[m]==1) cout<<"Vanya\n";
        if(vis[m]==2) cout<<"Vova\n";
        if(vis[m]==3) cout<<"Both\n";
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值