↓ 跳过正文
  1. Posts/

codeforces #339 div 2 C. Peter and Snow Blower

·559 字·2 分钟

http://codeforces.com/contest/614/problem/C
#

题意:给一个多边形和多边形外一定点,多边形绕定点旋转,问多边形扫过的面积。 思路:简单计算几何,找到多边形距离定点的最大和最小距离R和r,答案就是(R^2-R^2)*PI 需要注意的是:最大距离一定是从某点上取得,但是最小距离可能不在顶点上,而在某条边上。

代码实现
  1/* ***********************************************
  2Author :111qqz
  3Created Time :2016年02月16日 星期二 16时58分59秒
  4File Name :code/cf/problem/614C.cpp
  5************************************************ */
  6
  7#include <cstdio>
  8#include <cstring>
  9#include <iostream>
 10#include <algorithm>
 11#include <vector>
 12#include <queue>
 13#include <set>
 14#include <map>
 15#include <string>
 16#include <cmath>
 17#include <cstdlib>
 18#include <ctime>
 19#define fst first
 20#define sec second
 21#define lson l,m,rt<<1
 22#define rson m+1,r,rt<<1|1
 23#define ms(a,x) memset(a,x,sizeof(a))
 24typedef long long LL;
 25#define pi pair < int ,int >
 26#define MP make_pair
 27
 28using namespace std;
 29const double eps = 1E-8;
 30const int dx4[4]={1,0,0,-1};
 31const int dy4[4]={0,-1,1,0};
 32const int inf = 0x3f3f3f3f;
 33const int N = 1E5+7;
 34const double PI = acos(-1.0);
 35
 36int dblcmp(double d)
 37{
 38    return d<-eps?-1:d>eps;
 39}
 40struct point
 41{
 42    double x,y;
 43    point (){}
 44    point (double _x,double _y):
 45	x(_x),y(_y){};
 46    void input()
 47    {
 48	cin>>x>>y;
 49    }
 50    point sub(point p)
 51    {
 52	return point (x-p.x,y-p.y);
 53    }
 54    double dot(point p)
 55    {
 56	return x*p.x+y*p.y;
 57    }
 58    double distance2(point p)
 59    {
 60	return (x-p.x)*(x-p.x)+(y-p.y)*(y-p.y);
 61    }
 62    double distance(point p)
 63    {
 64	return hypot(x-p.x,y-p.y);
 65    }
 66    double det(point p)
 67    {
 68	return x*p.y-y*p.x;
 69    }
 70}p[N],q;
 71double sqr(double x)
 72{
 73    return x*x;
 74}
 75struct line
 76{
 77    point a,b;
 78    line(){}
 79    line (point _a,point _b)
 80    {
 81	a = _a;
 82	b = _b;
 83    }
 84    double length()
 85    {
 86	return a.distance(b);
 87    }
 88
 89    double dispointtoline2(point p)
 90    {
 91	double res = sqr(fabs(p.sub(a).det(b.sub(a)))/length());
 92//	cout<<"res:"<<res<<endl;
 93	return res;
 94    }
 95    double dispointtoseg2(point p)
 96    {
 97	if (dblcmp(p.sub(b).dot(a.sub(b)))<0||dblcmp(p.sub(a).dot(b.sub(a)))<0)
 98	    return min(p.distance2(a),p.distance2(b));
 99
100    return dispointtoline2(p);
101    }
102}li[N];
103
104int n;
105int main()
106{
107	#ifndef  ONLINE_JUDGE
108	freopen("code/in.txt","r",stdin);
109  #endif
110
111	cin>>n;
112	q.input();
113	double MIN = 99999999999999999;
114	double MAX = -1;
115	for ( int i = 1 ; i <= n ; i++)
116	{
117	    p[i].input();
118	    double d= p[i].distance2(q);
119	    MAX = max(MAX,d);
120	}
121
122	for ( int i = 1 ; i <= n-1 ; i++)
123	{
124	    li[i] = line(p[i],p[i+1]);
125	}
126	li[n]=line(p[n],p[1]);
127	for ( int i = 1 ; i <= n ; i++)
128	{
129	    double d = li[i].dispointtoseg2(q);
130//	    cout<<li[i].a.x<<" "<<li[i].a.y<<"   "<<li[i].b.x<<" "<<li[i].b.y<<endl;
131	//    cout<<"d:"<<d<<endl;
132	    MIN = min(MIN,d);
133	}
134//	cout<<"MAX:"<<MAX<<"  MIN:"<<MIN<<endl;
135	double ans = (MAX-MIN)*PI;
136	printf("%.18f\n",ans);
137
138
139  #ifndef ONLINE_JUDGE
140  fclose(stdin);
141  #endif
142    return 0;
143}

