原题链接: https://codeforces.com/contest/1288/problem/A
测试样例
input
3
1 1
4 5
5 11
output
YES
YES
NO
Note
In the first test case, Adilbek decides not to optimize the program at all, since d≤n.
In the second test case, Adilbek can spend 1 day optimizing the program and it will run ⌈5/2⌉=3 days. In total, he will spend 4 days and will fit in the limit.
In the third test case, it’s impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it’ll still work ⌈11/(2+1)⌉=4 days.
题意: 你有一个程序需要天的时间来等待运行结果,而此时这个程序却需要
天才可以显示结果。不过你可以进行一次修改操作。选择一个非负整数
,来使得:所需天数变为
,(修复时不会运行)问经过这次操作后能否在不超过
天内完成。
解题思路: 我们想要修改想要使得天数变得更少,那么就要充分利用这个修改。我们知道对于向上取整的数,我们可以用ceil函数来实现,也可以通过我们的运算修改为:(分号不知道为什么显示不了。),这样进行运算去掉符号。由于我们想要让这个值变得更小,我们自然会想到要让
,那么我们经过运算就可得到
,求到这个之后我们只需要判断
与
上下两个数的最小值是否可行即可。 OK,具体看代码。
AC代码
/*
*
*/
//POJ不支持
//i为循环变量,a为初始值,n为界限值,递增
//i为循环变量, a为初始值,n为界限值,递减。
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,d,n;
int main(){
//freopen("in.txt", "r", stdin);//提交的时候要注释掉
IOS;
while(cin>>t){
while(t--){
cin>>n>>d;
//截止日期前的天数和运行天数。
if(d<=n){
cout<<"YES"<<endl;
continue;
}
ll x=sqrt(d);
ll minn=inf;
rep(i,1,3){
if(i==1){
minn=min(minn,x+(d+x)/(x+1));
}
else if(i==2){
minn=min(minn,x-1+(d+x-1)/(x));
}
else{
minn=min(minn,1+x+(d+x+1)/(x+2));
}
}
if(minn>n){
cout<<"NO"<<endl;
}
else{
cout<<"YES"<<endl;
}
}
}
return 0;
}