题目:给定一个圆,要你求出一个在里面或者在边上的整数点,使得这个点到原点的距离最大,如果有多个相同,输出x最大,再输出y最大。

思路:对于一个圆,里面整点个数的x是能确定的。你找到x的上下界就可以了。就是mix = ceil(x0-r)//因为是小的值,所以要向上取整。mxx=floor(x0+r)//大的值要向下取整

对于y。我们也能用欧股定理确定。y也是有一个范围。但是并不是所有y都要枚举的。明显。y的值是离圆心越远越好。所以对于每一个x而言只需要枚举最远的两个y值

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
double xo,yo,r;
double dist(double xx1,double yy1,double xx2,double yy2)
{
return sqrt((xx1-xx2)*(xx1-xx2) + (yy1-yy2)*(yy1-yy2));
}
double eps = 1e-;
bool big (double a,double b)
{
return (a-b)>eps;
}
bool same (double a,double b)
{
return fabs(a-b)<eps;
}
void work ()
{
int mix = (int)ceil(xo-r);
int mxx = (int)floor(xo+r);
double mxdis=-;
int ansx,ansy;
for (int i=mix;i<=mxx;++i)
{
int yy = (int)floor((yo+sqrt(r*r-(i-xo)*(i-xo))));
double tdis = dist(i,yy,xo,yo);
if (big(tdis,mxdis))
{
mxdis = tdis; ansx = i; ansy = yy;
}
else if (same(tdis,mxdis)&&i>ansx)
{
mxdis = tdis; ansx = i; ansy = yy;
}
else if (same(tdis,mxdis)&&i==ansx&&yy>=ansy)
{
mxdis = tdis; ansx = i; ansy = yy;
} yy = (int)ceil(yo-sqrt(r*r-(i-xo)*(i-xo)));
tdis=dist(i,yy,xo,yo);
if (big(tdis,mxdis))
{
mxdis = tdis; ansx = i; ansy = yy;
}
else if (same(tdis,mxdis)&&i>ansx)
{
mxdis = tdis; ansx = i; ansy = yy;
}
else if (same(tdis,mxdis)&&i==ansx&&yy>=ansy)
{
mxdis = tdis; ansx = i; ansy = yy;
}
}
printf ("%d %d\n",ansx,ansy);
return ;
}
int main()
{
#ifdef local
freopen("data.txt","r",stdin);
#endif
while(~scanf("%lf%lf%lf",&xo,&yo,&r)) work();
return ;
}

最新文章

  1. 史上最全的maven的pom.xml文件详解
  2. 提交留言HTML模板代码
  3. C#中String.Empty,“”,NULL的区别
  4. Java基础之集合框架——使用堆栈Stack&lt;&gt;对象模拟发牌(TryDeal)
  5. [iOS基础控件 - 6.10.5] UIApplication
  6. 一个方便的shell命令,查看软件安装目录
  7. linux线程之pthread_join
  8. [HNOI2013]游走 期望+高斯消元
  9. redis存取对象
  10. 微信小程序初体验,入门练手项目--通讯录,部署上线(二)
  11. day5_函数返回值
  12. VS2013中Python学习笔记[环境搭建]
  13. JAVA 项目中使用 H2 数据库
  14. 【Mysql】Mysql修改Root密码
  15. 作业:WordCount--实现字符数,单词数,行数的统计
  16. 发现微信支付bug
  17. 李洪强漫谈iOS开发[C语言-053]-小结
  18. [AGC026B]rng_10s
  19. ARM串口控制终端命令
  20. Verilog HDL设计规范及经验谈(转载)

热门文章

  1. Dockerfile创建MySQL容器
  2. 创建Azure Blob Snapshot的脚本
  3. Mybatis+Mysql 返回主键的值
  4. Mysql ExcuteNonQuery
  5. 关于ArcGis for javascrept之Map类
  6. 微信小程序--录制音频,播放音频
  7. Maven Cargo 远程部署到tomcat7x
  8. Learning Python 009 dict(字典)和 set
  9. 让开发更简单 —— Coding Enterprise 发布
  10. 数据库 连接(join)