Codeforces 1288A - Deadline

题目大意:

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

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

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

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

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

 

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

 

解题思路:

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

可得到

 

那么总天数为

 

当且仅当

 

时成立。

所以

 

又因为x必为整数

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

#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int T,n,d,x,i,j,k;
    cin>>T;
    while(T--){
        cin>>n>>d;
        x=sqrt(d-0.75)-0.5;
        if(x+(d+x)/(x+1)<=n||x+1+(d+x+1)/(x+2)<=n)
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
    
    return 0;
}

 

posted @ 2020-01-21 11:49  StelaYuri  阅读(224)  评论(3编辑  收藏  举报