Poor Hanamichi

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0

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
 
解题:暴力乱搞居然A了,看看待会会被hack么。。。
   马丹 被hack了。。。
 #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",&lt,&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的更多相关文章

  1. [BestCoder Round #5] hdu 4956 Poor Hanamichi (数学题)

    Poor Hanamichi Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

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

  3. ACM学习历程—HDU4956 Poor Hanamichi(模拟)

    Poor Hanamichi Problem Description Hanamichi is taking part in a programming contest, and he is assi ...

  4. BestCoder5 1001 Poor Hanamichi(hdu 4956) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4956(它放在题库后面的格式有一点点问题啦,所以就把它粘下来,方便读者观看) 题目意思:给出一个范围 [ ...

  5. 【HDOJ】4956 Poor Hanamichi

    基本数学题一道,看错位数,当成大数减做了,而且还把方向看反了.所求为最接近l的值. #include <cstdio> int f(__int64 x) { int i, sum; i = ...

  6. hdu4956 Poor Hanamichi

    解决暴力的直接方法.一个直接的推论x%11方法. 打表可以发现,以解决不同的情况都不会在很大程度上会出现. 所以从l暴力开始枚举.找到的第一个错误值输出要. 如果它超过r同样在美国发现-1. #inc ...

  7. New Training Table

          2014_8_15 CodeForces 261 DIV2 A. Pashmak and Garden 简单题   B. Pashmak and Flowers    简单题   C. P ...

  8. hdu 4956(思路题)

    Poor Hanamichi Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  9. 关于过拟合、局部最小值、以及Poor Generalization的思考

    Poor Generalization 这可能是实际中遇到的最多问题. 比如FC网络为什么效果比CNN差那么多啊,是不是陷入局部最小值啊?是不是过拟合啊?是不是欠拟合啊? 在操场跑步的时候,又从SVM ...

随机推荐

  1. E2017E0605-hm

    carbon copy 抄送, 抄写与送达 blind carbon copy 密送 blind   adj. 失明的; 盲目的,轻率的; contact    n. 接触; 触点 v 联系,接触; ...

  2. bzoj 1575: [Usaco2009 Jan]气象牛Baric【dp】

    完了不会dp了 设f[i][j]为以i结尾,有j个时的最优值,辅助数组g[i][j]为s选了i和j,i~j中的误差值 转移是f[j][i]=min(f[k][i-1]+g[k][j]) #includ ...

  3. 慕课网4-2 编程练习:jQuery祖先后代选择器小案例

    4-2 编程练习 结合所学的祖先后代选择器,实现如下图所示效果 任务 (1)使用祖先后代选择器将第二段文字背景色变成红色 (2)使用jQuery的.css()方法设置样式,语法css('属性 '属性值 ...

  4. Nginx(三) 常用配置整理

    #定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于CPU总核心数. worker_processes 8; #全局错误日志定义类型,[ debug | ...

  5. mac更改本地mysql登陆密码

    安装完mysql 之后,登陆以后,运行任何命令,提示 You must SET PASSWORD before executing this statement解决办法. step 1: SET PA ...

  6. MyEclipse无法自动编译项目故障一例

    MyEclipse导入项目后发现无法自动编译,classes目录下没有编译的类. 尝试的解决方法: 1.刷新项目,失败: 2.project->clean-,失败: 3.关闭项目再次打开,失败: ...

  7. Objective-C设计模式——桥接Bridge(接口适配)

    桥接模式 桥接模式就是让抽象和实现分离的最好体现,符合面向对象的依赖倒转原则.Abstruct抽象类负责设计客户端接口,Implementor则负责具体的细节逻辑. 在桥接模式中,Abstruct类持 ...

  8. 高效程序员的45个习惯·敏捷开发修炼之道(Practices of an Agile Developer)读书笔记

    首先,这本书值得再看一遍——这次的阅读,有很多东西都是知其“形”,不知其“神”的,这导致了我对其中某些建议持怀疑态度,接受了的建议也有待商榷. 总之,先记录本书的一些信息: Practices of ...

  9. 富士康的盈利秒杀99%的A股公司:3星|《三联生活周刊》2018年10期

    三联生活周刊·最美的数学:天才为何成群到来(2018年10期) 本期专题是数学和成都,我都跳过去没看.其他内容也还有点意思. 总体评价3星. 以下是本期一些内容的摘抄,#号后面是kindle电子版中的 ...

  10. VS2015 安装包缺失(联网安装失败)问题解决

    Win7 x86 测试可行 *  如果前面有尝试过安装不成功, 一定要用卸载程序删除已安装的部分,否则会出乱子. 1. 或者是用虚拟光驱加载ISO, 或者是解压到硬盘上, 都没有关系. 2. 用管理员 ...