题目链接: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的更多相关文章

  1. poj 1266 Cover an Arc.

    http://poj.org/problem?id=1266 Cover an Arc. Time Limit: 1000MS   Memory Limit: 10000K Total Submiss ...

  2. 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 ...

  3. 贪心 URAL 1303 Minimal Coverage

    题目传送门 /* 题意:最少需要多少条线段能覆盖[0, m]的长度 贪心:首先忽略被其他线段完全覆盖的线段,因为选取更长的更优 接着就是从p=0开始,以p点为标志,选取 (node[i].l < ...

  4. ural 1245. Pictures

    1245. Pictures Time limit: 1.0 secondMemory limit: 64 MB Artist Ivanov (not the famous Ivanov who pa ...

  5. ural 1303 Minimal Coverage【贪心】

    链接: http://acm.timus.ru/problem.aspx?space=1&num=1303 http://acm.hust.edu.cn/vjudge/contest/view ...

  6. URAL 1277 Cops and Thieves

    Cops and Thieves Time Limit: 1000ms Memory Limit: 16384KB This problem will be judged on Ural. Origi ...

  7. 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 ...

  8. Dancing Links and Exact Cover

    1. Exact Cover Problem DLX是用来解决精确覆盖问题行之有效的算法. 在讲解DLX之前,我们先了解一下什么是精确覆盖问题(Exact Cover Problem)? 1.1 Po ...

  9. 黑马程序员——ARC机制总结和用ARC建立模型

    ARC 全称:Automatic Reference Counting 使用ARC 只需要在建立一个新的项目的时候把 下面的√打上 Xcode5以后都会默认建议开发者使用ARC机制 新的项目中如果有部 ...

随机推荐

  1. 使用for循环嵌套实现乘法口诀表

    九九乘法表的实现: package com.liaojianya.chapter1; /** * This program demonstrates the way of using * for-lo ...

  2. PC10303/UVA10252

    一开始看错题啦,以为是最长公共字序列的变题,认真一看,原来是排列后的最长公共序列,本来想着排序后,从小到大共同就输出的,但是认真一想,根本没必要,我有bitmap啊!之后哗啦啦地码完了,发现一个神奇的 ...

  3. 中文翻译:pjsip教程(一)之PJNATH简介

    在学习pjsip的过程中,发现只是单单的阅读英文官方文档,对于里边概念的理解还是不够透彻,并且苦于pjsip没有发现全一点的中文版本,所以想尽自己所能为建设和谐社会而贡献一份力量,文中定会有所疏漏,希 ...

  4. APACHE 与IIS同时存在的情况下,给APACHE添加反向代理 共用80端口

    一.首先打开IIS,将IIS的端口改成81,不要让IIS占用了80端口 二.打开APACHE的httpd.conf配置文件,将里面的端口配置成80 三.打开APACHE的虚拟目录配置文件,如:http ...

  5. etTimeout与setInterval方法的区别

    etTimeout与setInterval方法的区别 setTimeout()用于设定在指定的时间之后执行对应的函数或代码.,在全局作用域下执行 setTimeout(code,time[,args… ...

  6. [CSS]float&clear浮动

    CSS float 属性 浮动的框可以向左或向右移动,直到它的外边缘碰到包含框或另一个浮动框的边框为止. 由于浮动框不在文档的普通流中,所以文档的普通流中的块框表现得就像浮动框不存在一样.  可取的值 ...

  7. python判断一个数字是整数还是浮点数

    在网上闲逛,发现了一个python的用法

  8. 跨平台的WatiForSingleObject实现

    移植win32程序时,有一个难点就是涉及到内核对象的操作,需要模拟win32的实现. 其中比较奇葩的一个是WaitForSingleObject系列. Linux中没有类似的timeout实现,模拟这 ...

  9. Maven镜像配置

    镜像是为了提供更快的服务 如图:X就认为是Y的一个镜像. 编辑settings.xml配置中央仓库镜像: <settings> ... <mirrors> <mirror ...

  10. Android项目无法运行的解决方法

    文件本身是否有问题 有两种方法可以判断:1.比较快捷的办法就是用解压软件打开或者解压的过程中有没有弹出什么错误提示,如果有错误提示那就重新下载一遍文件(javaapk用的压缩工具是winrar4.0, ...