博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 4454, 离散化,枚举
阅读量:4670 次
发布时间:2019-06-09

本文共 2819 字,大约阅读时间需要 9 分钟。

B. Stealing a Cake

Time Limit: 2000ms
Case Time Limit: 2000ms
Memory Limit: 32768KB
64-bit integer IO format:
%I64d      Java class name:
Main
Font Size:
There is a big round cake on the ground. A small ant plans to steal a small piece of cake. He starts from a certain point, reaches the cake, and then carry the piece back home. He does not want to be detected, so he is going to design a shortest path to achieve his goal.
The big cake can be considered as a circle on a 2D plane. The ant’s home can be considered as a rectangle. The ant can walk through the cake. Please find out the shortest path for the poor ant.

Input

The input consists of several test cases.
The first line of each test case contains x,y, representing the coordinate of the starting point. The second line contains x, y, r. The center of the cake is point (x,y) and the radius of the cake is r. The third line contains x1,y1,x2,y2, representing the coordinates of two opposite vertices of the rectangle --- the ant's home.
All numbers in the input are real numbers range from -10000 to 10000. It is guaranteed that the cake and the ant's home don't overlap or contact, and the ant's starting point also is not inside the cake or his home, and doesn't contact with the cake or his home.
If the ant touches any part of home, then he is at home.
Input ends with a line of 0 0. There may be a blank line between two test cases.

Output

For each test case, print the shortest distance to achieve his goal. Please round the result to 2 digits after decimal point.

Sample Input

1 1-1 1 10 -1 1 00 2-1 1 10 -1 1 00 0

Sample Output

1.752.00 这是队友在比赛时YY出来的NC算法:把圆离散化为比如1000各点,枚举每个点即可:),然后我苦力代码了出来:)。
#include
#include
#include
#include
#include
#include
#define MAX_INT 0x7fffffff#define LL long long#define ULL unsigned long long#define MAX(x,y) ((x) > (y) ? (x) : (y))#define MIN(x,y) ((x) > (y) ? (y) : (x))using namespace std;double sx,sy;double rx,ry,r;double X1,Y1,X2,Y2;const double PI=3.141592653589794;const int n=10000;double INF = 66666.0;struct node{ double x,y;}p[n+5];inline double dis(double x,double y,double xx1,double yy1){ return sqrt((x-xx1)*(x-xx1) + (y-yy1)*(y-yy1));}double get_dis(double x, double y){ double t=MIN(X1,X2); X2=MAX(X1,X2); X1=t; t=MIN(Y1,Y2); Y2=MAX(Y1,Y2); Y1=t; if(x>=X1 && x<=X2){ return MIN(fabs(y-Y2),fabs(y-Y1)); } else if(y>=Y1 && y<=Y2){ return MIN(fabs(x-X1),fabs(x-X2)); } t=dis(x,y,X1,Y1); t=MIN(t, dis(x,y,X2,Y1)); t=MIN(t, dis(x,y,X2,Y2)); t=MIN(t, dis(x,y,X1,Y2)); return t;}int main(){ while(scanf(" %lf %lf",&sx,&sy)==2 && (sx||sy)){ int i; scanf(" %lf %lf %lf",&rx,&ry,&r); scanf(" %lf %lf %lf %lf",&X1,&Y1,&X2,&Y2); for(int i=0; i

 

转载于:https://www.cnblogs.com/ramanujan/p/3412928.html

你可能感兴趣的文章
predis如何实现phpredis的pconnect方法
查看>>
杜教筛
查看>>
JavaScriptDom操作与高级应用(八)
查看>>
拜占庭将军问题
查看>>
Codeforces 1163A - Eating Soup
查看>>
vim使用小技巧
查看>>
AutoCAD ObjectARX和RealDWG的基本数据操作
查看>>
CSS的常见属性
查看>>
java ArrayList源码分析(转载)
查看>>
WIN10 64位 JDK的安装
查看>>
php : RBAC 基于角色的用户权限控制-表参考
查看>>
Hadoop入门经典:WordCount
查看>>
Reverse Words in a String
查看>>
在web浏览器上显示室内温度(nodeJs+arduino+socket.io)
查看>>
nodejs生成UID(唯一标识符)——node-uuid模块
查看>>
Java删除文件夹和文件
查看>>
CSU 1803 2016(数论)
查看>>
UVA116 单向 DSP(多段图最短路)
查看>>
Kruskal算法
查看>>
2018中国域名大会-强调服务与网络信息安全
查看>>