A、Deadline(构造+数学)Educational Codeforces Round 80 (Rated for Div. 2)
原题链接: 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.
题意: 你有一个程序需要 n n n天的时间来等待运行结果,而此时这个程序却需要 d d d天才可以显示结果。不过你可以进行一次修改操作。选择一个非负整数 x x x,来使得:所需天数变为 ⌈ d x + 1 ⌉ + x \left\lceil \frac{d}{x + 1} \right\rceil+x ⌈x+1d⌉+x,(修复时不会运行)问经过这次操作后能否在不超过 n n n天内完成。
解题思路: 我们想要修改想要使得天数变得更少,那么就要充分利用这个修改。我们知道对于向上取整的数,我们可以用ceil函数来实现,也可以通过我们的运算修改为: d + x x + 1 + x \frac{d+x}{x + 1} +x x+1d+x+x(分号不知道为什么显示不了。),这样进行运算去掉符号。由于我们想要让这个值变得更小,我们自然会想到要让 d + x x + 1 = = x \frac{d+x}{x + 1}==x x+1d+x==x,那么我们经过运算就可得到 x = s q r t ( d ) x=sqrt(d) x=sqrt(d),求到这个之后我们只需要判断 x x x与 x x x上下两个数的最小值是否可行即可。 OK,具体看代码。
AC代码
/*
*邮箱:unique_powerhouse@qq.com
*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,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;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)