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


     1 // 圆内,求离圆心最远的整数点 hiho一下第111周 Farthest Point
     2 // 思路:直接暴力绝对T
     3 // 先确定x范围,每个x范围内,离圆心最远的点一定是y轴两端的点。枚举x的范围,再比较y
     4 // O(n)
     5 
     6 #include <bits/stdc++.h>
     7 using namespace std;
     8 #define LL long long
     9 const double inf = 123456789012345.0;
    10 const LL MOD =100000000LL;
    11 const int N =1e7+10;
    12 #define clc(a,b) memset(a,b,sizeof(a))
    13 const double eps = 1e-7;
    14 void fre() {freopen("in.txt","r",stdin);}
    15 void freout() {freopen("out.txt","w",stdout);}
    16 inline int read() {int x=0,f=1;char ch=getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch=getchar();}while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}return x*f;}
    17 
    18 double dis(double a,double b,double c,double d){
    19     return (a-c)*(a-c)+(b-d)*(b-d);
    20 }
    21 int main(){
    22     double x,y,r;
    23     double len=-1;
    24     int ans_y,ans_x;
    25     scanf("%lf%lf%lf",&x,&y,&r);
    26     for(double i=floor(x+r);i>=ceil(x-r);i--){
    27         double d=(double)sqrt(r*r-(i-x)*(i-x));
    28         double y1=floor(d+y),y2=ceil(y-d);
    29         if(dis(x,y,i,y1)>len){
    30             len=dis(x,y,i,y1);
    31             ans_x=i,ans_y=y1;
    32         }
    33         if(dis(x,y,i,y2)>len){
    34             len=dis(x,y,i,y2);
    35             ans_x=i,ans_y=y2;
    36         }
    37     }
    38     printf("%d %d
    ",ans_x,ans_y);
    39     return 0;
    40 }
  • 相关阅读:
    07_Go语言 ( 切片)
    06_Go语言( 数组)
    05_Go语言( 流程控制)
    04_Go语言( 运算符)
    02_Go语言(变量和常量)
    01_Go语言(环境的搭建)
    云电脑直播简单指南
    统信UOS共享打印机配置
    #插头dp#洛谷 5074 Eat the Trees
    #状压dp#洛谷 3959 [NOIP2017 提高组] 宝藏
  • 原文地址:https://www.cnblogs.com/ITUPC/p/5847610.html
Copyright © 2020-2023  润新知