hdu 4956 Poor Hanamichi BestCoder Round #5(数学题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4956
Poor Hanamichi
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7 Accepted Submission(s): 4
A integer X can be represented in decimal as:
X=An×10n+An−1×10n−1+…+A2×102+A1×101+A0
The odd dights are A1,A3,A5… and A0,A2,A4… are even digits.
Hanamichi comes up with a solution, He notices that:
102k+1 mod 11 = -1 (or 10), 102k mod 11 = 1,
So X mod 11
= (An×10n+An−1×10n−1+…+A2×102+A1×101+A0)mod11
= An×(−1)n+An−1×(−1)n−1+…+A2−A1+A0
= sum_of_even_digits – sum_of_odd_digits
So he claimed that the answer is the number of numbers X in the range which satisfy the function: X mod 11 = 3. He calculate the answer in this way :
Answer = (r + 8) / 11 – (l – 1 + 8) / 11.
Rukaw heard of Hanamichi’s solution from you and he proved there is something wrong with Hanamichi’s solution. So he decided to change the test data so that Hanamichi’s solution can not pass any single test. And he asks you to do that for him.
题意:
首先给出一个范围 [l, r],问能否从中找到一个数证明 Hanamichi’s solution 的解法(对于某个数 X,偶数位的数字之和 - 奇数位的数字之和 = 3 而且 这个 X 满足 X mod 11 = 3 )是错的。也就是在范围里寻找是否存在不能同时满足:①偶数位的数字之和 - 奇数位的数字之和 = 3; ②X mod 11 = 3;
代码如下:
#include <cstdio>
typedef __int64 LL;bool Judge(LL tt)
{LL sumo = 0, sume = 0;LL i = -1;while(tt){i++;LL t = tt%10;if(i%2)sumo += t;elsesume += t;tt /= 10;}if(sume - sumo == 3)return true;return false;
}
int main()
{int T;LL l, r;LL i, j;scanf("%d",&T);while(T--){scanf("%I64d%I64d",&l,&r);for(i = l; ; i++){if(i%11 == 3)break;}for(j = i; j <= r; j+=11){if(!Judge(j))break;}if(j > r)printf("-1\n");elseprintf("%I64d\n",j);}return 0;
}
hdu 4956 Poor Hanamichi BestCoder Round #5(数学题)相关推荐
- hdu 4956 Poor Hanamichi(暴力)
题目链接:hdu 4956 Poor Hanamichi 题目大意:Hanamichi要解决一个问题,即对给定区间l,r,求有多少个数的奇数位和比偶数位和大3,然后Hanamichi推出一个公式(r ...
- HDU 5228 ZCC loves straight flush( BestCoder Round #41)
题目链接:ZCC loves straight flush 题面: ZCC loves straight flush Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 5804 BestCoder Round #86 Price List (水题)
Price List 题目链接: 点我打开链接 Source BestCoder Round #86 题意:有一个人去 n 间商店购物,在每家商店购买最多一件物品,也可以什么都不买.给你每家商店的物 ...
- HDU 5597 GTW likes function(规律+欧拉函数模板题)——BestCoder Round #66(div.1 div.2)
GTW likes function Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Oth ...
- hdu4585 amp; BestCoder Round #1 项目管理(vector应用)
主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 项目管理 Time Limit: 2000/1000 MS (Java/Others) M ...
- hdu4932 Miaomiao#39;s Geometry (BestCoder Round #4 枚举)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4932 Miaomiao's Geometry Time Limit: 2000/1000 MS (Ja ...
- 矩阵快速幂---BestCoder Round#8 1002
当要求递推数列的第n项且n很大时,怎么快速求得第n项呢? 可以用矩阵快速幂来加速计算. 我们可以用矩阵来表示数列递推公式 比如fibonacci数列 可以表示为 [f(n) f(n-1)] = [ ...
- 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II
题目传送门 1 /* 2 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 3 当然有可能两个数和超过p,那么an ...
- 贪心 BestCoder Round #39 1001 Delete
题目传送门 1 /* 2 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 3 否则再在tot里减去多余的即为答案 4 用set容器也可以做,思 ...
最新文章
- 干货|TensorFlow开发环境搭建(Ubuntu16.04+GPU+TensorFlow源码编译)
- 互联网人不敢生孩子:加班多、想跳槽、怕被边缘化
- Debug Tensorflow: Expected these arguments to match one of the following 4 option(s):
- VTK:Utilities之DiscretizableColorTransferFunction
- 第二章:系统困境之 试图通过线性努力获得线性增长
- 跟我一起数据挖掘(10)——HP Vertica
- java android上传文件_Java-Android-如何将txt文件上传到网站?
- Wythoff's game
- mysql 大文件导入工具_BigDump:导入超大mysql数据库文件工具
- 张宇1000题高等数学 第十八章 多元函数积分学(一)
- 单片机C语言字符串转数字
- keil中断函数的写法_keil中怎样定义外部中断函数原型?
- 黑科技知识:需要登录才能访问的网站如何破解?仅仅只需 3 步!
- 记录mysql中如何统计日周月季度年
- Python基础学习笔记【廖雪峰】
- 清北毕业生5年来去向大数据:北大偏爱银行,清华更倾向国网,华为堪称最大黑洞-1
- Ruby 文件目录操作(实例讲解更易懂)
- 五句话介绍计算机英语,日常必备的英语口语句子3篇
- iconv php gbk utf8,PHP通过iconv将字符串从GBK转换为UTF8字符集
- stl string 源代码分析