A. Marketing Scheme(思维)Educational Codeforces Round 97 (Rated for Div. 2)

原题链接: https://codeforces.com/contest/1437/problem/A

在这里插入图片描述
测试样例

input
3
3 4
1 2
120 150
output
YES
NO
YES

Note

In the first test case, you can take, for example, a=5 as the size of the pack. Then if a customer wants to buy 3 cans, he’ll buy 5 instead (3mod5=3, 52=2.5). The one who wants 4 cans will also buy 5 cans.

In the second test case, there is no way to choose a.

In the third test case, you can take, for example, a=80.

题意: 有顾客想要购买数量为 x x x的猫粮, x x x属于区间 [ l , r ] [l,r] [l,r],而你会制定一个折扣,相当于购买 a a a个就会享受折扣,其余的 x   m o d   a x\ mod \ a x mod a则按原价购买。现在顾客有这样一个倾向:如果 x m o d      a ≥ a / 2 x\mod \ a≥a/2 xmod aa/2,那么顾客会购买多购买使得满折扣,你当然希望顾客多购买,故请你能否找到一个折扣 a a a,使得顾客总想这样做。

解题思路: 请认真理解题意,再继续阅读思路。好,我们来看,首先探讨条件: x m o d      a ≥ a / 2 x\mod \ a≥a/2 xmod aa/2,我们发现要想是这个等式成立,就要使左边大右边小,而左边大的实现方法就是让 a > x a>x a>x,这样取余永远为 x x x,而右边小的实现方法就是要让 a a a尽量小。 则我们可以发现 x x x最大为 r r r,我们就可以定 a a a r + 1 r+1 r+1,那么即可进行判断了。怎么判断呢?还有 x x x的值没有确定,我们试想,如果 x x x的最小值都满足,那么是不是这个 a a a就行,否则即是不可行的。则我们可以进行判断了。要注意的一点就是由于是四舍五入,故我们进行 a / 2 a/2 a/2时应该向上取整,我们也可以直接 ( a + 1 ) / 2 (a+1)/2 (a+1)/2即可。

AC代码

/*
*邮箱:[email protected]
*blog:https://me.csdn.net/hzf0701
*注:文章若有任何问题请私信我或评论区留言,谢谢支持。
*
*/
#include<bits/stdc++.h>	//POJ不支持

#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair

using namespace std;

const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll>  pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//

int t;
int l,r;
int main(){
    
    
	//freopen("in.txt", "r", stdin);//提交的时候要注释掉
	IOS;
	while(cin>>t){
    
    
		while(t--){
    
    
			cin>>l>>r;
			int temp=r+1;
			if(l%temp>=(temp+1)/2){
    
    
				cout<<"YES"<<endl;
			}
			else{
    
    
				cout<<"NO"<<endl;
			}
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/hzf0701/article/details/109324286