Yet Another Problem About Pi
链接: link.
题目:
题意:
路线的最大总长度为
π
π
π公里,找出在整个公路旅行中最多能参观多少个不同的地区。
题解:
可知最开始的起点一定会涉及最少四个区域(以极小极小的距离移动),而后直线行进时一格涉及两个区域(选择短的一边移动),对角线行进时一次涉及三个区域(斜线中以对角线效率最高)。由此可以得到走直线和走对角线的效率,根据效率选择走直线或是对角,此时应当注意,只有在起始或结尾(中间改变无法加大最优解)的状态转换可能能使涉及区域增加(有足够距离燃油时)。
#include<bits/stdc++.h>
using namespace std;
const double p=acos(-1);
int main()
{
int t;
cin>>t;
while(t--)
{
double w,d;
cin>>w>>d;
double x=min(w,d),y=sqrt(w*w+d*d);
//cout<<x<<' '<<y<<endl;
int ans1=4,ans2=4;
int yy=p/y,xx=p/x;
double a=x/2,b=y/3;
//cout<<yy<<" "<<xx<<endl;
if(a<b)
{
ans1+=xx*2;
if(p-(xx-1)*x>y&&xx>=1)ans1++;
}
else
{
ans2+=yy*3;
if(p-yy*y>x)ans2+=2;
else if(p-(yy-1)*y>2*x&&yy>=1)ans2++;
}
int ans=max(ans1,ans2);
cout<<ans<<endl;
}
}