题目链接: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

Problem Description
  
Hanamichi is taking part in a programming contest, and he is assigned to solve a special problem as follow: Given a range [l, r] (including l and r), find out how many numbers in this range have the property: the sum of its odd digits is smaller than the sum of its even digits and the difference is 3.

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.

Input
  
You are given a integer T (1 ≤ T ≤ 100), which tells how many single tests the final test data has. And for the following T lines, each line contains two integers l and r, which are the original test data. (1 ≤ l ≤ r ≤ 1018)
Output
  
You are only allowed to change the value of r to a integer R which is not greater than the original r (and R ≥ l should be satisfied) and make Hanamichi’s solution fails this test data. If you can do that, output a single number each line, which is the smallest R you find. If not, just output -1 instead.
Sample Input
  
3 3 4 2 50 7 83
Sample Output
  
-1 -1 80
  
Source
BestCoder Round #5

题意:

首先给出一个范围 [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(数学题)相关推荐

  1. hdu 4956 Poor Hanamichi(暴力)

    题目链接:hdu 4956 Poor Hanamichi 题目大意:Hanamichi要解决一个问题,即对给定区间l,r,求有多少个数的奇数位和比偶数位和大3,然后Hanamichi推出一个公式(r ...

  2. HDU 5228 ZCC loves straight flush( BestCoder Round #41)

    题目链接:ZCC loves straight flush 题面: ZCC loves straight flush Time Limit: 2000/1000 MS (Java/Others)    ...

  3. HDU 5804 BestCoder Round #86 Price List (水题)

    Price List 题目链接: 点我打开链接 Source BestCoder Round #86  题意:有一个人去 n 间商店购物,在每家商店购买最多一件物品,也可以什么都不买.给你每家商店的物 ...

  4. 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 ...

  5. hdu4585 amp; BestCoder Round #1 项目管理(vector应用)

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 项目管理 Time Limit: 2000/1000 MS (Java/Others)    M ...

  6. 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 ...

  7. 矩阵快速幂---BestCoder Round#8 1002

    当要求递推数列的第n项且n很大时,怎么快速求得第n项呢? 可以用矩阵快速幂来加速计算. 我们可以用矩阵来表示数列递推公式 比如fibonacci数列 可以表示为 [f(n)   f(n-1)] = [ ...

  8. 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II

    题目传送门 1 /* 2 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 3 当然有可能两个数和超过p,那么an ...

  9. 贪心 BestCoder Round #39 1001 Delete

    题目传送门 1 /* 2 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 3 否则再在tot里减去多余的即为答案 4 用set容器也可以做,思 ...

最新文章

  1. 干货|TensorFlow开发环境搭建(Ubuntu16.04+GPU+TensorFlow源码编译)
  2. 互联网人不敢生孩子:加班多、想跳槽、怕被边缘化
  3. Debug Tensorflow: Expected these arguments to match one of the following 4 option(s):
  4. VTK:Utilities之DiscretizableColorTransferFunction
  5. 第二章:系统困境之 试图通过线性努力获得线性增长
  6. 跟我一起数据挖掘(10)——HP Vertica
  7. java android上传文件_Java-Android-如何将txt文件上传到网站?
  8. Wythoff's game
  9. mysql 大文件导入工具_BigDump:导入超大mysql数据库文件工具
  10. 张宇1000题高等数学 第十八章 多元函数积分学(一)
  11. 单片机C语言字符串转数字
  12. keil中断函数的写法_keil中怎样定义外部中断函数原型?
  13. 黑科技知识:需要登录才能访问的网站如何破解?仅仅只需 3 步!
  14. 记录mysql中如何统计日周月季度年
  15. Python基础学习笔记【廖雪峰】
  16. 清北毕业生5年来去向大数据:北大偏爱银行,清华更倾向国网,华为堪称最大黑洞-1
  17. Ruby 文件目录操作(实例讲解更易懂)
  18. 五句话介绍计算机英语,日常必备的英语口语句子3篇
  19. iconv php gbk utf8,PHP通过iconv将字符串从GBK转换为UTF8字符集
  20. stl string 源代码分析

热门文章

  1. k8s部署有状态(StatefulSet)zk-kafka集群
  2. 支付宝要融资上市,马云大赚,不过他承诺捐了
  3. 凸优化笔记10(罚函数法-内点罚函数、外点罚函数)
  4. iphone文件访问Windows共享文件夹
  5. 阿里云Redis之:配置程序接入阿里云Redis集群缓存数据(十七)
  6. Microphone回音问题分析
  7. axios拦截器 config_axios拦截器的实现
  8. 恒生电子探路金融大模型
  9. c语言编程10000次模拟抛硬币,用c语言模拟抛硬币的过程
  10. Licode入门学习:MediaStream源码分析(三)