A. Vanya and Cubes
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.
The first line contains integer n (1 ≤ n ≤ 104) — the number of cubes given to Vanya.
Print the maximum possible height of the pyramid in the single line.
1
1
25
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
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?
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.
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.
7 15 15 5 3 7 9 14 0
2.5000000000
2 5 2 5
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
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?
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).
In the first line print the minimum number of essays.
5 5 4 5 2 4 7 3 1 3 2 2 5
4
2 5 4 5 2 5 2
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
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.
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.
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.
4 3 2 1 2 3 4
Vanya Vova Vanya Both
2 1 1 1 2
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;
}