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

Link to the original question: https://codeforces.com/contest/1437/problem/A

Insert picture description here
Test sample

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.

Question: Some customers want to buy xxcat food for x ,xxx belongs to the interval[l, r] [l,r][l,r ] , and you will make a discount, which is equivalent to buyingaaa will enjoy a discount, the rest ofx mod ax\ mod \ ax m o d a is   purchased at the original price. Now customers have this tendency: ifxmod a ≥ a / 2 x\mod \ a≥a/2xmod aa / 2 , then customers will buy more purchases to make full discounts, of course you want customers to buy more, so please can you find a discountaaa , so that customers always want to do this.

Question- solving ideas: Please understand the meaning of the question carefully before continuing to read the ideas. Well, let’s take a look, first discuss the condition: xmod a ≥ a / 2 x\mod \ a≥a/2xmod aa / 2 , we found that if this equation holds,It is necessary to make the left big and the right small, and the way to achieve the big left is to make a> x a>xa>x , so the remainder is alwaysxxx , and the small implementation method on the right is to makeaaa as small as possible.Then we can find xxx max isrrr , we can setaaa purposer + 1 r + 1r+1 , then the judgment can be made. How to judge? AndxxThe value of x is not determined, let’s imagine, ifxxThe minimum value of x is satisfied, so is thisaaa is fine, otherwise it is not feasible. Then we can judge. One thing to note is that since it is rounding, we performa / 2 a/2a / 2 should be rounded up, we can also directly(a + 1) / 2 (a+1)/2(a+1 ) / 2 is fine.

AC code

/*
*邮箱:[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;
}

Guess you like

Origin blog.csdn.net/hzf0701/article/details/109324286