Codeforces Round 280 Div.2 解题报告

A. Vanya and Cubes

Problem Description

给定方块的数目,垒成金字塔形,共可以垒几层

Solution

水题一个

源代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<stdio.h>
#include<string.h>
int n[10010];
int sum[10010];
void init()
{

sum[1]=1;
for(int i=2;i<=10000;i++)
{
sum[i]+=sum[i-1]+(1+i)*i/2;
}
}
int main()
{

int nn;
scanf("%d",&nn);
init();
for(int i=1;i<=10000;i++)
{
if(sum[i]==nn)
{
printf("%d\n",i);
break;
}
if(sum[i]>nn)
{
printf("%d\n",i-1);
break;
}
}
return 0;
}

B. Vanya and Lanterns

Problem Description

给一个坐标轴,以及上面的点,求点的最小覆盖范围,使得所有点能把坐标轴覆盖

Solution

先把点排序一遍,然后求相邻两点间的最大差/2即可,别忘了边界条件。比赛时我的条件判断写蒙了,二判时不知怎么就挂了……

源代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define max(a,b) a>b?a:b
using namespace std;
int main()
{

int a[1010];
int i,j,k;
int n;
int l;
while(scanf("%d%d",&n,&l)!=EOF)
{
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
int now=0;

sort(a+1,a+1+n);
int max_ans = a[1] * 2;
for(i=1;i<=n;i++)
{
max_ans = max(max_ans, a[i] - now);
now = a[i];
}
max_ans = max(max_ans, (l - a[n]) * 2);
printf("%.10lf\n",(double)max_ans/2.0);
}
return 0;
}

C. Vanya and Exams

Problem Description

给定平均分和一些分数以及获得对应科目1分所花费的价值,求达到平均分花费的最小价值

Solution

贪心排遍序即可,比赛中struct里面没开long long又二判判死了……

源代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
struct grade
{
long long a,b;
} g[100010];
int cmp(grade a,grade b)
{

return a.b<b.b;
}
int main()
{

int i,j,k;
long long n,avg,sum,r;
long long cost;
cin>>n>>r>>avg;
cost=0;
sum=0;
for(i=1; i<=n; i++)
{
scanf("%d%d",&g[i].a,&g[i].b);
sum+=g[i].a;
}
if(sum>=n*avg)
{
printf("0\n");
return 0;
}
sort(g+1,g+1+n,cmp);
for(i=1; i<=n; i++)
{
if(avg*n-sum>r-g[i].a)
{
sum+=r-g[i].a;
cost+=g[i].b*(r-g[i].a);
}
else
{
cost+=g[i].b*(avg*n-sum);
break;
}
}
cout<<cost<<endl;
return 0;
}

D. Vanya and Computer Game

Problem Description

自己读题看的会更明白一些……

Solution

先将所求的怪兽的击打数对a+b取模,然后生成1至a+b两个人的击打序列,然后在序列里查找就行了,我中间查找写的有点麻烦,貌似不用seq数组也行……

源代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
long long seq[1000010<<1];
long long times[1000010<<1];
int main()
{

long long a,b,time,sum,big,gcdd,now1,now2;
int n;
while(scanf("%d",&n)!=EOF)
{
cin>>a>>b;
sum=a+b;
big=a*b;
memset(times,-1,sizeof(times));
memset(seq,0,sizeof(seq));
now1=0;
now2=0;
for(int j=1; j<=sum; j++)
{
if(now1+b>now2+a)
{
times[j]=1;
seq[j]=seq[j-1]+1;
now2+=a;
}
else if(now1+b<now2+a)
{
times[j]=2;
seq[j]=seq[j-1]+1;
now1+=b;
}
else
{
times[j]=0;
seq[j]=seq[j-1]+1;
now1+=b;
now2+=a;
j++;
times[j]=0;
seq[j]=seq[j-1]+1;
}
}
for(int i=1; i<=n; i++)
{
cin>>time;
time%=sum;
if(time==0)
time=sum;
if(times[seq[time]]==2)
{
printf("Vanya\n");
}
else if(times[seq[time]]==1)
{
printf("Vova\n");
}
else
{
printf("Both\n");
}
}
}
return 0;
}

今天这场打的还是迷迷糊糊的,该对的不对……但愿下次状态能好点……