zoukankan      html  css  js  c++  java
  • 2015 Multi-University Training Contest 7 1005

    The shortest problem

    Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 380    Accepted Submission(s): 186


    Problem Description
    In this problem, we should solve an interesting game. At first, we have an integer n, then we begin to make some funny change. We sum up every digit of the n, then insert it to the tail of the number n, then let the new number be the interesting number n. repeat it for t times. When n=123 and t=3 then we can get 123->1236->123612->12361215.
     
    Input
    Multiple input.
    We have two integer n (0<=n<=104 ) , t(0<=t<=105) in each row.
    When n==-1 and t==-1 mean the end of input.
     
    Output
    For each input , if the final number are divisible by 11, output “Yes”, else output ”No”. without quote.
     
    Sample Input
    35 2
    35 1
    -1 -1
     
    Sample Output
    Case #1: Yes
    Case #2: No
     
    Source
     
    题意:将前面的每位数相加得到的数加到最后,如此往复执行n次,问最后得到的数字能否被11整除
    分析:模拟一次就行,注意答案可能计算中的结果可能会超int
    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<string>
    #include<iostream>
    #include<cstring>
    #include<cmath>
    #include<stack>
    #include<queue>
    #include<vector>
    #include<map>
    #include<stdlib.h>
    #include<algorithm>
    #define LL __int64
    using namespace std;
    LL num,n,ans,sum;
    
    LL calc(LL x)
    {
        LL res=0;
        while(x)
        {
            res+=x%10;
            x=x/10;
        }
        return res;
    }
    
    LL count_digit(LL x)
    {
        if(x==0) return 10;
        LL ok=1;
        while(x)
        {
            x=x/10;
            ok=ok*10;
        }
        return ok;
    }
    int main()
    {
        //freopen("in.txt","r",stdin);
        int Case=0;
        while(scanf("%I64d %I64d",&num,&n)!=EOF)
        {
            if(num==-1 && n==-1) break;
    
            ans=calc(num);//ans表示当前要加在后排的数
            sum=num;//sum表示累加的和
            for(int i=1;i<=n;i++)
            {
                sum=sum*count_digit(ans)+ans;
                sum=sum%11;
                ans=ans+calc(ans);
            }
    
            printf("Case #%d: ",++Case);
            if(sum%11==0) printf("Yes
    ");
            else printf("No
    ");
        }
        return 0;
    }
    View Code
  • 相关阅读:
    selenium(七)expected_conditions EC
    Alpine Linux常用命令
    python logging模块,升级print调试到logging。
    用flask Flask-RESTful,实现RESTful API
    python,判断操作系统是windows,linux
    在docker hub,用github的dockerfile自动生成docker镜像
    解决pycharm问题:module 'pip' has no attribute 'main'
    alpine linux docker 安装 lxml出错的解决办法。
    (转载)服务端技术选型
    maven的pom文件
  • 原文地址:https://www.cnblogs.com/clliff/p/4722296.html
Copyright © 2011-2022 走看看