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

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么。。。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 #include <climits>
 7 #include <vector>
 8 #include <queue>
 9 #include <cstdlib>
10 #include <string>
11 #include <set>
12 #include <stack>
13 #define LL long long
14 #define pii pair<int,int>
15 #define INF 0x3f3f3f3f
16 using namespace std;
17 LL lt,rt;
18 LL test(LL x){
19     int d[20],i = 0,j,sum = 0;
20     LL y = x;
21     while(x){d[i++] = x%10; x /= 10;}
22     for(j = 0; j < i; j++){
23         if(j&1)sum -= d[j];
24         else sum += d[j];
25     }
26     if(sum != 3) return y;
27     return -1;
28 }
29 int main() {
30     int t;
31     LL tst;
32     scanf("%d",&t);
33     while(t--){
34         scanf("%I64d %I64d",&lt,&rt);
35         bool flag = false;
36         for(LL i = lt/11+1; i*11+3 <= rt; i++){
37             tst = test(i*11+3);
38             if(tst > 0) {flag = true;break;}
39         }
40         if(flag) printf("%I64d\n",tst);
41         else puts("-1");
42     }
43     return 0;
44 }

Poor Hanamichi,布布扣,bubuko.com

时间: 2024-10-19 03:07:29

Poor Hanamichi的相关文章

【HDOJ】4956 Poor Hanamichi

基本数学题一道,看错位数,当成大数减做了,而且还把方向看反了.所求为最接近l的值. 1 #include <cstdio> 2 3 int f(__int64 x) { 4 int i, sum; 5 6 i = sum = 0; 7 while (x) { 8 if (i & 1) 9 sum -= x%10; 10 else 11 sum += x%10; 12 ++i; 13 x/=10; 14 } 15 return sum; 16 } 17 18 int main() { 1

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 Problem Description Hanamichi is taking part in

HDU 4956 Poor Hanamichi

HDU 4956 Poor Hanamichi 题目链接 思路:直接从l往上找判断即可 代码: #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; typedef long long ll; int t; ll l, r; bool judge(ll num) { ll flag = 1; ll ans = 0; whi

hdu 4956 Poor Hanamichi 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4956(它放在题库后面的格式有一点点问题啦,所以就把它粘下来,方便读者观看) 题目意思:给出一个范围 [l, r] 你, 问是否能从中找到一个数证明 Hanamichi’s solution 的解法是错的. Hanamichi’s solution 是这样的: 对于某个数 X,从右往左数它的每一位数字(假设第一位是从0开始数).它 偶数位的数字之和 -  奇数位的数字之和  = 3  而且 这个 X

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

Poor Hanamichi Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 743    Accepted Submission(s): 275 Problem Description Hanamichi is taking part in a programming contest, and he is assigned to so

hdu4956 Poor Hanamichi

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

&#183;BC」 Round 5

这次就看了第一题,而且还做得够呛. 到最后都不知道正确的做法. 看完题解之后有一种想自杀的感觉 1.HDU 4956 - Poor Hanamichi (..找规律 ) 可以证明,真的不知道怎么证明,别人说是打表 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 int T; 6 7 bool check(__int64 t) 8 { 9 __

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

Poor Generalization 这可能是实际中遇到的最多问题. 比如FC网络为什么效果比CNN差那么多啊,是不是陷入局部最小值啊?是不是过拟合啊?是不是欠拟合啊? 在操场跑步的时候,又从SVM角度思考了一下,我认为Poor Generalization属于过拟合范畴. 与我的论文 [深度神经网络在面部情感分析系统中的应用与改良] 的观点一致. SVM ImageNet 2012上出现了一个经典虐杀场景.见[知乎专栏] 里面有一段这么说道: 当时,大多数的研究小组还都在用传统compute

HDU 4952 Poor Mitsui(贪心)

HDU 4957 Poor Mitsui 题目链接 思路:利用相邻交换法去贪心即可,注意容积为0的情况,这是个坑点 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 45; struct SB { int a, b; } sb[N]; bool cmp(SB x, SB y) { return x.b * y.a < x.