CF Codeforces Round #231 (Div. 2)

http://codeforces.com/contest/394

话说这次CF做的超级不爽,A题一开始交过了,我就没再管,B题还没看完呢,就死困死困的,后来觉得B题枚举一下估计能行,当时是觉得可以从后往前乘,但是细节什么的都没想好,所以干在纸上画也没写出什么来。没想到我A题竟然忘了一种情况,就是+前就一根的时候,郁闷死我了。

A  Counting Sticks

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <stdlib.h>

using namespace std ;

int main()
{
    char sh[5200] ;
    while(~scanf("%s",sh))
    {
        int len = strlen(sh) ;
        int left = 0,right = 0 ;
        for(int i = 0 ; i < len ; i++)
        {
            if(sh[i] != '=')
                left++ ;
            else
                break ;
        }
        right = len-left-1 ;
        left -= 1 ;
        if(right == left)
        {
            printf("%s
",sh) ;
            continue ;
        }
        else if(right -1 == left +1)
        {
            printf("|") ;
            for(int i = 0 ; i < len-1 ; i++)
                printf("%c",sh[i]) ;
            printf("
") ;
        }
        else if(right + 1 == left - 1)
        {
            if(sh[1] == '+')
            {
                printf("|+") ;
                for(int i = 3 ; i < len ; i++)
                    printf("%c",sh[i]) ;
            printf("|
") ;
            }
            else
            {
                for(int i = 1 ; i < len ; i++)
                printf("%c",sh[i]) ;
                printf("|
") ;
            }
        }
        else printf("Impossible
") ;
    }
    return 0 ;
}
View Code

Very Beautiful Number

用的乘法,跑时171ms,看了一个人的代码用了62ms,看他用的是除法,其实这些个原理都差不多,不懂的可以去百度。

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>

using namespace std ;

char ch[45456798] ;

int  main()
{
    int p,x ;
    while(~scanf("%d %d",&p,&x))
    {
        int flag = 0 ;
        for(int i = 1 ; i < 10 ; i++)
        {
            memset(ch,0,sizeof(ch)) ;
            ch[0] = ch[p] = i + '0' ;
            int s = 0 ;
            for(int j = p ; j > 0 ; j--)
            {
                int k = (ch[j]-'0')*x ;
                ch[j-1] = (k+s)%10+'0' ;
                s = (k+s)/10 ;
            }
            if(s == 0 && ch[0] == ch[p] && ch[1] != '0')
            {flag = 1 ;
            break ;}
        }
        if(flag){
        for(int i = 1 ; i <= p ; i++)
        printf("%c",ch[i]) ;
        printf("
") ;
        }
        else
        printf("Impossible
") ;
    }
    return 0 ;
}
View Code
#include <iostream>
using namespace std;

char nums[1000001];

int main()
{
    int p,x;
    cin>>p>>x;
    for(int i = x ; i < 10 ; ++i)
    {
        int n = i , a , b ;
        for(int j = 0 ; j < p ; ++j)
        {
            a = n/x, b = n % x ;
            n = b*10+a;
            nums[j] = '0'+a;
        }
        nums[p] = '';
        if(a==i && b==0)
        {
            cout<<nums<<endl;
            break;
        }
        if(i==9)cout<<"Impossible"<<endl;
    }
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/luyingfeng/p/3559488.html