poj 1266 Cover an Arc.
2015-05-07 08:53
169 查看
http://poj.org/problem?id=1266
Cover an Arc.
Description
A huge dancing-hall was constructed for the Ural State University's 80-th anniversary celebration. The size of the hall is 2000 * 2000 metres! The floor was made of square mirror plates with side equal to 1 metre. Then the walls were painted with an indelible paint. Unfortunately, in the end the painter flapped the brush and the beautiful mirror floor was stained with the paint. But not everything is lost yet! The stains can be covered with a carpet.
Nobody knows why, but the paint on the floor formed an arc of a circle (a centre of the circle lies inside the hall). The dean of the Department of Mathematics and Mechanics measured the coordinates of the arc's ends and of some other point of the arc (he is sure that this information is quite enough for any student of the Ural State University). The dean wants to cover the arc with a rectangular carpet. The sides of a carpet must go along the sides of the mirror plates (so, the corners of the carpet must have integer coordinates).
You should find the minimal square of such a carpet.
Input
The input consists of six integers. At first the coordinates of the arc's ends are given. The co-ordinates of an inner point of the arc follow them. Absolute value of coordinates doesn't exceed 1000. The points don't belong the same straight line. The arc lies inside the square [-1000,1000] * [-1000,1000].
Output
You should write to the standard output the minimal square of the carpet covering this arc.
Sample Input
Sample Output
Source
Ural State University Internal Contest October'2000 Students Session (URAL 1043)
分析:
几何题, 求正方形覆盖圆弧的面积。
AC代码:
Cover an Arc.
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 823 | Accepted: 308 |
A huge dancing-hall was constructed for the Ural State University's 80-th anniversary celebration. The size of the hall is 2000 * 2000 metres! The floor was made of square mirror plates with side equal to 1 metre. Then the walls were painted with an indelible paint. Unfortunately, in the end the painter flapped the brush and the beautiful mirror floor was stained with the paint. But not everything is lost yet! The stains can be covered with a carpet.
Nobody knows why, but the paint on the floor formed an arc of a circle (a centre of the circle lies inside the hall). The dean of the Department of Mathematics and Mechanics measured the coordinates of the arc's ends and of some other point of the arc (he is sure that this information is quite enough for any student of the Ural State University). The dean wants to cover the arc with a rectangular carpet. The sides of a carpet must go along the sides of the mirror plates (so, the corners of the carpet must have integer coordinates).
You should find the minimal square of such a carpet.
Input
The input consists of six integers. At first the coordinates of the arc's ends are given. The co-ordinates of an inner point of the arc follow them. Absolute value of coordinates doesn't exceed 1000. The points don't belong the same straight line. The arc lies inside the square [-1000,1000] * [-1000,1000].
Output
You should write to the standard output the minimal square of the carpet covering this arc.
Sample Input
476 612 487 615 478 616
Sample Output
66
Source
Ural State University Internal Contest October'2000 Students Session (URAL 1043)
分析:
几何题, 求正方形覆盖圆弧的面积。
AC代码:
#include<iostream> #include<algorithm> #include<stdio.h> #define max(a,b) a>b?a:b #define min(a,b) a>b?b:a #include<math.h> using namespace std; #define eps 1e-8 struct point{double x,y;}; struct line {point a,b;}; point a,b,c; double xmult(point p1,point p2,point p0){ return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y); } bool pp(point p) { double t1,t2; t1=(xmult(a,c,b)); t2=(xmult(a,p,b)); if ((t1<0&&t2<0)||(t1>0&&t2>0)) return true; return false; } double distan (point p1,point p2) { return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)); } point inter(line u,line v) { point ret = u.a; double t = ((u.a.x-v.a.x)*(v.a.y-v.b.y)-(u.a.y-v.a.y)*(v.a.x-v.b.x))/((u.a.x-u.b.x)*(v.a.y-v.b.y)-(u.a.y-u.b.y)*(v.a.x-v.b.x)); ret.x +=(u.b.x-u.a.x)*t; ret.y +=(u.b.y-u.a.y)*t; return ret; } point circle(point a,point b,point c ) { line u,v; u.a.x =(a.x+b.x)/2; u.a.y = (a.y+b.y)/2; u.b.x = u.a.x - a.y+b.y; u.b.y = u.a.y + a.x-b.x; v.a.x = (a.x+c.x)/2; v.a.y = (a.y+c.y)/2; v.b.x = v.a.x - a.y+c.y; v.b.y = v.a.y+a.x-c.x; return inter(u,v); } int main() { point d,e,p; int cas =1; while(~scanf("%lf %lf %lf %lf %lf %lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y)) { d = circle(a,b,c); double bj = distan(d,a); double maxx,maxy,minx,miny; double dd=d.x,yy=d.y; int ax,bx,cx,ay,by,cy; maxx=max(a.x,b.x); maxx=max(maxx,c.x); minx=min(a.x,b.x); minx=min(minx,c.x); maxy=max(a.y,b.y); maxy=max(maxy,c.y); miny=min(a.y,b.y); miny=min(miny,c.y); p.x=d.x-bj; p.y=d.y; if(pp(p)) minx=p.x; p.x=d.x+bj; if(pp(p)) maxx=p.x; p.x=d.x; p.y=d.y-bj; if(pp(p)) miny=p.y; p.y=d.y+bj; if(pp(p)) maxy=p.y; cx=(long)ceil(maxx-eps)-(long)floor(minx+eps); cy=(long)ceil(maxy-eps)-(long)floor(miny+eps); printf("%d\n",cx*cy); } return 0; }
相关文章推荐
- POJ1266 Cover an Arc (计算几何模板)
- POJ 1266 Cover an Arc. 笔记
- POJ 1694 An Old Stone Game
- POJ 3358- Period of an Infinite Binary Expansion(欧拉函数+欧拉定理)
- POJ_1694_An Old Stone Game
- POJ 2826 An Easy Problem?!
- POJ-3358-Period of an Infinite Binary Expansion 解题报告
- poj 3778 hdu 3412 An Odd Award Rule
- POJ 1694 An Old Stone Game
- POJ 3842 An Industrial Spy
- POJ 2411 - Mondriaan\'s Dream
- poj_3358_Period of an Infinite Binary Expansion
- POJ_3842_An Industrial Spy_筛法、素数表
- POJ 2826 An Easy Problem?!
- POJ 2826 An Easy Problem?! (线段相交)
- POJ 2826 An Easy Problem?! <计算几何>
- POJ 2826 An Easy Problem? 判断线段相交
- POJ 2826 An Easy Problem?!(计算几何)
- POJ 2394 Checking an Alibi 简单最短路
- poj 3358 Period of an Infinite Binary Expansion 欧拉定理