CF-Contest339-614

614A-Link/Cut Tree

比较水,注意64位int仍然可能溢出。

#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

typedef unsigned long long int LL;

LL l,r;
int k;

int main()
{
    scanf("%I64d %I64d %d",&l,&r,&k);
    int cnt = 0;
    LL pow = 1;
    int i = 0;
    while(true)
    {
        if(pow <=r && pow >=l)
        {
            printf("%s%I64d",cnt?" ":"",pow);
            cnt++;
        }
        i++;
        if(pow > r) break;
        if(r/k < pow) break;
        pow *= k;
    }
    if(cnt == 0) printf("-1
");
}

614B-Gena's Code

很水,统计0的个数就好了

区分beautiful和非beautiful数。

#include <cstdio>
#include <cstring>

using namespace std;

int N,n0;
char unbtf[100100];

int main()
{
    scanf("%d",&N);
    int flag_unb = 0;
    int flag_0 = 0;
    getchar();

    for(int i=0;i<N;i++)
    {
        char c;
        int cnt = 0,flag = 1,tmp0 = 0;
        while((c=getchar()) && c>='0' && c<='9')
        {
            if(!flag_unb) unbtf[cnt] = c;
            if((c!='0'&&cnt!=0) || (c!='1'&&c!='0'&&cnt==0))
            {
                flag = 0;
            }
            if(c == '0') tmp0++;
            cnt++;
        }
        if(!flag_unb) unbtf[cnt] = '';
        if(cnt == 1 && tmp0 == 1) flag_0 = 1;
        if(flag&&cnt>1) n0 += tmp0;
        else if(!flag)flag_unb = 1;
    }

    if(flag_0)
    {
        printf("0
");
        return 0;
    }

    if(flag_unb) printf("%s",unbtf);
    else printf("1");
    for(int i=0;i<n0;i++)
        printf("0");
    printf("
");
}
原文地址:https://www.cnblogs.com/helica/p/5167898.html