关闭

HDU 5373 The shortest problem(模拟)——2015 Multi-University Training Contest 7

标签: 模拟
469人阅读 评论(0) 收藏 举报
分类:

传送门

The shortest problem

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


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

题目大意:

给你一个数 n(n104),然后你可以每次求得这个数 n 的每一位数的和,算出来加在

n 的后面组成一个新的数,操作 t(t105) 次,问 t 次之后的结果是不是能够被 11

整除。

解题思路:

就是按照题意进行模拟,然后需要知道的是被 11 整除有一个特点:所有的奇数位上的

和与所有偶数位上和的差能够被 11 整除,根据这个特点就可以做了,每次用一个数

组,保存每一位的值,进行判断就行了。

My Code

/**
2016 - 08 - 29 下午
Author: ITAK

Motto:

今日的我要超越昨日的我,明日的我要胜过今日的我,
以创作出更好的代码为目标,不断地超越自己。
**/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9+5;
const int MAXN = 1e6+5;
const int MOD = 1e9+7;
const double eps = 1e-7;
const double PI = acos(-1);
using namespace std;
LL Scan_LL()///输入外挂
{
    LL res=0,ch,flag=0;
    if((ch=getchar())=='-')
        flag=1;
    else if(ch>='0'&&ch<='9')
        res=ch-'0';
    while((ch=getchar())>='0'&&ch<='9')
        res=res*10+ch-'0';
    return flag?-res:res;
}
int Scan_Int()///输入外挂
{
    int res=0,ch,flag=0;
    if((ch=getchar())=='-')
        flag=1;
    else if(ch>='0'&&ch<='9')
        res=ch-'0';
    while((ch=getchar())>='0'&&ch<='9')
        res=res*10+ch-'0';
    return flag?-res:res;
}
void Out(LL a)///输出外挂
{
    if(a>9)
        Out(a/10);
    putchar(a%10+'0');
}
int a[MAXN];
int main()
{
    int t, cas = 1, n;
    while(cin>>n>>t)
    {
        if(n==-1 && t==-1)
            break;
        int tmp = n, cnt = 1, sum = 0;
        memset(a, 0, sizeof(a));
        while(tmp)
        {
            a[cnt++] = tmp%10;
            sum += (tmp%10);
            tmp /= 10;
        }
        for(int i=1; i<=cnt/2; i++)
            swap(a[i], a[cnt-i]);
        int sum1 = 0, sum2 = 0, tp;
        for(int i=1; i<cnt; i++)
        {
            if(i & 1)
                sum1 += a[i];
            else
                sum2 += a[i];
        }
        ///cout<<"sum1 = "<<sum1<<endl<<"sum2 = "<<sum2<<endl;
        while(t--)
        {
            tmp = sum, tp = cnt;
            ///cout<<"sum = "<<sum<<endl;
            while(tmp)
            {
                a[cnt++] = tmp%10;
                sum += (tmp%10);
                tmp /= 10;
            }
            for(int i=tp; i<=(cnt-1+tp)/2; i++)
                swap(a[i], a[cnt-i+tp-1]);
            /**for(int i=1; i<cnt; i++)
                cout<<"a[i] = "<<a[i]<<endl;
            cout<<"+++++++++++++++++++++++"<<endl;*/
            for(int i=tp; i<cnt; i++)
            {
                if(i & 1)
                    sum1 += a[i];
                else
                    sum2 += a[i];
            }
        }
        ///cout<<"sum1 = "<<sum1<<endl<<"sum2 = "<<sum2<<endl;
        if(abs(sum1-sum2) % 11 == 0)
            printf("Case #%d: Yes\n",cas++);
        else
            printf("Case #%d: No\n",cas++);
    }
    return 0;
}
0
0
查看评论
发表评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场

多示例学习(Multi Instance Learning)的概念

多示例学习(Multi Instance Learning)
  • roypi
  • roypi
  • 2014-10-10 14:51
  • 7557

多臂赌博机,multi-armed bandit problem(1):

感觉多臂赌博机方面的中文文献很少,偶尔碰到,记录一下,方便其它人学习。感谢原作者:http://mlyixi.byethost32.com/blog/?tag=%E5%A4%9A%E8%87%82%E...
  • mmc2015
  • mmc2015
  • 2016-04-26 09:11
  • 11458

HDU2056 Rectangles 【矩形面积交】

Rectangles Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...
  • u012846486
  • u012846486
  • 2015-01-19 10:26
  • 1228

HDU 5319 Painter(模拟 + 规律)——2015 Multi-University Training Contest 3

传送门 PainterTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot...
  • qingshui23
  • qingshui23
  • 2016-08-24 17:25
  • 746

HDU 5387 Clock(简单模拟)——2015 Multi-University Training Contest 8

传送门 ClockTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total...
  • qingshui23
  • qingshui23
  • 2016-08-31 14:14
  • 502

HDU 5402 Travelling Salesman Problem (2015 Multi-University Training Contest 9 2015多校联合)

题目传送门:HDU5402 Travelling Salesman Problem Travelling Salesman Problem Time Limit: 3000/1500 MS...
  • wangcong9614
  • wangcong9614
  • 2015-08-19 09:23
  • 381

HDU 5328 Problem Killer (2015 Multi-University Training Contest 4 2015多校联合)

这道题就是给你一列数组。求里边等差或者等比最长的序列长度。比较简单,但是卡数据。就是等比有可能公比是非整数。需要考虑到这一点。然后输入的时候,依次算出公比和公差,然后累加判断就可以了。 代码如下: #...
  • wangcong9614
  • wangcong9614
  • 2015-07-31 20:11
  • 239

hdu 5349 MZL's simple problem 2015 Multi-University Training Contest 5

这一题用map, multiset, priority_queue直接模拟都可以。注意每一个test case里可能输入多个N,之前因为这个TLE了。另外,因为题目只要输出最大值,可以直接在输入的时候...
  • yixin94
  • yixin94
  • 2015-08-27 22:32
  • 384

HDU 5318 The Goddess Of The Moon(构造矩阵 )——2015 Multi-University Training Contest 3

传送门 The Goddess Of The MoonTime Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K ...
  • qingshui23
  • qingshui23
  • 2016-08-25 20:09
  • 776

HDU 5407 CRB and Candies(素数筛 + 逆元 + 组合数公式)——2015 Multi-University Training Contest 10

传送门CRB and CandiesTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others...
  • qingshui23
  • qingshui23
  • 2016-09-02 13:43
  • 692
    个人资料
    • 访问:506731次
    • 积分:11326
    • 等级:
    • 排名:第1597名
    • 原创:639篇
    • 转载:5篇
    • 译文:0篇
    • 评论:93条
    博客专栏