F. 正方形计数

F. 正方形计数

解题思路:枚举两个点为一条线段,以这条线段为对角线,求出另为两个点,判断条件有没有给出。答案要除2,因为有重复的。

正方形,已知 (x0,y0) 和(x2,y2) 可以根据下列关系求(x1,y1),(x3,y3)
x1+x3 = x0+x2;
x1-x3 = y2-y0;
y1+y3 = y0+y2;
y1-y3 = x0-x2;

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lf;
typedef unsigned long long ull;
typedef pair<double,double>P;
const int inf = 0x7f7f7f7f;
const ll INF = 1e16;
const int N = 1e3+10;
const ll mod =  998244353;
const double PI = acos(-1.0);
const double eps = 1e-4;

inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
inline string readstring(){string str;char s=getchar();while(s==' '||s=='\n'||s=='\r'){s=getchar();}while(s!=' '&&s!='\n'&&s!='\r'){str+=s;s=getchar();}return str;}
int random(int n){return (int)(rand()*rand())%n;}
void writestring(string s){int n = s.size();for(int i = 0;i < n;i++){printf("%c",s[i]);}}





double x[N],y[N];
map<P,int>vis;

int main(){
    srand((unsigned)time(NULL));
    int n = read();
    for(int i = 1;i <= n;i++){
        x[i] = read();
        y[i] = read();
        vis[P(x[i],y[i])] = 1;
    }
    int ans = 0;
    for(int i = 1;i <= n;i++){
        for(int j = i+1;j <= n;j++){
            double x1 = (x[i]+x[j]+y[j]-y[i])/2.0;
            double x3 = x[i]+x[j]-x1;
            double y1 = (y[i]+y[j]+x[i]-x[j])/2.0;
            double y3 = y[i]+y[j]-y1;
            if(vis[P(x1,y1)]&&vis[P(x3,y3)]){
                ans++;
            }
        }
    }
    cout<<ans/2<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_42868863/article/details/114002921