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 ;
}

最新文章

  1. call_user_func()的参数不能为引用传递 自定义替代方法
  2. 第3章 Linux常用命令(6)_关机重启命令
  3. java中使用队列:java.util.Queue (转)
  4. raspberry pi 如何汉化显示中文
  5. XBox360-双光盘游戏自制GOD
  6. 为网站加入Drupal星球制作RSS订阅源
  7. 实战开发中UI资源制作标准
  8. 从 mian 函数开始一步一步分析 nginx 执行流程(三)
  9. CTime,Systemtime的比较还有转换成日期格式。
  10. shell中的declare命令
  11. sql从某不连续的数字中将其分段并找出缺失的数字并分段
  12. 设计模式16:迭代模式(Iterator)
  13. Chrome浏览器扩展开发系列之十八:扩展的软件国际化chrome.i18n API
  14. Work 3(工作类) (2017.07.01)
  15. 计蒜客NOIP模拟赛(2) D2T1 劫富济贫
  16. Spring Cloud Alibaba基础教程:使用Sentinel实现接口限流
  17. JDK的动态代理-----为接口进行代理
  18. 论文阅读笔记三十六:Mask R-CNN(CVPR2017)
  19. 杨其菊201771010134《面向对象程序设计(java)》第六周学习总结
  20. gulp入门实践

热门文章

  1. P2746 [USACO5.3]校园网Network of Schools(Tarjan)
  2. python自动化测试学习笔记-9测试框架
  3. 2017杭电多校第六场1011Classes
  4. 使用mysqldump导出数据库(表)
  5. EasyUI系列学习(十)-Tabs(选项卡)
  6. Unity笔记(2)自学第一天
  7. Python批量生成用户名
  8. PHP开发心得四
  9. SpringBoot+Mybatis 自动创建数据表(适用mysql)
  10. chr()返回值是当前整数对应的 ASCII 字符。