HDU 5365(计算几何)

Run

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 101    Accepted Submission(s): 43

Problem Description

AFA is a girl who like runing.Today,he download an app about runing .The app can record the trace of her runing.AFA will start runing in the park.There are many chairs in the park,and AFA will start his runing in a chair and end in this chair.Between two chairs,she running in a line.she want the the trace can be a regular triangle or a square or a regular pentagon or a regular hexagon.
Please tell her how many ways can her find.
Two ways are same if the set of chair that they contains are same.

Input

There are multiply case.
In each case,there is a integer n(1 < = n < = 20)in a line.
In next n lines,there are two integers xi,yi(0 < = xi,yi < 9) in each line.

Output

Output the number of ways.

Sample Input

4
0 0
0 1
1 0
1 1

Sample Output

1

虽然题目很简单,我还是来个通用的代码吧

#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <bitset>
#include <sstream>
#include <cstdlib>
#include <complex>
#include <climits>
#include <cstring>
#include <iostream>
#include <algorithm>

#define REP(i,N) for (int i = 0;i < (N);i++)
#define REP_1(i,N) for (int i = 1;i < (N);i++)
#define REP_2(i,be,en) for (int i = (be);i < (en);i++)
#define DWN(i,N) for (int i = (N);i >= 0;i--)
#define DWN_1(i,N) for (int i = (N);i >= 1;i--)
#define DWN_2(i,en,be) for (int i = (en);i >= (be);i--)
#define FR(N) freopen((N),"r",stdin)
#define FW(N) freopen((N),"w",stdout)
#define SO(N) scanf("%d",&(N))
#define STO(N,M) scanf("%d %d",&(N),&(M))
#define STH(N,M,K) scanf("%d %d %d",&(N),&(M),&(K))
#define PS(N) printf("%d",(int)(N));
#define MAXN 2010
#define GETS(ch) fgets((ch),MAXN,stdin)
#define INF 0x3f3f3f3f
#define MOD 1000000007
using namespace std;

typedef long long LL;
typedef LL ll;
typedef map<int,LL> MINT;
typedef map<char,int> MCH;
typedef map<string,int> MSTR;

typedef vector<int> VINT;
typedef set<LL> SINT;
typedef pair<int,int> PINT;

LL read(){
    LL ret=0,f=1;
    char x=getchar();
    while(!(x>=‘0‘ && x<=‘9‘)){if(x==‘-‘)f=-1;x=getchar();}
    while(x>=‘0‘ && x<=‘9‘) ret=ret*10+x-‘0‘, x=getchar();
    return ret*f;
}

class point {
public:
    int x,y;
}node[30];
point List[5];

int cross(point p0,point p1,point p2) //计算叉积  p0p1 X p0p2
{
    return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);
}
double dis(point p1,point p2)  //计算 p1p2的 距离
{
    return sqrt((double)(p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));
}
bool cmp(point p1,point p2) //极角排序函数 , 角度相同则距离小的在前面
{
    int tmp=cross(List[0],p1,p2);
    if(tmp>0) return true;
    else if(tmp==0&&dis(List[0],p1)<dis(List[0],p2)) return true;
    else return false;
}

int cross2(point p0,point p1,point p2) //计算点积  p0p1 · p1p2
{
    return (p1.x-p0.x)*(p2.x-p1.x)+(p1.y-p0.y)*(p2.y-p1.y);
}

int ans = 0;
int work(vector<int> V) {
    int len = V.size();
    for (int i = 1;i < len;i++) {
        if (node[V[i]].x < node[V[0]].x) {
            swap(V[i],V[0]);
        }
        else if (node[V[i]].x == node[V[0]].x) {
            if (node[V[i]].y < node[V[0]].y) {
                swap(V[i],V[0]);
            }
        }
    }
    for (int i = 0;i < len;i++) {
        List[i] = node[V[i]];
    }
    sort(List,List + len,cmp);
    for (int i = 0;i < len - 1;i++) {
        if (dis(List[i],List[i + 1]) - dis(List[i + 1],List[(i + 2) % len]) > 1e-6) return 0;
        if (cross2(List[(i + len - 1) % len],List[i],List[i + 1]) != 0) return 0;
    }

    return 1;
}
int N;

void dfs(int u,int pos,vector<int> V,int num) {
    if (pos == num) {
        ans += work(V);
        return;
    }
    if (u >= N) return;
    V.push_back(u);
    dfs(u + 1,pos + 1,V,num);
    V.pop_back();
    dfs(u + 1,pos,V,num);
}

int main() {
    while (cin >> N) {
        for (int i = 0;i < N;i++) {
            cin >> node[i].x >> node[i].y;
        }
        vector<int> V;
        V.clear();
        ans = 0;
        dfs(0,0,V,4); // 只能形成4边形
        cout << ans << endl;
    }
}

  

时间: 2024-08-06 16:04:31

HDU 5365(计算几何)的相关文章

hdu 1616 计算几何 凸包

题意是一个世界有许多个国家,每个国家有N个建筑,包括一个发电站和N-1个用电建筑,所有建筑围成的凸包就是这个国家的面积.一枚导弹如果在一个国家之内爆炸则可以使这个国家停电. step 1:求出每个国家的凸包(我用水平排序就是各种坑,改叉乘排序才过,主要是后面求面积的时候需要这个叉乘排序的信息). step 2:判断每枚导弹是否在这个国家的范围之内. step 3:求出所有停电的国家的面积. 就是计算几何的综合模拟水题,坑点就是要小心(QAQ||写计算几何的题目都是要小心). 传送门:http:/

BestCoder Round #50 (div.2) HDU 5365 Run(简单几何)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5365 题面:(严重吐槽,看着真不舒服,还是改一下吧) Run Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 549    Accepted Submission(s): 245 Problem Description AFA is a g

hdu 3320 计算几何(三维图形几何变换)

openGL Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 170    Accepted Submission(s): 77 Problem Description Jiaoshou selected a course about “openGL” this semester. He was quite interested in m

hdu 5365+hdu 5355

5365 题目链接:点击打开链接 题目大意:给定一些整数点,问这些点能够组成多少个正三角形或者是正方形.正五边形.正六边形. 思路:如果仔细想一想的话,这道题目是根本不存在正三角形.正五边形.正六边形的请款的.(在纸上画图看一看,可以发现确实不行.题目输入是整数点) 所以题目变成:这些点能够组成多少个正方形.看数据范围,n<=20,坐标范围<=8. 题目瞬间简单了,暴力!暴力枚举4个点,然后判断这4个点是否能组成一个正方形.判断是否为正方形的方法很多,向量或者是距离. 我这里用的是算出4个点的

HDU 5784 (计算几何)

Problem How Many Triangles (HDU 5784) 题目大意 给定平面上的n个点(n<2000),询问可以组成多少个锐角三角形. 解题分析 直接统计锐角三角形较困难,考虑问题的反面,统计直角三角形.钝角三角形.平角三角形(暂时这么叫吧QAQ). 首先枚举三角形的一个端点A,对其他点进行象限为第一关键字,极角为第二关键字排序. 然后使用三个指针,进行O(n)的扫描. 具体做法为用 i 指针指向三角形的第二个端点B.我们可以假想通过平移和旋转,把A点置于平面直角坐标系的原点,

2017-03-18 HDU 5733 计算几何 codeforces 599E 状压dp(待补)

HDU 5733 题意:给出四面体的四个顶点,求出其内切球的球心坐标和半径,如果不存在内切球,输出"O O O O". tags:一堆公式..可以做模板了 我们可以将平面上的四点得到由同一个点出发的三个矢量.这样就可以计算这三个矢量的混合积M,则M/6即为四面体体积V. 题目无解的情况当且仅当四点共面,即混合积为0. 求得四面体体积后,可以根据公式r = 3V/(S1+S2+S3+S4)得到内切球半径, S1~S4为四面体四个面的面积. 当前的问题转化为如何求四面体四个面的面积. 由于

HDU 5365 Run(大水题)

大致题意: 8*8的整点格子,输入16个整点,求多少种点的集合可以组成正3,正4,5,6边形 思路:sb题啊...整点格子组成不了n !=4的所有正多边形,只要判是否能组成正方形就可以了 这里有个优美的无穷递降的证明:http://www.zhihu.com/question/25304120 而我是枚举所有点的集合判断是否能组成正多边形的蠢方法= =,先用凸包对点排个序,然后判各点距离相等和用余弦定理判个顶角相等..... //#pragma comment(linker, "/STACK:1

hdu 1558(计算几何+并查集)

Segment set Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4479    Accepted Submission(s): 1672 Problem Description A segment and all segments which are connected with it compose a segment set.

hdu 5365 Run(BC 50 B题)(求四边形的个数)

本来准备睡觉,结果还是忍不住想把它A了,因为已经看了题解了, 题意:就是给你一些坐标,都是整数,求一些正多边形的数目,官方题解说是地球人都知道整数坐标构不成正三角形,正五边形和正六边形的...然而我并不知道...以后才知道... 所以呢这道题直接暴力就可以了,求正四边形的个数,这里判断是否是正四边形用的是四条边相等,而且两条对角线相等,并且边比对角线小,我也不知道是否这样一定是正四边形(...) 放代码: #include<iostream> #include<cstdio> #i