A. The Miracle and the Sleeper(水题)
题目如下:
You are given two integers l and r, l≤r. Find the largest possible value of amodb over all pairs (a,b) of integers for which r≥a≥b≥l
As a reminder, amodb
is a remainder we get when dividing a by b. For example, 26mod8=2
Input
Each test contains multiple test cases.
The first line contains one positive integer t
(1≤t≤104)
, denoting the number of test cases. Description of the test cases follows.
The only line of each test case contains two integers l
, r (1≤l≤r≤109).
Output
For every test case, output the largest possible value of amodb
over all pairs (a,b) of integers for which r≥a≥b≥l.
Example
Input
4 1 1 999999999 1000000000 8 26 1 999999999
Output
0 1 12 499999999
Note
In the first test case, the only allowed pair is (a,b)=(1,1)
, for which amodb=1mod1=0.
In the second test case, the optimal choice is pair (a,b)=(1000000000,999999999)
, for which amodb=1.
AC代码如下:
#include<stdio.h>
int main()
{int t;scanf("%d", &t);int x, y;while (t--){scanf("%d %d", &x, &y);if (y / 2 + 1 >= x){printf("%d\n", y %(y/2+1));}elseprintf("%d\n", y % x);}return 0;
}
对于a%b,如果要获取最大的值
理想上:
1.a越大越好
2.b = a/2+1
但也有可能存在a/2+1找不到的情况(代码上:y / 2 + 1 < x [对应else]),那就直接进行mod——》
y%x。此时的x——》就是最理想的(因为你无法取到y/2+1,x就是该输入中最理想的)!
ps:开学的第4天,已经开始正常上课了。课程跟紧,代码不停!ACM努力中!!!
A. The Miracle and the Sleeper(水题)相关推荐
- 水题/poj 1852 Ants
1 /* 2 PROBLEM:poj1852 3 AUTHER:Nicole 4 MEMO:水题 5 */ 6 #include<cstdio> 7 using namespace std ...
- HDU2673-shǎ崽(水题)
如果不能够直接秒杀的题,就不算水题.又应证了那句话,有时候,如果在水题上卡住,那么此题对于你来说,也就不算是水题了额~~ 刚睡醒,迷迷糊糊. 题目的意思很简单,求一个最大的,再求一个最小的.几乎是什么 ...
- 图论刷水题记录(二)(最短路-----SPFA算法)
继第一篇的后续,又来刷水题了,写的是SPFA算法,这个算法的复杂度比较玄学,感觉能不用就不用了,但是他的好处就是可以判断负圈. 3月26日: 1.POJ 1847 Tram 题意:在一个交通网络上有N ...
- 图论刷水题记录(一)(最短路-----dijkstra算法)
最近实在不知道干些什么,感觉自己除了水题什么都不会做,算了去刷一刷图论的水题吧本来想合起来一起发,想了想太长的话以后看起来也不方便,题目所以今天晚上就先发了dij部分,由上到下由易变难. 1.POJ ...
- hdu 2041:超级楼梯(水题,递归)
超级楼梯Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...
- HDU2568 前进【水题】
前进 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...
- CF Round #426 (Div. 2) The Useless Toy 思维 水题
题目链接: http://codeforces.com/contest/834/problem/A 题目描述: 输入起始状态和结束状态和数列长度, 判断旋转方向是顺时针逆时针还是不合理 解题思路: 长 ...
- NUC1312 Sum【水题+数学题】
Sum 时间限制: 1000ms 内存限制: 65536KB 通过次数: 1总提交次数: 1 问题描述 认为自然数是从1-N.将每个数和+或-联系起来,然后计算这个表达式的值我们得到一个和S.这个问题 ...
- Codeforces 864 A Fair Game 水题
题目链接: http://codeforces.com/problemset/problem/864/A 题目描述: 看不是是不是一串数中只有两种数且这两种数字的数量是相同的 解题思路: 水题, 水过 ...
- poj1564 Sum It Up dfs水题
题目描述: Description Given a specified total t and a list of n integers, find all distinct sums using n ...
最新文章
- 某程序员吐槽:回老家被乡镇公务员表哥怼,催他赶紧上岸!表哥月薪3800,而他年包90w!...
- 我去,为什么最左前缀原则失效了?
- Leetcode_最后一个单词的长度
- 翻译SSD论文(Single Shot MultiBox Detector)
- python as_Python with as的用法
- redis启动.停止.重启
- 香港中文大学(深圳)吴保元教授课题组博士后招聘
- OAuth2.0_授权服务配置_密码模式及其他模式_Spring Security OAuth2.0认证授权---springcloud工作笔记145
- 更快,可扩展性更强的 Apache Cassandra 4.0 正式发布
- Tensorflow Python3 做神经网络(视频教程)
- PAIP.提升效率----论项目知识库的建设。。
- html 屏幕录像,Screencastify:屏幕录像
- bitlocker正在加密 c盘_win10不能分盘,硬盘提示Bitlocker已加密解决方法
- 去雾算法学习-----Automatic recovery of the atmospheric light hazy image(fattal 大气光值自适应去雾算法)阅读笔记
- ERNIE(二妮儿)模型初探
- 股票实时行情接口编程难度大吗?
- eslint : 无法加载文件 C:\Users\user\AppData\Roaming\npm\eslint.ps1
- 通过Fiddler进行抓包并分析
- 【CTF-misc】真是阳间题!
- APNS证书制作问题
热门文章
- C语言,向函数传递一维数组,计算最高分,平均分,人数(要求输入负值时输入结束,且不能超过40人)
- 【Day07】v-model 是如何实现的,语法糖实际是什么?
- 安装EXSI遇到No Network Adapters的解决方案
- 添加谷歌翻译到你的网站
- 异步生成器_异步生成器作为状态管理的替代方法
- 所代币代币_代币网络效应
- aws docker_如何使用Docker的功能来摆脱AWS Lambda函数的困境
- javascript控制台_如何使您JavaScript控制台静音
- html5支持多中浏览器写法,html5及css3对table表格高亮当前行列的多浏览器兼容写法...
- 通过Applescript打开终端运行py文件