题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5373

The shortest problem

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

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
 
 
 
题目大意:将前面的数加起来的得到的和接在后面,并判断最后得到的这个数是否可以被11整除。例如:23->一次变换后235->两次变换后23510
解题思路:想象一下,除以11是怎么除的,每次都是前面的先除存下余数加上后面的继续除。这样的话就算104也不在话下。这里要注意的是后面接上的数字不一定是一位数两位数or三位数。所以要特殊判断下,第一个剩下的余数要乘以几个10。
 
详见代码。(这个需要用G++提交)

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath> using namespace std; int fun(int n)
{
int sum=;
while (n)
{
int a1=n%;
sum+=a1;
n/=;
}
return sum;
} int fun1(int x)
{
int t=;
while (x)
{
t++;
x/=;
}
return t;
} int fun2(int n)
{
int s=;
for (int i=;i<n;i++)
{
s*=;
}
return s;
} int main()
{
int n,t;
int flag=;
while (~scanf("%d%d",&n,&t))
{
if (n==-&&t==-)
break;
int ans=n%;
//cout<<ans<<endl;
int ss=fun(n);
for (int i=; i<t; i++)
{
ans=ans*fun2(fun1(ss))+ss;//pow(10,fun1(ss))+ss;
//cout<<ans<<endl;
ans%=;
//cout<<ans<<endl;
ss+=fun(ss);
//cout<<ss<<endl;
}
if (ans%==)
printf ("Case #%d: Yes\n",flag++);
else
printf ("Case #%d: No\n",flag++);
}
return ;
}

还有另外一种比较省时间的代码。

能被11整除的数的特征 
把一个数由右边向左边数,将奇位上的数字与偶位上的数字分别加起来,再求它们的差,如果这个差是11的倍数(包括0),那么,原来这个数就一定能被11整除。

详见代码。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define ll long long
const double eps = 1e-;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = ; int n,t;
int x,y,k; int main ()
{
int a,b,c,d,e,ii=;
while (scanf ("%d%d",&n,&t)==)
{
if (n==-&&t==-)
break;
a = n/;
b = (n/)%;
c = (n/)%;
d = (n/)%;
e = n%;
//if (d!=0){k++; if(c!=0)k++; if(b!=0)k++; if(a!=0)k++;}
y = d+b;
x = c+a+e; while (t--)
{
k = ;
int p=,q=,m=x+y;
while (m)
{
k++;
if (k%)
p += m%;
else
q += m%;
m /= ;
}
//cout<<p<<" "<<q<<endl;cout<<x<<" "<<y<<endl;
if (k%)
{
x += q;
y += p;
swap(x, y);
}
else
{
x += p;
y += q;
}
}
if ((x-y)%)
printf ("Case #%d: No\n",ii++);
else
printf ("Case #%d: Yes\n",ii++);
}
return ;
}

