• HDU 6055


    题意略。

    思路:要你找出所有正多边形,其实是唬人的,整点的正多边形只有正方形,具体证明可以参考     2017国家队论文集-《正多边形》-杨景钦

    详见代码:

    #include<bits/stdc++.h>
    #define maxn 505
    //#define LOCAL
    using namespace std;
    
    struct Point{
        int x,y;
        Point(int a = 0,int b = 0){
            x = a,y = b;
        }
        Point operator+ (const Point& p){
            return Point(x + p.x,y + p.y);
        }
        Point operator- (const Point& p){
            return Point(x - p.x,y - p.y);
        }
        bool operator== (const Point& p) const{
            return x == p.x && y == p.y;
        }
        bool operator< (const Point& p) const{
            if(x != p.x) return x < p.x;
            return y < p.y;
        }
    };
    
    struct line{
        Point s,t;
        line(){}
        line(Point a,Point b){
            s = a,t = b;
        }
        bool operator< (const line& l) const{
            if(!(s == l.s)) return s < l.s;
            return t < l.t;
        }
    };
    
    set<line> st;
    Point store[maxn * maxn];
    
    int main(){
        #ifdef LOCAL
        freopen("kkk.txt","r",stdin);
        freopen("kkkout.txt","w",stdout);
        #endif
        int n;
        while(scanf("%d",&n) == 1){
            st.clear();
            for(int i = 0;i < n;++i)
                scanf("%d%d",&store[i].x,&store[i].y);
            sort(store,store + n);
            for(int i = 0;i < n;++i){
                for(int j = i + 1;j < n;++j){
                    st.insert(line(store[i],store[j]));
                }
            }
            int ans = 0;
            for(int i = 0;i < n;++i){
                for(int j = i + 1;j < n;++j){
                    Point d = store[j] - store[i];
                    Point temp(d.y,-d.x);
                    Point s = store[i] + temp;
                    Point t = s + d;
                    if(st.count(line(s,t))) ++ans;
                }
            }
            printf("%d
    ",ans / 2);
        }
        return 0;
    }
  • 相关阅读:
    UVa 10010 Where's Waldorf?
    boost 学习笔记
    C++ enum类型的一个更好的用法
    新浪面试题:删除字符串中多余的空格
    微软面试题:写程序找出二叉树的深度
    c++中sizeof的分析
    复习计划
    boost学习之 时间和日期 timer
    c++ template学习总结3
    微软面试题:反序一个单向链表
  • 原文地址:https://www.cnblogs.com/tiberius/p/8613143.html
Copyright © 2020-2023  润新知