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 ...
随机推荐
- 02.VUE学习二之数据绑定
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- Disharmony Trees HDU - 3015
Disharmony Trees HDU - 3015 One day Sophia finds a very big square. There are n trees in the square. ...
- 二分答案:Poweroj2461-入门基础之二分答案(二分法的应用)
传送门:点击打开链接 入门基础之二分答案 Time Limit: 1000 MS Memory Limit: 65536 KBTotal Submit: 179 Accepted: 33 Page V ...
- 笔记-python-反射
笔记-python-反射 1. 反射 在很多地方看到自省和反射,很晕菜,整理了一下相关文档,加深了理解. 自省和反射其实说的是一件事,核心操作是根据输入去对象(模块)中调用(查找/获取/删除/添加)成 ...
- hive操作语句
设置属性: //设置本地执行作set hive.exec.mode.local.auto=true; //设置动态分区 set hive.exec.dynamic.partition=true; se ...
- SSRS 制作报表时报错: 超时时间已到。在操作完成之前超时时间已过或服务器未响应。
转载注明出处,原文地址:http://www.cnblogs.com/zzry/p/5718739.html 在用ssrs 制作报表时报如下错误 错误信息截图: 看到如上错误第一个想到的解决方法就是 ...
- 倍增 - 强制在线的LCA
LCA 描述 给一棵有根树,以及一些询问,每次询问树上的 2 个节点 A.B,求它们的最近公共祖先. !强制在线! 输入 第一行一个整数 N. 接下来 N 个数,第 i 个数 F i 表示 i 的父亲 ...
- ogre3D学习基础18 -- 材质的使用与脚本的简单书写
这一节以基础16为基础,练习材质的使用. 第一,看看框架 //material #include "ExampleApplication.h" class TutorialAppl ...
- SEO搜索引擎优化基础
要如何提高自己网站的知名度,那必须了解一些SEO知识. 1.什么是搜索引擎 所谓的搜索引擎(Search Engines)是一些能够主动搜索信息(搜索网页上的单词和简短的特定的内容描述)并将其自动索 ...
- Python基础-week02 Python的常用数据类型
一.模块初识 import导入Py自带模块例如os,sys等及其自己编写的Py文件,导入到其他文件中,默认查找当前目录.如果不在同一目录,会报错,将该自定义py文件模块放到site-packages目 ...