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数组. 题 ...
随机推荐
- laravel 字段映射问题,表单中提交字段与数据表中字段不一致
在遇到提交表单时,表单中的name属性与数据表中的字段不一致,报错, 解决方法: 参考1:提交表单的时候,表单的name属性和数据表字段名称是一样的,这样有什么不妥么? 你数据库的信息给前端透露得越多 ...
- 【C++】构造函数不能是虚函数
1 虚函数对应一个vtable,这大家都知道,可是这个vtable其实是存储在对象的内存空间的.问题出来了,如果构造函数是虚的,就需要通过 vtable来调用,可是对象还没有实例化,也就是内存空间还没 ...
- java面试及答案
优秀总结博客 mybatis总结 java并发包相关 一.Java基础 1.String类为什么是final的. 2.HashMap的源码,实现原理,底层结构. hashmap3.反射中,Class. ...
- HDU2460-Network
题目 给一个\(n\)个点\(m\)条边的无向连通图,\(Q\)次往图中加边,每次加边后问图中的桥有多少个.(加边后边留着). \(n\le 10^5,m\le 2\times 10^5,Q\le 1 ...
- 【uoj#180】[UR #12]实验室外的攻防战 结论题+树状数组
题目描述 给出两个长度为 $n$ 的排列 $A$ 和 $B$ ,如果 $A_i>A_{i+1}$ 则可以交换 $A_i$ 和 $A_{i+1}$ .问是否能将 $A$ 交换成 $B$ . 输入 ...
- DNA Sequence POJ - 2778 (ac自动机 + 快速幂)
题意: 给出患病的DNA序列,问序列长度为n的,且不包含患病的DNA序列有多少种 解析: 以给出的患病DNA序列建trie树 患病结点要用flag标记 对于长度为n的序列 位置i有四种 情况A C ...
- CodeForces - 955B(用char会超时。。。)
#include <bits/stdc++.h> #define mem(a, b) memset(a, b, sizeof(a)) using namespace std; , INF ...
- 【刷题】BZOJ 4650 [Noi2016]优秀的拆分
Description 如果一个字符串可以被拆分为 AABBAABB 的形式,其中 AA 和 BB 是任意非空字符串,则我们称该字符串的这种拆分是优秀的.例如,对于字符串 aabaabaa,如果令 A ...
- [CF1111E]Tree
题目大意:给一棵$n(n\leqslant10^5)$个点的树,有$q(q\leqslant10^5)$次询问,每次询问给出$k,m,r$表示把以下$k$个点分成不超过$m$组,使得在以$r$为根的情 ...
- 【BZOJ4654】【NOI2016】国王饮水记(动态规划,斜率优化)
[BZOJ4654][NOI2016]国王饮水记(动态规划,斜率优化) 题面 BZOJ 洛谷 题解 首先肯定是找性质. 明确一点,比\(h_1\)小的没有任何意义. 所以我们按照\(h\)排序,那么\ ...