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
  • 相关阅读:
    【云图】如何制作附近实体店的地图?-微信微博支付宝
    【云图】如何设置支付宝里的家乐福全国连锁店地图?
    【云图】如何设置微信里的全国实体店地图?
    【云图】如何制作官网上的实体店分布图?
    MYSQL 锁机制 分析
    数据结构-线性表-栈-递归
    mysql 异步执行 query //@todo
    C语言操作mysql
    linux gcc头文件搜索路径
    LINUX下动态库及版本号控制
  • 原文地址:https://www.cnblogs.com/clliff/p/4722296.html
Copyright © 2011-2022 走看看