Home  >  Article  >  Web Front-end  >  Codeforces Round #276 (Div. 2) Solution Report_html/css_WEB-ITnose

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

WBOY
WBOYOriginal
2016-06-24 11:54:36978browse

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

Question A: Factory

Simulate according to the process and determine whether a loop occurs. If a loop occurs, The explanation is definitely impossible and jumps out directly.

The code is as follows:

#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;int _hash[100001];int main(){    int a, m, i, flag=0;    memset(_hash,0,sizeof(_hash));    scanf("%d%d",&a,&m);    a=a%m;    _hash[a]=1;    while(1)    {        a=a*2%m;        if(a==0)        {            flag=1;            break;        }        if(_hash[a])        {            break;        }        _hash[a]=1;    }    if(!flag) puts("No");    else        puts("Yes");    return 0;}

Question B: Valuable Resources

Directly find the maximum and minimum values ​​of rows and columns, Not much to say

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 LL INF=1e11;int main(){    LL n, x, y, max1, max2, min1, min2, s;    while(scanf("%I64d",&n)!=EOF)    {        max1=-INF;        max2=-INF;        min1=INF;        min2=INF;        while(n--)        {            scanf("%I64d%I64d",&x,&y);            max1=max(max1,x);            max2=max(max2,y);            min1=min(min1,x);            min2=min(min2,y);        }        s=max(max1-min1,max2-min2);        s*=s;        printf("%I64d\n",s);    }    return 0;}

Question C: Bits

Greedy

Start small , keep adding 1 starting from the low bit until it is greater than the larger number.

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 LL INF=1e11;int s[1000];int main(){    int n, len, max1;    LL x, y, z1, z, i;    scanf("%d",&n);    while(n--)    {        scanf("%I64d%I64d",&x,&y);        z1=x;        len=0;        memset(s,0,sizeof(s));        while(z1)        {            s[len++]=z1%2;            z1/=2;        }        z=x;        for(i=0;i<100;i++)        {            if(s[i]==0)            {                x+=(LL)1<<i;                //printf("%d\n",1<<i);                if(x>y)                {                    printf("%I64d\n",z);                    break;                }                z=x;            }        }    }    return 0;}

Question D: Maximum Value

For x, in k*x~(k 1) Within the range of Just update.

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[2100000], dp[2100000], a[2100000];int main(){    int n, i, j, x, min1, ans, max1;    while(scanf("%d",&n)!=EOF)    {        memset(_hash,0,sizeof(_hash));        min1=INF;        max1=-1;        for(i=0; i<n; i++)        {            scanf("%d",&x);            _hash[x]=1;            min1=min(min1,x);            max1=max(max1,x);        }        for(i=min1; i<=2000000; i++)        {            if(_hash[i-1]) dp[i]=i-1;            else dp[i]=dp[i-1];        }        ans=0;        for(i=1; i<=1000000; i++)        {            if(_hash[i])            {                for(j=2*i; ; j+=i)                {                    if(dp[j]<i) continue ;                    ans=max(ans,dp[j]%i);                    if(dp[j]==max1) break;                    //printf("%d %d\n",j,ans);                }            }        }        printf("%d\n",ans);    }    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