圆内,求离圆心最远的整数点 hiho一下第111周 Farthest Point

 // 圆内,求离圆心最远的整数点 hiho一下第111周 Farthest Point
// 思路:直接暴力绝对T
// 先确定x范围,每个x范围内,离圆心最远的点一定是y轴两端的点。枚举x的范围,再比较y
// O(n) #include <bits/stdc++.h>
using namespace std;
#define LL long long
const double inf = 123456789012345.0;
const LL MOD =100000000LL;
const int N =1e7+;
#define clc(a,b) memset(a,b,sizeof(a))
const double eps = 1e-;
void fre() {freopen("in.txt","r",stdin);}
void freout() {freopen("out.txt","w",stdout);}
inline int read() {int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-; ch=getchar();}while(ch>=''&&ch<='') {x=x*+ch-'';ch=getchar();}return x*f;} double dis(double a,double b,double c,double d){
return (a-c)*(a-c)+(b-d)*(b-d);
}
int main(){
double x,y,r;
double len=-;
int ans_y,ans_x;
scanf("%lf%lf%lf",&x,&y,&r);
for(double i=floor(x+r);i>=ceil(x-r);i--){
double d=(double)sqrt(r*r-(i-x)*(i-x));
double y1=floor(d+y),y2=ceil(y-d);
if(dis(x,y,i,y1)>len){
len=dis(x,y,i,y1);
ans_x=i,ans_y=y1;
}
if(dis(x,y,i,y2)>len){
len=dis(x,y,i,y2);
ans_x=i,ans_y=y2;
}
}
printf("%d %d\n",ans_x,ans_y);
return ;
}
上一篇:调用接口,发送https请求


下一篇:Minutes和TotalMinutes的区别