↓ 跳过正文
  1. Posts/

codeforces 14 C. Four Segments

·452 字·1 分钟

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

第二步,检查两个方向的边是否各有两条。。

第三步,将所有点的坐标排序。。然后看8个点是否会因为重合而变成4个.。

代码实现
  1/* ***********************************************
  2Author :111qqz
  3Created Time :2015年12月29日 星期二 16时28分28秒
  4File Name :code/cf/problem/14C.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;
 33int a,b,c,d;
 34int l[10];
 35int cnt;
 36
 37
 38
 39struct point
 40{
 41    int x,y;
 42
 43    bool operator <(point p)const
 44    {
 45	if (x<p.x) return true;
 46	if (x==p.x&&y<p.y) return true;
 47	return false;
 48    }
 49    bool ok (point p)
 50    {
 51	if (x!=p.x&&y!=p.y) return false; //不平行
 52	if (x==p.x&&y==p.y) return false; //退化成一点
 53	if (x==p.x) cnt++;
 54	return true;
 55    }
 56
 57    bool operator ==(point p)const
 58    {
 59	return x==p.x&&y==p.y;
 60    }
 61    bool operator !=(point p)const
 62    {
 63	if (x!=p.x||y!=p.y) return true;
 64	return false;
 65    }
 66}p[10];
 67int main()
 68{
 69	#ifndef  ONLINE_JUDGE
 70	freopen("code/in.txt","r",stdin);
 71  #endif
 72
 73	bool ok=true;
 74	cnt =  0 ;
 75	for ( int i = 0 ; i < 4 ; i++)
 76	{
 77	    cin>>p[i].x>>p[i].y>>p[i+4].x>>p[i+4].y;
 78	    if (!p[i].ok(p[i+4]))
 79	    {
 80		ok = false;
 81	    }
 82	}
 83	if (!ok||cnt!=2)
 84	{
 85	    puts("NO");
 86
 87	}
 88	else
 89	{
 90	    sort(p,p+8);
 91	    if (p[0]==p[1]&&p[2]==p[3]&&p[4]==p[5]&&p[6]==p[7]&&p[0]!=p[2]&&p[2]!=p[4]&&p[4]!=p[6]) //两两重合后保证四个点
 92	    {
 93		puts("YES");
 94	    }
 95	    else
 96	    {
 97		puts("NO");
 98	    }
 99	}
100
101  #ifndef ONLINE_JUDGE
102  fclose(stdin);
103  #endif
104    return 0;
105}

相关文章

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.

poj 1106 Transmitters (计算几何,叉积||极角排序)

·902 字·2 分钟
Transmitters Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4817 Accepted: 2576 Description In a wireless network with multiple transmitters sending on the same frequencies, it is often a requirement that signals don’t overlap, or at least that they don’t conflict. One way of accomplishing this is to restrict a transmitter’s coverage area. This problem uses a shielded transmitter that only broadcasts in a semicircle. A transmitter T is located somewhere on a 1,000 square meter grid. It broadcasts in a semicircular area of radius r. The transmitter may be rotated any amount, but not moved. Given N points anywhere on the grid, compute the maximum number of points that can be simultaneously reached by the transmitter’s signal. Figure 1 shows the same data points with two different transmitter rotations.