hdu 4956(思路题)
Poor Hanamichi
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 893 Accepted Submission(s): 407
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.
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)
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.
3 4
2 50
7 83
-1
80
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
using namespace std;
typedef long long LL; bool judge(LL x){
LL bit[];
int t = ;
while(x){
bit[t++] = x%;
x/=;
}
LL odd=,even=;
for(int i=;i<t;i+=){
odd+=bit[i];
}
for(int i=;i<t;i+=){
even+=bit[i];
}
if(odd-even==) return true;
return false;
}
int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--){
LL l,r;
scanf("%lld%lld",&l,&r);
LL ans = -,x=;
for(LL i=l;i<=r;i++){
LL temp = (i+)/- (l-+)/;
if(judge(i)){
x++;
}
if(x!=temp){
ans = i;
break;
}
}
printf("%lld\n",ans);
}
}
hdu 4956(思路题)的更多相关文章
- hdu 4908(思路题)
BestCoder Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- Proud Merchants HDU - 3466 (思路题--有排序的01背包)
Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerfu ...
- hdu 5191(思路题)
Building Blocks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- hdu 5101(思路题)
Select Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- hdu 5063(思路题-反向操作数组)
Operation the Sequence Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- hdu 4859(思路题)
Goffi and Squary Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- hdu 5400(思路题)
Arithmetic Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- HDU 1173 思路题
题目大意 有n个地点(坐标为实数)需要挖矿,让选择一个地点,使得在这个地方建造基地,到n个地点的距离和最短,输出基地的坐标. 题解+代码: 1 /* 2 把这个二维分开看(即把所有点投影到x轴上,再把 ...
- 51nod P1305 Pairwise Sum and Divide ——思路题
久しぶり! 发现的一道有意思的题,想了半天都没有找到规律,结果竟然是思路题..(在大佬题解的帮助下) 原题戳>>https://www.51nod.com/onlineJudge/ques ...
随机推荐
- ubuntu下vim的简单配置
该文章只是进行符合自己习惯的最基本的配置,更加高级的配置请参考更加有含量的博文! 1.打开vim下的配置文件 sudo vim /etc/vim/vimrc 2.在这个文件中,会有这么一句:synta ...
- 如何使用pyinstaller打包32位的exe
说明:原来安装的python为64位,故安装的pyinstaller和打包后的exe都为64位.而64位的exe文件在32位的win7操作系统下是无法执行的,显示不兼容.网上查询发现,简单(可能不方便 ...
- String使用方法详解
标准c++中string类函数介绍 注意不是CString 之所以抛弃char*的字符串而选用C++标准程序库中的string类,是因为他和前者比较起来,不必 担心内存是否足够.字符串长度等等,而且作 ...
- linux命令行操作基本知识
乱七八糟的命令 . 表示当前目录 .. 表示上一级目录 ls 显示文件 -l 列表 -a 隐藏文件 -h 文件大小人性化显示 gedit 自带文本编辑器 subl 打开sublime > 重定向 ...
- 4819: [Sdoi2017]新生舞会(分数规划)
4819: [Sdoi2017]新生舞会 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1031 Solved: 530[Submit][Statu ...
- LuffyCity-MySQL综合练习50实例
1.请创建如下表,并添加相应约束: 2.自行构造测试数据: 新建数据库 创建表 构造测试数据 #Step1-创建数据库LuffyCity_MySQL; #CREATE DATABASE LuffyCi ...
- PHP 删除 url 中的 query string
function removeQueryStringFromUrl($url) { if (substr($url,0,4) =="http") { $urlPartsArray ...
- 计算两个日期之间的天数差C++/java
1--Java 分析:调用java中Calendar类 int days(Date date1,Date date2){ Calendar cal = new Calendar.getInstance ...
- 【转】BehaviorDesigner学习
BehaviorDesigner学习 行为树: 行为树设计师插件是一个专门为unity设计的AI插件. 通过继承Behavior中的Task下的四个节点,可以创建自己的行为树节点. 行为树中的自定 ...
- Jquery鼠标悬停按钮图标动态变化效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...