Ural 1043 Cover the Arc
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1043
题目大意:一个2000*2000方格坐标,x,y范围都是【-1000,1000】。现在给你一个圆弧,告诉你圆弧的两个端点和任意一个中间点。现在要你算出最小的矩形(长和宽都要为整数,即四个顶点在方格顶点上)来完全覆盖这个圆弧。
算法思路:很明显要算出圆心,这个可以有线段中垂线交求,也可以由方程,只是很麻烦。然后以圆心找出这个圆的左右上下四个极点,判断是否在圆弧上(用叉积即可),与给出的三个点一起维护这段圆弧的四个方向的极大点。然后向上向下取整即可。
代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std; const double eps = 1e-;
const double INF = 1000000000.00; struct Point{
double x,y;
Point(double x=,double y=): x(x), y(y) {}
}; typedef Point Vector; Vector operator + (Vector A,Vector B) { return Vector(A.x+B.x,A.y+B.y); }
Vector operator - (Vector A,Vector B) { return Vector(A.x-B.x,A.y-B.y); }
Vector operator * (Vector A,double p) { return Vector(A.x*p,A.y*p); }
Vector operator / (Vector A,double p) { return Vector(A.x/p,A.y/p); } bool operator < (const Point& A, const Point& B){
return A.x < B.x || (A.x == B.x && A.y < B.y);
}
int dcmp(double x){
if(fabs(x) < eps) return ;
return x < ? - : ;
}
bool operator == (const Point& A,const Point& B){
return dcmp(A.x-B.x) == && dcmp(A.y-B.y) == ;
}
double Dot(Vector A,Vector B){ return A.x*B.x+A.y*B.y; }
double Length(Vector A) { return sqrt(Dot(A,A)); }
double Cross(Vector A,Vector B) { return A.x*B.y-A.y*B.x; } Point read_point()
{
Point P;
scanf("%lf %lf",&P.x,&P.y);
return P;
}
Point normal(Vector A) { return Vector(-A.y,A.x); }; Point GetLineIntersecion(Point P, Vector v,Point Q,Vector w){
Vector u = P - Q;
double t = Cross(w,u)/Cross(v,w);
return P + v*t;
} void Judge(Point& Pl,Point& Pr,Point& Pu,Point& Pd,Point P){
if(Pl.x > P.x) Pl = P;
if(Pr.x < P.x) Pr = P;
if(Pu.y < P.y) Pu = P;
if(Pd.y > P.y) Pd = P;
} int main()
{
//freopen("E:\\acm\\input.txt","r",stdin);
Point Ps,Pt,Pi;
Ps = read_point();
Pt = read_point();
Pi = read_point();
Point mid1,mid2,O; mid1 = (Ps+Pi)/;
mid2 = (Pi+Pt)/;
O = GetLineIntersecion(mid1,normal(Ps-Pi),mid2,normal(Pi-Pt)); double r = Length(O-Ps);
Point Pu,Pl,Pr,Pd;
Pu = Pl = Pr = Pd = Ps; Judge(Pl,Pr,Pu,Pd,Pt);
Judge(Pl,Pr,Pu,Pd,Pi); Point P = Point(O.x+r,O.y);
if(dcmp(Cross(Pt-Ps,Pi-Ps)*Cross(Pt-Ps,P-Ps)) > ){
Judge(Pl,Pr,Pu,Pd,P);
}
P = Point(O.x-r,O.y);
if(dcmp(Cross(Pt-Ps,Pi-Ps)*Cross(Pt-Ps,P-Ps)) > ){
Judge(Pl,Pr,Pu,Pd,P);
}
P = Point(O.x,O.y+r);
if(dcmp(Cross(Pt-Ps,Pi-Ps)*Cross(Pt-Ps,P-Ps)) > ){
Judge(Pl,Pr,Pu,Pd,P);
}
P = Point(O.x,O.y-r);
if(dcmp(Cross(Pt-Ps,Pi-Ps)*Cross(Pt-Ps,P-Ps)) > ){
Judge(Pl,Pr,Pu,Pd,P);
}
int width = ceil(Pu.y-eps) - floor(Pd.y+eps);
int length = ceil(Pr.x-eps) - floor(Pl.x+eps);
printf("%d\n",width*length);
}
Ural 1043 Cover the Arc的更多相关文章
- poj 1266 Cover an Arc.
http://poj.org/problem?id=1266 Cover an Arc. Time Limit: 1000MS Memory Limit: 10000K Total Submiss ...
- URAL 2038 Minimum Vertex Cover
2038. Minimum Vertex Cover Time limit: 1.0 secondMemory limit: 64 MB A vertex cover of a graph is a ...
- 贪心 URAL 1303 Minimal Coverage
题目传送门 /* 题意:最少需要多少条线段能覆盖[0, m]的长度 贪心:首先忽略被其他线段完全覆盖的线段,因为选取更长的更优 接着就是从p=0开始,以p点为标志,选取 (node[i].l < ...
- ural 1245. Pictures
1245. Pictures Time limit: 1.0 secondMemory limit: 64 MB Artist Ivanov (not the famous Ivanov who pa ...
- ural 1303 Minimal Coverage【贪心】
链接: http://acm.timus.ru/problem.aspx?space=1&num=1303 http://acm.hust.edu.cn/vjudge/contest/view ...
- URAL 1277 Cops and Thieves
Cops and Thieves Time Limit: 1000ms Memory Limit: 16384KB This problem will be judged on Ural. Origi ...
- Convert BSpline Curve to Arc Spline in OpenCASCADE
Convert BSpline Curve to Arc Spline in OpenCASCADE eryar@163.com Abstract. The paper based on OpenCA ...
- Dancing Links and Exact Cover
1. Exact Cover Problem DLX是用来解决精确覆盖问题行之有效的算法. 在讲解DLX之前,我们先了解一下什么是精确覆盖问题(Exact Cover Problem)? 1.1 Po ...
- 黑马程序员——ARC机制总结和用ARC建立模型
ARC 全称:Automatic Reference Counting 使用ARC 只需要在建立一个新的项目的时候把 下面的√打上 Xcode5以后都会默认建议开发者使用ARC机制 新的项目中如果有部 ...
随机推荐
- oracle 消除块竞争(hot blocks)
上篇日志提到了,那么高的负载,是存在数据块读竞争,下面介绍几个方法来消除块竟争 查找块竟争 SELECT p1 "file#", p2 "block#", p3 ...
- Jsp的九个隐含对象
JSP的9个隐含对象(内置对象) 不需要预先声明,就可以在jsp或者表达式中随意使用 out javax.servlet.jsp.JspWriter类型,代表输出流的对象.作业域:页面的执行期. re ...
- java常用正则表达式
1.邮编 public static final String POSTAL_CODE = "^\\d{6}$"; 2. email(支持中文域名邮箱) 正则表达式 public ...
- ios专题 - Scrum
什么是Scrum? Scrum是一个敏捷开发框架,是一个增量的.迭代的开发过程.在这个框架中,整个开发过程由若干个短的迭代周期组成,一个短的迭代周期称为一个 Sprint,每个Sprint的建议长度是 ...
- PHP 单一入口
单一入口概述 单一入口的应用程序就是说用一个文件处理所有的HTTP请求,例如不管是列表页还是文章页,都是从浏览器访问index.php文件,这个文件就是这个应用程序的单一入口. 打个比方,大家都要上W ...
- Git 基本使用配置
// 1.配置用户名邮箱:用于记录你个人的用户名称和电子邮件地址,用户名可随意修改,git 用于记录是谁提交了更新,以及更新人的联系方式: $ git config --global user.nam ...
- 基于jq图片居中插件 [center]
最近在做一个项目,大量的图片基于js进行缩放(图片放大镜),考虑用css要写许多hack,而已经基于jq了,干脆写个方法得了. 代码很简单,不用多讲但是很实用. $.fn.extend({ cente ...
- 【随记】还原SQL Server数据库步骤
情景:在一台机器上备份数据库,然后在另一台机器上还原数据库,可能会出现错误提示:System.Data.SqlClient.SqlError: 备份集中的数据库备份与现有的 'XXX' 数据库不同. ...
- [CSS]float&clear浮动
CSS float 属性 浮动的框可以向左或向右移动,直到它的外边缘碰到包含框或另一个浮动框的边框为止. 由于浮动框不在文档的普通流中,所以文档的普通流中的块框表现得就像浮动框不存在一样. 可取的值 ...
- php几个比较高级的函数
1.传递任意数量的函数参数 我们在.NET或者JAVA编程中,一般函数参数个数都是固定的,但是PHP允许你使用任意个数的参数.下面这个示例向你展示了PHP函数的默认参数: 1 2 3 4 5 6 7 ...