K. Yet Another Problem About Pi
题意:
求长度为 π \pi π 的路线最多经过几个区域
分析:
可以走短的直边(贡献值为2)或斜边(对角线,贡献值为3)
-
最初先判断主要走什么边
-
走直边:最后要判断去掉一条直边是否足够一条斜边
-
走斜边:最后要判断剩余的是否足够一条直边,再判断去掉一条斜边是否足够两条直边
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=acos(-1);
int main()
{
int t;
cin>>t;
while(t--)
{
double x,y;
cin>>x>>y;
double cro=sqrt(x*x+y*y);
if(x>y) x=y;
if(x>pi) { cout<<"4"<<endl; continue; }
ll ans=4,xt=0,ct=0;
double xn=x/2, crn=cro/3; // 对比一下性价比
if(xn<crn)
{
xt = ll(pi/x);
ans += xt*2;
if(pi-(xt-1)*x > cro) ans++;
}
else
{
ct = ll(pi/cro);
ans += ct*3;
if(pi-ct*cro > x) ans+=2;
else if(pi-(ct-1)*cro > 2*x) ans++;
}
cout<<ans<<endl;
}
return 0;
}