Poor Hanamichi
Poor Hanamichi
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
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.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
LL lt,rt;
LL test(LL x){
int d[],i = ,j,sum = ;
LL y = x;
while(x){d[i++] = x%; x /= ;}
for(j = ; j < i; j++){
if(j&)sum -= d[j];
else sum += d[j];
}
if(sum != ) return y;
return -;
}
int main() {
int t;
LL tst;
scanf("%d",&t);
while(t--){
scanf("%I64d %I64d",<,&rt);
bool flag = false;
for(LL i = lt/+; i*+ <= rt; i++){
tst = test(i*+);
if(tst > ) {flag = true;break;}
}
if(flag) printf("%I64d\n",tst);
else puts("-1");
}
return ;
}
Poor Hanamichi的更多相关文章
- [BestCoder Round #5] hdu 4956 Poor Hanamichi (数学题)
Poor Hanamichi Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu 4956 Poor Hanamichi BestCoder Round #5(数学题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4956 Poor Hanamichi Time Limit: 2000/1000 MS (Java/Ot ...
- ACM学习历程—HDU4956 Poor Hanamichi(模拟)
Poor Hanamichi Problem Description Hanamichi is taking part in a programming contest, and he is assi ...
- BestCoder5 1001 Poor Hanamichi(hdu 4956) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4956(它放在题库后面的格式有一点点问题啦,所以就把它粘下来,方便读者观看) 题目意思:给出一个范围 [ ...
- 【HDOJ】4956 Poor Hanamichi
基本数学题一道,看错位数,当成大数减做了,而且还把方向看反了.所求为最接近l的值. #include <cstdio> int f(__int64 x) { int i, sum; i = ...
- hdu4956 Poor Hanamichi
解决暴力的直接方法.一个直接的推论x%11方法. 打表可以发现,以解决不同的情况都不会在很大程度上会出现. 所以从l暴力开始枚举.找到的第一个错误值输出要. 如果它超过r同样在美国发现-1. #inc ...
- New Training Table
2014_8_15 CodeForces 261 DIV2 A. Pashmak and Garden 简单题 B. Pashmak and Flowers 简单题 C. P ...
- hdu 4956(思路题)
Poor Hanamichi Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- 关于过拟合、局部最小值、以及Poor Generalization的思考
Poor Generalization 这可能是实际中遇到的最多问题. 比如FC网络为什么效果比CNN差那么多啊,是不是陷入局部最小值啊?是不是过拟合啊?是不是欠拟合啊? 在操场跑步的时候,又从SVM ...
随机推荐
- bzoj1880: [Sdoi2009]Elaxia的路线(spfa,拓扑排序最长路)
1880: [Sdoi2009]Elaxia的路线 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 1944 Solved: 759[Submit][St ...
- [Swift]经典解题思路:联合查找Union Find
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- spring cloud config搭建说明例子(三)-添加actuator
添加心跳 服务端 ConfigServer pom.xml添加actuator包 <dependency> <groupId>org.springframework.cloud ...
- 洛谷 P2142 高精度减法(模板)
题目描述 高精度减法 输入输出格式 输入格式: 两个整数a,b(第二个可能比第一个大) 输出格式: 结果(是负数要输出负号) 输入输出样例 输入样例#1: 2 1 输出样例#1: 1 说明 20%数据 ...
- K Seq HihoCoder - 1046 || BZOJ4504 k个串
这题与超级钢琴类似,然而重复的不重复计算贡献.. 那么先求出数组nxt,nxt[i]表示第i个元素之后的第一个与其相等的元素的下标,不存在则nxt[i]=0 考虑取的区间左端点为1时的情况. 将读入序 ...
- python如何添加浏览器驱动路径
闲来无事,整一整python+selenium,写完代码后运行发现找不到webdriver的路径:之前是仿照java一样直接把webdriver放到浏览器的安装目录下 迫于无奈,只好查一下问题如何处理 ...
- Mysql动态查询
if条件查询 格式: <if test=”条件判断”> 添加到sql的语句 </if> where标签 简化SQL语句中WHERE条件判断 智能处理and和or 如果使用几个i ...
- SpringMvc下的文件上传
首先是springmvc.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=&q ...
- Git命令add和commit的区别
要想弄明白git add和git commit的区别,首先我们需要知道三个概念:工作区(Working Directory).版本库(Repository).暂存区(Stage or index). ...
- vuex的各个细节理解(因人而异)
应用级的状态集中放在store中: 改变状态的方式是提交mutations,这是个同步的事物: 异步逻辑应该封装在action中. const vuex_store = new Vuex.store( ...