AtCoder Regular Contest 094 D - Worst Case(数学思维)

匿名 (未验证) 提交于 2019-12-03 00:18:01

D - Worst Case


Time limitMemory limit

700

Problem Statement

101010101010-th.

score

Q

  • iAiBiAiBi-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.

Constraints

  • 1Q100
  • 1Ai,Bi109(1iQ)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

Q A1 B1 : AQ BQ 

Output

For each query, print the maximum possible number of participants whose scores are smaller than Takahashi's.


Sample Input 1

Copy
8 1 4 10 5 3 3 4 11 8 9 22 40 8 36 314159265 358979323 

Sample Output 1

Copy
1 12 4 11 14 57 31 671644785 

xy(x,y).

(2,1)1.


BUG反馈门


3 3


2 4
4 2
5 1
1 5

意思就是说 左右列不能存在重复

分析:

由于需要得到最大的组数且不存在重复的情况 因此:



该题也可作为结论来记住

#include<bits/stdc++.h> using namespace std; #define ll long long int main (){     ios_base::sync_with_stdio(false);     int t;cin>>t;     while(t--){         ll a,b,ans=0;cin>>a>>b;         if(a==b) ans=2*a-2;         else {             ll tmp=sqrt(a*b);             if(tmp*tmp==a*b) tmp--;             if(tmp*(tmp+1)>=a*b) ans=2*tmp-2;             else ans=2*tmp-1;         }         cout<<ans<<endl;     }     return 0; } 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!