Justice is Given by Light,一条计算几何
来源:互联网 发布:中国物联网域名注册 编辑:程序博客网 时间:2024/06/06 04:36
http://acm.uestc.edu.cn/#/problem/show/814
一条简单的计算几何,也是我的开篇之作。
其实挺简单的,只要注意到一条边可以被一个圆完全包含,也能被两条边完全包含即可。
曾经看到一个二分r的题解,不推荐那样做。
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <cmath>#include <algorithm>using namespace std;typedef long long ll;inline double ss(double a,double b,double c,double d) //求点与点距离{return sqrt((a-c)*(a-c)+(b-d)*(b-d));}double x[22],y[22],x_1,x_2,y_1,y_2,x_0,y_0;double count_len(int i) //计算要包含第i个点与第i+1个点所需最小半径{double a1=ss(x_1,y_1,x[i],y[i]),a2=ss(x_2,y_2,x[i],y[i]),b1=ss(x_1,y_1,x[i+1],y[i+1]),b2=ss(x_2,y_2,x[i+1],y[i+1]);double r=0;r=min<double>(max<double>(a1,b1),max<double>(a2,b2));if(fabs(y_1-y_2)<1e-6) {if(x[i]<=x_0&&x[i+1]>=x_0||x[i+1]<=x_0&&x[i]>=x_0) {double yy=(y[i+1]-y[i])/(x[i+1]-x[i])*(x_0-x[i])+y[i]-y_0;r=min<double>(r,max<double>(sqrt(yy*yy+(x_0-x_1)*(x_0-x_1)),max<double>(min<double>(a1,a2),min<double>(b1,b2))));}}else {double k=(x_1-x_2)/(y_2-y_1);if(fabs(x[i]-x[i+1])<1e-6) {double yy=y_0+k*(x[i]-x_0);if(yy>=y[i]&&yy<=y[i+1]||yy>=y[i+1]&&yy<=y[i])r=min<double>(r,max<double>(ss(x_1,y_1,x[i],yy),max<double>(min<double>(a1,a2),min<double>(b1,b2))));}else {double ki=(y[i+1]-y[i])/(x[i+1]-x[i]);double xx=(ki*x[i]+y_0-y[i]-k*x_0)/(ki-k);double yy=y[i]+ki*(xx-x[i]);if(xx<=x[i]&&xx>=x[i+1]||xx<=x[i+1]&&xx>=x[i])r=min<double>(r,max<double>(ss(x_1,y_1,xx,yy),max<double>(min<double>(a1,a2),min<double>(b1,b2))));}}return r;}int main(){//freopen("aa.txt","r",stdin);int n,i;double ans=0;cin>>n;for(i=1;i<=n;i++)cin>>x[i]>>y[i];x[n+1]=x[1];y[n+1]=y[1];cin>>x_1>>y_1>>x_2>>y_2;x_0=(x_1+x_2)/2;y_0=(y_1+y_2)/2;for(i=1;i<=n;i++)ans=max<double>(ans,count_len(i));cout.setf(ios::fixed);cout.precision(3);cout<<ans;}
0 0
- Justice is Given by Light,一条计算几何
- uestc oj Justice is Given by Light(计算几何)
- the 12th UESTC Programming Contest Final Justice is Given by Light (几何+ 二分)
- 【计算几何】ZOJ 2976 Light Bulbs
- zoj 3203 Light Bulb(计算几何)
- HDU-2857-Mirror and Light(计算几何)
- ZOJ 3203 Light Bulb (三分+计算几何)
- HDU 2857 Mirror and Light [计算几何]
- UVALive 6188 (LA 6188) Let There Be Light 计算几何
- light oj 1043 - Triangle Partitioning【简单计算几何】
- light oj 1211 - Intersection of Cubes (计算几何)
- light oj 1216 - Juice in the Glass (几何计算)
- HDU 2857 Mirror and Light (计算几何求 对称点和两直线的交点)
- Light oj 1433 - Minimum Arc Distance【计算几何(坑精度!)】
- Hessian调用过程报错Pass-by-value is not supported for the given object
- UVa 10012 How Big is It? (计算几何+DFS)
- uva 10209 Is This Integration ? (计算几何)
- UVa 10209 Is This Integration ?(计算几何)
- 迪杰斯特拉算法入门
- 经典排序算法-------插入排序法
- Dart更近一步,Sky会一统江湖吗?
- 物与物的互通:解析Thread、AllJoyn、OIC、Bonjour的特点
- Bluemix云平台实战日志:IBM Mobile Data云服务和Android应用开发
- Justice is Given by Light,一条计算几何
- HttpClient和OkHttp关于Https请求问题
- poj 3704 Sudoku(Dancing Links)
- NSOperaion相关
- 最佳实战:用Cocos2d-x3.x和C++11编写2048游戏以及游戏AI(全民2048 Android版上线啦)
- 写博文不仅仅是记录,更是思考、总结和提高
- GRASP:Greedy Randomized Adaptive Search Procedures 贪心随机自适应搜索算法的基本思想
- Race to 1 Again [概率]
- jQuery源码学习(版本1.11)-ready