相关文章

codeforces 14 C. Four Segments

·452 字·1 分钟
http://codeforces.com/problemset/problem/14/C 题意:给出四条边的坐标,问能否形成一个边与坐标轴平行的矩形。边可能退化成点。 思路:首先第一步,检查有没有边退化成点以及是否有不平行的边。 第二步,检查两个方向的边是否各有两条。。

hdu 1221 Rectangle and Circle

·252 字·1 分钟
http://acm.hdu.edu.cn/showproblem.php?pid=1221 题意:问圆和矩形是否相交 思路:主要特殊的包含情况,然后判断与线段相交。 代码实现 1/* *********************************************** 2Author :111qqz 3Created Time :2015年12月21日 星期一 21时38分22秒 4File Name :code/hdu/rr1221.cpp 5************************************************ */ 6 7#include <iostream> 8#include <string.h> 9#include <stdio.h> 10#include <algorithm> 11#include <cmath> 12#define eps 1e-8 13using namespace std; 14struct point 15{ 16 double x; 17 double y; 18}circle,a,b,c,d; 19double r; 20double dis(point &a,point &b) 21{ 22 return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); 23} 24 25bool ok() 26{ 27 28 if(dis(a,circle)<r && dis(b,circle) <r && dis(c,circle)<r && dis(d,circle) <r) 29 return false; 30 if(circle.x>=a.x && circle.x<=b.x) 31 { 32 if(fabs(circle.y-a.y) <= r || fabs(circle.y-b.y) <= r) 33 return true; 34 } 35 if((circle.y >= a.y && circle.y <=b.y) || (circle.y>=b.y && circle.y<=a.y)) 36 { 37 if(fabs(circle.x-a.x) <=r || fabs(circle.x-b.x) <=r) 38 return true; 39 } 40 if(dis(a,circle)<=r || dis(b,circle) <=r || dis(c,circle)<=r || dis(d,circle) <=r) 41 return true; 42 return false; 43} 44int main() 45{ 46 #ifndef ONLINE_JUDGE 47 freopen("code/in.txt","r",stdin); 48 #endif 49 int t; 50 scanf("%d",&t); 51 while(t--) 52 { 53 scanf("%lf %lf %lf %lf %lf %lf %lf",&circle.x,&circle.y,&r,&a.x,&a.y,&b.x,&b.y); 54 if(a.x > b.x) 55 swap(a,b); 56 c.x=a.x,c.y=b.y; 57 d.x=b.x,d.y=a.y; 58 59 if (ok()) 60 { 61 puts("YES"); 62 } 63 else 64 { 65 puts("NO"); 66 } 67 } 68 return 0; 69}

codeforces #320 div 2 C. A Problem about Polyline(计算几何?数学)

·818 字·2 分钟
C. A Problem about Polyline time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There is a polyline going through points (0, 0) - (x, x) - (2_x_, 0) - (3_x_, x) - (4_x_, 0) - … - (2_kx_, 0) - (2_kx_ + x, x) - …. We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or determine that there is no such x.

hdu 3532 Max Angle(atan2的使用)

·784 字·2 分钟
Max Angle # **Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 678 Accepted Submission(s): 238 ** Problem Description Given many points in a plane, two players are playing an interesting game. Player1 selects one point A as the vertex of an angle. Then player2 selects other two points B and C. A, B and C are different with each other. Now they get an angle B-A-C.