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机制 新的项目中如果有部 ...
随机推荐
- Java:Json与其他Java对象集合的转换
一.引入的jar包 json-lib-2.4-jdk15.jar 二.Json字符串转换为其他对象 1.对象==>json字符串 2.list和Map集合==>json字符串 3.Map集 ...
- jQuery 效果方法
jQuery 效果方法 下面的表格列出了所有用于创建动画效果的 jQuery 方法. 方法 描述 animate() 对被选元素应用"自定义"的动画 clearQueue() 对被 ...
- ios专题 - GCD(1)
什么是GCD? Grand Central Dispatch或者GCD,是一套低层API,提供了一种新的方法来进行并发程序编写.从基本功能上讲,GCD有点像 NSOperationQueue,他们都允 ...
- java中的包装类
每一个包装类都对应一种基本数据类型.包装类有:Integer.character.Byte.Short.Long.Floot.Double.Boolean这八种,分别对应的基本数据类型是:int.ch ...
- 选取两个有序数组中最大的K个值,降序存入另一个数组中
原题: 假设有两个有序的整型数组int *a1, int *a2,长度分别为m和n.试用C语言写出一个函数选取两个数组中最大的K个值(K可能大于m+n)写到int *a3中,保持a3降序,并返回a3实 ...
- 第一天的CI笔记
1 CI不区分大小写2. http://xxx.com/index/[控制器名称]/[控制器里面方法的确名称]/[传入方法的参数 ]/ 3. 控制器及控制器类名称与文件名称一致, 继承 CI_Cont ...
- Node.js(window)基础(2)——node环境下的模块,模块间调用
参考:http://www.liaoxuefeng.com/wiki/001434446689867b27157e896e74d51a89c25cc8b43bdb3000/00143450241959 ...
- js学习--DOM操作详解大全 前奏(认识DOM)
一 . 节点属性 DOM 是树型结构,相应的,可以通过一些节点属性来遍历节点树: 方法 说明 nodeName 节点名称,相当于tagName.属性节点返回属性名,文本节点返回#text.nodeNa ...
- 轻松使用px为单位开发移动端页面
研究移动端页面已经有许久了,一直执着于rem来开发,不谈性能怎么样,单从工作效率上看影响了不少,首先要固定设计稿的宽度,一般都是固定在640px,然后在根据根目录的字体大小来计算出每个元素的rem的值 ...
- 学习Swift -- 可选链
可空链式调用 可空链式调用是一种可以请求和调用属性.方法及下标的过程,它的可空性体现于请求或调用的目标当前可能为空(nil).如果可空的目标有值,那么调用就会成功:如果选择的目标为空(nil),那么这 ...