题目链接: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. VC的常用调试方法

    前言 VS是非常强大的IDE,所以掌握VSVC的常用方法,将会使得我们找出问题解决问题事半功倍. 目录 VSVC的常用调试方法 前言 1. Watch窗口查看伪变量 2. 查看指针指向的一序列值 3. ...

  2. caffe框架下目标检测——faster-rcnn实战篇问题集锦

    1.问题 解决方案:没编译好,需要在lib下编译make 需要在caffe-fast-rcnn下编译make或者make all -j16  ,还需要make pycaffe 2.问题 解决方案:/p ...

  3. [洛谷P1642]规划

    题目大意:有一棵$n(n\leqslant100)$个点的树,每个点有两个权值$a,b$,要求选择一个$m$个点的连通块$S$,最大化$\dfrac{\sum\limits_{i\in S}a_i}{ ...

  4. 基于注解的spring mvc 中使用 ajax json 的model

    在 Spring mvc3中,响应.接受 JSON都十分方便. 使用注解@ResponseBody可以将结果(一个包含字符串和JavaBean的Map),转换成JSON. 使用 @RequestBod ...

  5. 那些你不常用却非常有用的MySql语句和命令

    操作数据库 关于数据库的操作比较少,主要是:看.建.用.删. 查看数据库 获取服务器上的数据库列表通常很有用.执行show databases;命令就可以搞定. 1 mysql> show da ...

  6. php 修改图片分辨率

    <?php function resize_image($file, $w, $h, $crop=FALSE) { list($width, $height) = getimagesize($f ...

  7. Maven仓库--Nexus的配置使用

    一.Nexus的作用 指定私服的中央地址.将自己的Maven项目指定到私服地址.从私服下载中央库的项目索引.从私服仓库下载依赖组件.将第三方项目jar上传到私服供其他项目组使用. 二.Nexus仓库 ...

  8. 「Django」rest_framework学习系列-序列化

    序列化方式一 :在业务类里序列化数据库数据 class RolesView(APIView): def get(self,request,*args,**kwargs): roles = models ...

  9. checkbox选择根据后台List数据进行回显

    需求:记住用户已经选择的 checkbox 选项,当用户再次对该 checkbox 进行选择操作时,应对该用户已经选择的 checkbox 选项进行选中操作. 示例代码: checkbox,js遍历后 ...

  10. HNOI2004 宠物收养所 (Treap)

    1285 宠物收养所 http://codevs.cn/problem/1285/  时间限制: 1 s  空间限制: 128000 KB     题目描述 Description 最近,阿Q开了一间 ...