#NOIP模擬賽#多邊形Polygon(枚舉 + 模擬)








Code:算法一實現(慢死)

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

const double eps = 1e-6;

struct node{
    int x, y, dis;
    node(){}
    node(int a, int b, int c){  x = a, y = b, dis = c;}
}P[20500];

int L, cnt;

int abs(int x){ return x < 0 ? -x : x;}

void Pre_Work(){
    int up = L / 2, tmp;
    for(int i = 1; i <= L; ++ i)
        for(int j = 0; i * i + j * j <= up * up; ++ j){
            int d = sqrt(tmp = i * i + j * j);
            if(d * d == tmp)
                P[++ cnt] = node(i, j, d);
        }
}

bool Check(int a, int b){
    return P[a].x * P[b].y - P[a].y * P[b].x;
}

int main(){
    freopen("polygon.in", "r", stdin);
    freopen("polygon.out", "w", stdout);
    scanf("%d", &L);
    if(L & 1 || L == 2)   {printf("-1.000000\n"); return 0;}
    Pre_Work();
    int tmp, d, Ans = 0x3f3f3f3f;
    for(int i = 1; i <= cnt; ++ i)
        for(int j = i + 1; j <= cnt; ++ j){
            d = sqrt(tmp = (P[i].x - P[j].x) * (P[i].x - P[j].x) + (P[i].y - P[j].y) * (P[i].y - P[j].y));
            if(d * d == tmp && Check(i, j) && d + P[i].dis + P[j].dis == L)
                Ans = min(Ans, max(abs(d - P[i].dis), max(abs(P[i].dis - P[j].dis), abs(P[j].dis - d))));
        }
    if(Ans != 0x3f3f3f3f)
        printf("%d.000000\n", Ans);
    else printf("%d.000000\n", (L / 2) & 1);
    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章