Home  >  Article  >  Web Front-end  >  Codeforces Round #280 (Div. 2) Solution Report A.B.C.D.E._html/css_WEB-ITnose

Codeforces Round #280 (Div. 2) Solution Report A.B.C.D.E._html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:52:561041browse

I don’t know whether it’s because my level has improved or because the CF questions have changed. . . . . .

A - Vanya and Cubes

Water question. . Violent enumeration will do. .

The code is as follows:

#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;#define LL __int64const int INF=0x3f3f3f3f;int s[100], sum[100];int main(){        int n, i;        s[1]=1;        sum[i]=1;        scanf("%d",&n);        for(i=2;i<=10000;i++){                s[i]=s[i-1]+i;                sum[i]=sum[i-1]+s[i];                if(sum[i]>=n)break;        }        printf("%d\n",i-1);        return 0;}

B - Vanya and Lanterns

Water question. . Violently find the shortest distance/2 between two adjacent ones, and then compare it with the boundary to find the longest distance.

The code is as follows:

#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;#define LL __int64const int INF=0x3f3f3f3f;int a[2000];int main(){        int n, l, i, j;        double d, max1=-1;        scanf("%d%d",&n,&l);        a[0]=0;        a[n+1]=l;        for(i=1;i<=n;i++){                scanf("%d",&a[i]);        }        sort(a,a+n+2);        for(i=2;i<=n;i++){                max1=max(max1,(a[i]-a[i-1])/2.0);        }        max1=max(max1,a[1]-0.0);        max1=max(max1,l*1.0-a[n]);        printf("%.10lf\n",max1);        return 0;}

C - Vanya and Exams

Greedy.

Start with the fewest papers required and add up.

The code is as follows:

#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;#define LL __int64const int INF=0x3f3f3f3f;struct node{        LL f, e;}fei[110000];int cmp(node x, node y){        return x.e<y.e;}int main(){        int i;        LL n, r, ave, s, sum, ss, ans=0;        scanf("%I64d%I64d%I64d",&n,&r,&ave);        sum=n*ave;        s=0;        for(i=0;i<n;i++){                scanf("%I64d%I64d",&fei[i].f,&fei[i].e);                s+=fei[i].f;        }        ss=sum-s;        if(ss<=0)        {                printf("0\n");                return 0;        }        sort(fei,fei+n,cmp);        //printf("%d\n",ss);        for(i=0;i<n;i++){                if(fei[i].f>=r) continue ;                if(ss-(r-fei[i].f)<=0){                        ans+=ss*fei[i].e;                        break;                }                else{                        ss-=r-fei[i].f;                        ans+=fei[i].e*(r-fei[i].f);                }                //printf("%d\n",ss);        }        printf("%I64d\n",ans);        return 0;}

D - Vanya and Computer Game

I thought of the two-point time during the game. I have never figured out how to tell who it is after finding the time. . It dawned on me the next day. . Just judge whether it is divisible or not. . . . Why didn't I think of that at the time? . . depressed. .

First zoom in on the time axis, zoom in 1/x and 1/y seconds to y and x, and then divide the time into two halves. After finding the time, judge whether it is divisible.

The code is as follows:

#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;#define LL __int64const int INF=0x3f3f3f3f;int main(){        LL n, x, y, i, z, low, high, mid, ans;        scanf("%I64d%I64d%I64d",&n, &x, &y);        while(n--) {                scanf("%I64d",&z);                low=1;                high=1e16;                while(low<=high) {                        mid=low+high>>1;                        if(mid/x+mid/y>=z) {                                high=mid-1;                                ans=mid;                        }                        else low=mid+1;                }                if(ans%x==0&&ans%y==0) puts("Both");                else if(ans%x==0) puts("Vova");                else puts("Vanya");        }        return 0;}

E - Vanya and Field

I feel like the E question this time is good. . . First of all, because gcd is 1, it can be guaranteed that all n numbers can be accessed and will not be repeated. So you can let him start from a certain point with the abscissa 0 by default. Then when the ordinate is 0, a mapping relationship between the x coordinate and the y coordinate can be found and saved. Then every time you enter a coordinate, you can use a formula to determine which point it starts from. Then just find the most starting point.

The code is as follows:

#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;#define LL __int64const int INF=0x3f3f3f3f;int _hash[1100000], a[1100000];int main(){        int n, m, dx, dy, i, j, x, y, pos, max1;        scanf("%d%d%d%d",&n,&m,&dx,&dy);        x=y=0;        for(i=0;i<n;i++){                a[x]=y;                x=(x+dx)%n;                y=(y+dy)%n;        }        memset(_hash,0,sizeof(_hash));        while(m--){                scanf("%d%d",&x,&y);                _hash[(y+n-a[x])%n]++;        }        max1=-1;        for(i=0;i<n;i++){                if(max1<_hash[i]){                        max1=_hash[i];                        pos=i;                }        }        printf("0 %d\n",pos);        return 0;}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn