↓ 跳过正文
  1. Posts/

bzoj 1610 [Usaco2008 Feb]Line连线游戏 (计算几何)

·492 字·1 分钟

http://www.lydsy.com/JudgeOnline/problem.php?id=1610 题意:给出n个点,问有多少条直线,这些之间之间都不平行。 思路:求斜率(注意考虑斜率不存在),看有多少种斜率。 妈蛋。。。。斜率不存在是横坐标相等啊,不是纵坐标啊。。。蠢哭了好么。。。。。。

妈蛋。。。。斜率不存在是横坐标相等啊,不是纵坐标啊。。。蠢哭了好么。。。。。。

妈蛋。。。。斜率不存在是横坐标相等啊,不是纵坐标啊。。。蠢哭了好么。。。。。。

太他妈惨了。。。。

null
代码实现
 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年02月28日 星期日 01时34分35秒
 4File Name :code/bzoj/1610.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=205;
34const double oo=1897987987;
35struct node
36{
37    double x,y;
38
39
40    double getk(node b)
41    {
42	return (y-b.y)/(x-b.x);
43    }
44
45
46}p[N];
47double k[40005];
48int n;
49
50
51int dblcmp(double d)
52{
53    return d<-eps?-1:d>eps;
54}
55int main()
56{
57	#ifndef  ONLINE_JUDGE
58	freopen("code/in.txt","r",stdin);
59  #endif
60
61	ios::sync_with_stdio(false);
62	cin>>n;
63	for ( int i = 1 ; i <= n ; i++)
64	{
65	    cin>>p[i].x>>p[i].y;
66	}
67
68	int cnt = 0 ;
69	for ( int i = 1 ; i <= n-1  ;i++)
70	{
71	    for ( int j = i+1 ; j <= n ; j++)
72	    {
73		++cnt;
74	//	cout<<"i:"<<i<<" p[i].y:"<<p[i].y<<" j:"<<j<<" p[j].y:"<<p[j].y<<endl;
75		if (dblcmp(p[i].x-p[j].x)==0) k[cnt]=oo;
76		else k[cnt] = p[i].getk(p[j]);
77	    }
78	}
79
80	//check k
81//	for ( int i = 1 ; i <= cnt ; i++) cout<<k[i]<<endl;
82	sort(k+1,k+cnt+1);
83
84	int ans = 0 ;
85	for ( int i = 1 ; i <= cnt ; i++)
86	{
87	    if (i==1||dblcmp(k[i]-k[i-1])!=0) ans++;
88	}
89
90	cout<<ans<<endl;
91
92
93
94  #ifndef ONLINE_JUDGE
95  fclose(stdin);
96  #endif
97    return 0;
98}

相关文章

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 需要注意的是:最大距离一定是从某点上取得,但是最小距离可能不在顶点上,而在某条边上。

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.