Home >Web Front-end >HTML Tutorial >Codeforces Round #274 (Div. 2) Solution Report_html/css_WEB-ITnose

Codeforces Round #274 (Div. 2) Solution Report_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:56:031018browse

Question address: http://codeforces.com/contest/479

This time I can only answer 4 questions.

Question A: Expression

Water question.

Just enumerate six situations and find the maximum value.

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 __int64int main(){    LL a, b, c, d[10];    while(scanf("%I64d%I64d%I64d",&a,&b,&c)!=EOF)    {        d[0]=a*b*c;        d[1]=(a+b)*c;        d[2]=a+b+c;        d[3]=a*(b+c);        d[4]=a+b*c;        d[5]=a*b+c;        sort(d,d+6);        printf("%I64d\n",d[5]);    }    return 0;}

Question B: Towers

Water question.

Every time, one of the largest ones is given to the smallest one, until the difference between the largest one and the smallest one is less than or equal to 1.

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 __int64struct node{    int x, num;}fei[1000];int cmp(node x, node y){    return x.x<y.x;}int a[2000], b[2000];int main(){    int n, m, i, j, cnt, ans;    while(scanf("%d%d",&n,&m)!=EOF)    {        for(i=0;i<n;i++)        {            scanf("%d",&fei[i].x);            fei[i].num=i;        }        cnt=0;        while(m--)        {            sort(fei,fei+n,cmp);            if(fei[n-1].x-fei[0].x<=1) break;            a[cnt]=fei[n-1].num;            b[cnt++]=fei[0].num;            fei[n-1].x--;            fei[0].x++;        }        sort(fei,fei+n,cmp);        printf("%d %d\n",fei[n-1].x-fei[0].x, cnt);        for(i=0;i<cnt;i++)        {            printf("%d %d\n",a[i]+1,b[i]+1);        }    }    return 0;}

Question C: Exams

Still water. . Little greedy

Little greedy. First sort them by the marked date, and then scan them. If you can use the smaller ones, give priority to the smaller ones.

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 __int64struct node{    int x, y;}fei[6000];int cmp(node x, node y){    if(x.x==y.x)        return x.y<y.y;    return x.x<y.x;}int main(){    int n, i, j, ans, k, x1, x2;    while(scanf("%d",&n)!=EOF)    {        for(i=0;i<n;i++)        {            scanf("%d%d",&fei[i].x,&fei[i].y);        }        sort(fei,fei+n,cmp);        k=1;        for(i=0;i<n;i++)        {            if(fei[i].y>=k)            {                k=fei[i].y;            }            else            {                k=fei[i].x;            }        }        printf("%d\n",k);    }    return 0;}

Question D:

Still water. . . . Two points.

Consider 4 situations respectively, x, y, x y, y-x. Then use two points to find the difference between these four numbers.

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 __int64int a[110000];int bin_search(int x, int y, int high){    int low=0, mid;    while(low<=high)    {        mid=low+high>>1;        if(y-a[mid]==x) return 1;        else if(y-a[mid]>x) low=mid+1;        else high=mid-1;    }    return 0;}int main(){    int n, l, x, y, i, j, k, flag1, flag2;    while(scanf("%d%d%d%d",&n,&l,&x,&y)!=EOF)    {        flag1=flag2=0;        for(i=0; i<n; i++)        {            scanf("%d",&a[i]);            if(a[i]==x)                flag1=1;            if(a[i]==y)                flag2=1;        }        if(flag1&&flag2)        {            printf("0\n");        }        else        {            flag1=flag2=0;            for(i=1;i<n;i++)            {                if(bin_search(x,a[i],i-1))                {                    flag1=1;                    break;                }            }            for(i=1;i<n;i++)            {                if(bin_search(y,a[i],i-1))                {                    flag2=1;                }            }            if(flag1&&flag2)            {                printf("0\n");            }            else if(flag1) printf("1\n%d\n",y);            else if(flag2) printf("1\n%d\n",x);            else            {                int flag=0;                for(i=1;i<n;i++)                {                    if(bin_search(y+x,a[i],i-1))                    {                        flag=1;                        break;                    }                }                if(flag)                {                    printf("1\n%d\n",a[i]-x);                }                else                {                    flag=0;                    for(i=1;i<n;i++)                    {                        if(bin_search(y-x,a[i],i-1)&&(a[i]-y>=0||a[i]+x<=l))                        {                            flag=1;                            break;                        }                    }                    if(flag&&a[i]-y>=0)                    {                        printf("1\n%d\n",a[i]-y);                    }                    else if(flag&&a[i]+x<=l)                    {                        printf("1\n%d\n",a[i]+x);                    }                    else                    {                        printf("2\n%d %d\n",x,y);                    }                }            }        }    }    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