hdu 5373 The shortest problem(杭电多校赛第七场)的更多相关文章

  1. HDU 4627 The Unsolvable Problem 杭电多校联赛第三场1009 数学题

    题意描述:给出一个n,要求在所有满足n = a+b的a和b里面求a和b的最小公倍数最大的两个数的最小公倍数. 解题报告:比赛的时候看到这个题的第一反应就是寻找这两个数一定是在a和b比较接近的地方找,这 ...

  2. hdu 5328 Problem Killer(杭电多校赛第四场)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5328 题目大意:找到连续的最长的等差数列or等比数列. 解题思路:1.等差等比的性质有很多.其中比较重 ...

  3. hdu 5319 Painter(杭电多校赛第三场)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5319 Painter Time Limit: 2000/1000 MS (Java/Others)   ...

  4. hdu 5326 Work(杭电多校赛第三场)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5326 Work Time Limit: 2000/1000 MS (Java/Others)    M ...

  5. 可持久化线段树的学习(区间第k大和查询历史版本的数据)(杭电多校赛第二场1011)

    以前我们学习了线段树可以知道,线段树的每一个节点都储存的是一段区间,所以线段树可以做简单的区间查询,更改等简单的操作. 而后面再做有些题目,就可能会碰到一种回退的操作.这里的回退是指回到未做各种操作之 ...

  6. 2015 Multi-University Training Contest 7 hdu 5373 The shortest problem

    The shortest problem Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  7. HDU 5373 The shortest problem (数学)

    题意:给定两个数的n和m,有一种操作,把 n 的各位数字加起来放到 n后面形成一个新数n,问重复 m 次所得的数能否整除 11. 析:这个题首先要知道一个规律奇数位的和减去偶数位的和能被11整除的数字 ...

  8. HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 解题报告:输入一个序列,然后有q次操作,操作有两种,第一种是把区间 (l,r) 变成x,第二种是 ...

  9. HDU 5821 Ball (贪心排序) -2016杭电多校联合第8场

    题目:传送门. 题意:T组数据,每组给定一个n一个m,在给定两个长度为n的数组a和b,再给定m次操作,每次给定l和r,每次可以把[l,r]的数进行任意调换位置,问能否在转换后使得a数组变成b数组. 题 ...

随机推荐

  1. Windows下多线程编程(一)

    前言 熟练掌握Windows下的多线程编程,能够让我们编写出更规范多线程代码,避免不要的异常.Windows下的多线程编程非常复杂,但是了解一些常用的特性,已经能够满足我们普通多线程对性能及其他要求. ...

  2. [翻译]API Guides - Layouts

    官方文档地址:http://developer.android.com/guide/topics/ui/declaring-layout.html PS:API Guides里面的内容不免都简单些,翻 ...

  3. Java List部分截取,获得指定长度子集合

    subList方法用于获取列表中指定范围的子列表,该列表支持原列表所支持的所有可选操作.返回列表中指定范围的子列表. 语法 subList(int fromIndex, int toIndex) fr ...

  4. spring 整合 struts2 + Hibernate application配置文件(基于注解)

    下面是 application.xml 文件. <?xml version="1.0" encoding="UTF-8"?> <beans x ...

  5. mvc4中使用部分视图局部刷新实例

    如上效果图,网页中有主视图(上)和部分视图(下),点击提交会把文本框中的值发送到服务器,再返回所有添加的信息,在下方局部更新(只更新部分视图),实现如下: 1.网页主视图代码: @model MvcA ...

  6. 【.Net】Net开发

    博客里的好多文章都是本人看着比较好,就转过来的,好少自己亲自去写点什么,也很少把自己学的一点心得于大家分享,今天特别想聊一下,关于本人做Net开发时的那段回忆! 一.关于知识的回忆 还记得Handle ...

  7. bzoj1923[Sdoi2010]外星千足虫(高斯消元)

    Description Input 第一行是两个正整数 N, M. 接下来 M行,按顺序给出 Charles 这M次使用“点足机”的统计结果.每行 包含一个“01”串和一个数字,用一个空格隔开.“01 ...

  8. hdu6021[BestCoder #93] MG loves string

    这场BC实在是有趣啊,T2是个没有什么算法但是细节坑的贪心+分类讨论乱搞,T3反而码起来很顺. 然后出现了T2过的人没有T3多的现象(T2:20人,T3:30人),而且T2的AC率是惨烈的不到3% ( ...

  9. 创建 cachingConfiguration 的配置节处理程序时出错: 未能加载文件或

    C:\Users\xxx\Documents\IISExpress\config\applicationhost.config 将这里面带的项目路径替换成你当前路径 {"创建 caching ...

  10. Python敏感地址扫描和爬取工具

    0×01 说明: 为了方便信息安全测评工作,及时收集敏感地址(初衷是爬取api地址),所以写了这么个小工具.两个简单的功能(目录扫描和url地址爬取). 0×02 使用参数: python spide ...