Educational Codeforces Round 80. A - Deadline

题面:https://codeforces.com/contest/1288/problem/A

题目大意:

Adilbek有一个特殊项目,他需要运行这个项目得到结果。

但是这个项目直接运行需要消耗d天时间。

他也可以选择优化程序以减少程序运行消耗时间。

假设他用了x天优化程序,那么最后运行程序只需要消耗天的时间(括号指向上取整)。

那么总共需要消耗的天数是

问,他能不能在n天内得到结果?

解题思路:

问能不能在n天内得到结果,只需要求出最少需要的天数与n对比即可。

可得到

那么总天数为

当且仅当

时成立。

所以

又因为x必为整数

所以x取上式向下取整后代入公式,再去向下取整+1代入公式,得出的两个结果取小作为答案。

 1 /*
 2 Written By. StelaYuri
 3 On 2020/01/14
 4 */
 5 #include<bits/stdc++.h>
 6 using namespace std;
 7 int main(){
 8     ios::sync_with_stdio(0);
 9     cin.tie(0);cout.tie(0);
10     int T,n,d,x,i,j,k;
11     cin>>T;
12     while(T--){
13         cin>>n>>d;
14         x=sqrt(d-3.0/4)-1.0/2;
15         if(x+(d+x)/(x+1)<=n||x+1+(d+x+1)/(x+2)<=n)
16             cout<<"YES\n";
17         else
18             cout<<"NO\n";
19     }
20     
21     return 0;
22 }

猜你喜欢

转载自www.cnblogs.com/stelayuri/p/12221044.html
今日推荐