hdu 5365 Run(BC 50 B題)(求四邊形的個數),hdu5365

來源:互聯網
上載者:User

hdu 5365 Run(BC 50 B題)(求四邊形的個數),hdu5365

本來準備睡覺,結果還是忍不住想把它A了,因為已經看了題解了,

題意:就是給你一些座標,都是整數,求一些正多邊形的數目,官方題解說是地球人都知道整數座標構不成正三角形,正五邊形和正六邊形的。。。然而我並不知道。。。以後才知道。。。

所以呢這道題直接暴力就可以了,求正四邊形的個數,這裡判斷是否是正四邊形用的是四條邊相等,而且兩條對角線相等,並且邊比對角線小,我也不知道是否這樣一定是正四邊形(。。。)

放代碼:

#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<vector>#include<set>#include<string>#include<algorithm>using namespace std;int solve(int a,int b,int c,int d){return (a-c)*(a-c)+(b-d)*(b-d);}int cmp(const void *a,const void *b){return *(int *)a - *(int *)b;}int main(){int n,i,j,k,p;int a[25],b[25],c[25];while(cin >> n){for(i=1; i<=n; i++)cin >> a[i] >> b[i];int ans = 0;for(i=1; i<=n; i++)for(j=i+1; j<=n; j++)for(k=j+1; k<=n; k++)for(p=k+1; p<=n; p++){c[0] = solve(a[i],b[i],a[k],b[k]);c[1] = solve(a[i],b[i],a[j],b[j]);c[2] = solve(a[i],b[i],a[p],b[p]);c[3] = solve(a[j],b[j],a[k],b[k]);c[4] = solve(a[j],b[j],a[p],b[p]);c[5] = solve(a[k],b[k],a[p],b[p]);qsort(c,6,sizeof(c[0]),cmp);if(c[0]==c[1]&&c[1]==c[2]&&c[2]==c[3]&&c[4]==c[5])ans++;}cout << ans << endl;} return 0;}


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.