hdu 5373 The shortest problem(杭电多校赛第七场)
题目链接: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
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.
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.
11, output “Yes”, else output ”No”. without quote.
#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(杭电多校赛第七场)的更多相关文章
- HDU 4627 The Unsolvable Problem 杭电多校联赛第三场1009 数学题
题意描述:给出一个n,要求在所有满足n = a+b的a和b里面求a和b的最小公倍数最大的两个数的最小公倍数. 解题报告:比赛的时候看到这个题的第一反应就是寻找这两个数一定是在a和b比较接近的地方找,这 ...
- hdu 5328 Problem Killer(杭电多校赛第四场)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5328 题目大意:找到连续的最长的等差数列or等比数列. 解题思路:1.等差等比的性质有很多.其中比较重 ...
- hdu 5319 Painter(杭电多校赛第三场)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5319 Painter Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 5326 Work(杭电多校赛第三场)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5326 Work Time Limit: 2000/1000 MS (Java/Others) M ...
- 可持久化线段树的学习(区间第k大和查询历史版本的数据)(杭电多校赛第二场1011)
以前我们学习了线段树可以知道,线段树的每一个节点都储存的是一段区间,所以线段树可以做简单的区间查询,更改等简单的操作. 而后面再做有些题目,就可能会碰到一种回退的操作.这里的回退是指回到未做各种操作之 ...
- 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 ...
- HDU 5373 The shortest problem (数学)
题意:给定两个数的n和m,有一种操作,把 n 的各位数字加起来放到 n后面形成一个新数n,问重复 m 次所得的数能否整除 11. 析:这个题首先要知道一个规律奇数位的和减去偶数位的和能被11整除的数字 ...
- HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 解题报告:输入一个序列,然后有q次操作,操作有两种,第一种是把区间 (l,r) 变成x,第二种是 ...
- HDU 5821 Ball (贪心排序) -2016杭电多校联合第8场
题目:传送门. 题意:T组数据,每组给定一个n一个m,在给定两个长度为n的数组a和b,再给定m次操作,每次给定l和r,每次可以把[l,r]的数进行任意调换位置,问能否在转换后使得a数组变成b数组. 题 ...
随机推荐
- phpcms前端模板目录与文件结构分析图【templates】
phpcms前端模板目录与文件结构分析图[templates] 原文地址:http://www.iphpcms.net/phpcms-ziliao/2015_14.html
- mysql中联合查询
联合查询union 一个翻译问题的解释: 在mysql的手册中,将连接查询(Join)翻译为联合查询: 而联合查询(union),没有明确翻译. 但: 在通常的书籍或文章中,join被翻译为“连接”查 ...
- HDU4759_Poker Shuffle
这是一个很好的题目,来自2013长春网赛. 题目的意思是给你2^N张扑克牌,每次洗牌前分别把从下开始数为奇数和偶数的牌分别拿出来放在一堆,两堆可以任意一个放在上面. 现在问你是否存在一种情况使得经过若 ...
- solr服务器的查询过程
SolrDispatchFilter的作用 This filter looks at the incoming URL maps them to handlers defined in solrcon ...
- xpose修改手机imei码,注入广告
何为hook Hook英文翻译过来就是“钩子”的意思,那我们在什么时候使用这个“钩子”呢? 我们知道,在Android操作系统中系统维护着自己的一套事件分发机制.应用程序,包括应用触发事件和后台逻 ...
- Insert Node in Sorted Linked List
Insert a node in a sorted linked list. Have you met this question in a real interview? Yes Example ...
- NOIP2017 列队 题解报告【56行线段树】
题目描述 Sylvia 是一个热爱学习的女♂孩子. 前段时间,Sylvia 参加了学校的军训.众所周知,军训的时候需要站方阵. Sylvia 所在的方阵中有n \times mn×m名学生,方阵的行数 ...
- 【bzoj3796】Mushroom追妹纸
Portal -->bzoj3796 Description 给出字符串s1.s2.s3,找出一个字符串w,满足: 1.w是s1的子串: 2.w是s2的子串: 3.s3不是w的子串. 求w的 ...
- 简述this,call,apply,bind之间的关系
一.什么是this? this是JavaScript语言的一个关键字,它是函数运行时在函数体内部自动生成的一个对象,只能在函数体内部使用.函数的不同使用场合,this的指向不同. 在ES5中,this ...
- UESTC--1732
原题链接:http://acm.uestc.edu.cn/problem.php?pid=1732 分析:dp,n个相同物品放入m个相同的盒子(允许为空)的个数为dp[n][m]=dp[n][m-1] ...