题目链接: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. 一款jquery小插件:实现轻松获取和绑定编辑表单的值(带源码)

    实现目的:通常在项目中,编辑页面在前后台需要一个一个框赋值,取值操作,小伙伴们普遍都会感觉繁琐,麻烦.: 实现思路:利用json对象化键值的思想: 好处:方便快速开发,提高开发效率,减少重复性代码: ...

  2. 2014-11-26----css的简介

    CSS :层叠样式表 cascading style sheets 它的作用是:美化html网页 格式:样式名:值:样式名:值:样式名:值: 注释语法:/* 注释内容 */ 选中代码按TAB,代码左移 ...

  3. Java基础--Java内存管理与垃圾回收

      Java自动内存管理 在讲解内存管理之前,首先需要了解对象和对象引用的区别 对象是类的一个实例,以人这个类为例,Person是我们定义的一个类 public class Person{} publ ...

  4. 自己使用Jquery封装各种功能分享

    自己使用Jquery封装各种功能分享: 左右滚动图片 瀑布流 流动显示列表 广告切换 头像切换And广告切换 获取搜索引擎的来源关键字 上面列表中展示的功能都是使用jquery进行封装实现的,希望大家 ...

  5. 使用 fn 标签 解决字数过多时用省略号代替 .............................

    list列表单条记录某字段大于10就后面添加省略号(如:内容只是显示开始的10个字,后面的用省略号代替) 在list列表中单条记录某字段大于10就后面添加省略号, 首先引入 jstl标签: <% ...

  6. SVN遇到Can't convert string from 'UTF-8' to native encoding

    刚配好mysql,svn co代码的时候遇到问题 svn: Can't convert string from 'UTF-8' to native encoding: svn: platform/co ...

  7. svn服务器时间与本地时间不同步解决

    在用svn的时候,由于svn的时间与本地不同步,导致每次看log总是需要对时间. 今天修改了svn服务器时间与本地同步.只需要修改svn服务器时间与本地时间相同即可,但要主要修改时区,不然会出现时间又 ...

  8. highcharts-Highmaps 动态传入城市名称

    做前端按地区(地图)分布监控数据展示用了 HIGHMAPS JAVASCRIPT MAPS 控件,很好很强大. 基础实现是这样的:调用插件动态传入需要展示的数据(data),插件会在地图数据(mapd ...

  9. 常用machine learning数据集

    ImageNet:非商业化的可视化大数据 截止到2015年5月1日,ImageNet数据库拥有超过1500万的图像. cifar10:10类物体识别数据集 数据集中包含60,000幅32*32图像,共 ...

  10. [BZOJ 1034] [ZJOI2008] 泡泡堂BNB 【贪心】

    题目链接:BZOJ - 1034 题目分析 这道题和田忌赛马的典故很相似. 先要将两队的队员都按照水平从小到大分别排序. 然后每次尝试用我方最弱的队员赢对方最弱的队员,或者用我方最强的队员赢对方最强的 ...