【hihocoder】1237 : Farthest Point 微软2016校招在线笔试题
题目:给定一个圆,要你求出一个在里面或者在边上的整数点,使得这个点到原点的距离最大,如果有多个相同,输出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 ;
}
【hihocoder】1237 : Farthest Point 微软2016校招在线笔试题的更多相关文章
- 2016最新Java笔试题集锦
更新时间:2015-08-13 来源:网络 投诉删除 [看准网(Kanzhun.com)]笔试题目频道小编搜集的范文“2016最新Java笔试题集锦”,供大家阅读参考, ...
- hihocoder 1237 Farthest Point
#1237 : Farthest Point 时间限制:5000ms 单点时限:1000ms 内存限制:256MB 描述 Given a circle on a two-dimentional pla ...
- ThoughtWorks西邮暑期特训营 -- JavaScript在线笔试题
ThoughtWorks 公司在西邮正式开办的只教女生前端开发的女子卓越实验室已经几个月过去了,这次计划于暑期在西邮内部开展面向所有性别所有专业的前端培训. 具体官方安排请戳:ThoughtWorks ...
- 2014阿里巴巴WEB前端实习生在线笔试题
2014年3月31日晚,我怀着稍微忐忑的心情(第一次在线笔试^_^!!)进行了笔试.阿里巴巴的笔试题共同拥有10道,差点儿包括了Web前端开发的各个方面,有程序题.有叙述题.时间很紧张,仅仅完毕了大概 ...
- [Hihocoder 1289] 403 Forbidden (微软2016校园招聘4月在线笔试)
传送门 #1289 : 403 Forbidden 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi runs a web server. Someti ...
- hihoCoder #1106 : Koch Snowflake 微软苏州校招笔试(1月17日)
描述 Koch Snowflake is one of the most famous factal. It is built by starting with an equilateral tria ...
- 2016年4月21百度iOS实习生在线笔试题&编程题
1.一个人上台阶可以一次上1个,2个,或者3个,问这个人上32层的台阶,总共有几种走法? 思路:先建立数学模型,设3步的走 i 次,2步的走 j 次, 1步的走 k 次,上了3*i + 2*j + 1 ...
- 2015网易校招Java开发工程师(技术架构)在线笔试题
1. 程序和进程的本质区别是? A.在外存和内存存储 B.非顺序和顺序执行机器指令 C.独占使用和分时使用计算机资源 D.静态和动态特征 参考答案分析: 进程与应用程序的区别: 进程(Process ...
- 2015年网易校招Java开发工程师(技术架构)在线笔试题
1. 程序和进程的本质区别是? A.在外存和内存存储 B.非顺序和顺序执行机器指令 C.独占使用和分时使用计算机资源 D.静态和动态特征 参考答案分析: 进程与应用程序的区别: 进程(Process ...
随机推荐
- Go中使用动态库C/C++库
转自:http://studygolang.com/articles/1441 最近需要做一些在go中使用动态C++库的工作,经常碰到找不到动态库路径这种情况,所以就花点时间,专门做一下实验来了解Go ...
- 滑动swipe的妙用
转自:http://www.cnblogs.com/NEOCSL/archive/2013/03/04/2942861.html iterface ITouchable; function OnPic ...
- windows 创建和调用 动态库,静态库
windows创建和调用静态库 // MathFuncsLib.h namespace MathFuncs { class MyMathFuncs { public: // Returns a + b ...
- nop前端分页实现思路及步骤
注:nop本身已经有啦可以实现分页的类,所以我们直接去使用就可以啦 . (编程部分)步骤如下: 第一步,针对Model操作,在需要使用分页的界面Model中将分页类作为该Model类的成员,并在Mod ...
- Bluetooth Functions
The functions in this section are used for managing Bluetooth devices and services. Bluetooth is als ...
- socket消息发送
expressClient.html <html><head><meta http-equiv="Content-Type" content=&quo ...
- Flask03 路由控制(转换器)、反转、请求方法控制
1 提出问题 如何实现前端传过去的路径时动态的(即:多个url对应一个url视图函数) 例如: 浏览器中输入 http://127.0.0.1:5000/test/good/ 或者 http://12 ...
- webpack@3.6.0(3)-- 优化
本篇内容 babel配置 打包调试 第三方资源引入 静态资源的集中输出 babel配置 cnpm i -D babel-core babel-loader babel-preset-es2015 // ...
- SQL Server 2012 安装——安装 OR 卸载
前言 上篇介绍了.net framework 3.5的安装,这次介绍一下,SQL Server2012的安装和彻底卸载.根据百度,下面是自己根据自己实际情况整理的安装步骤: 安装 见安装步骤( ...
- hdu6055(求正方形个数)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6055 题意: 给出 n 组坐标 x, y, 输出其中的正多边形个数 . 其中 x, y 均为整数. ...