[思維]CodeForces 135B

題意:
給出8個點,問能否分成兩個集合,使得一個組成正方形,另一個組成矩形。如果能,就輸出YES,並且輸出兩個集合分別是什麼,如果能,那就直接輸出NO;

分析:
本來覺得這題很煩,沒什麼興趣做了,瀏覽status的時候,偶然發現某final爺的id,點進去亮瞎了雙眼。。。代碼精簡美觀,思路一樣很暴力,但是暴力的漂亮,於是乎學習了一下。
思路就是判斷所有的邊的可能排列,然後根據邊判斷,不用什麼點積來做了。親測正常點的做法起碼要100++,細節錯誤的話還容易WA。這樣暴力的話就不用煩惱這些了。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#define read freopen("q.in","r",stdin)
#define LL long long
#define maxn 1000005
using namespace std;
int p[]={0,1,2,3,4,5,6,7,8};
int x[9],y[9];
int d(int a,int b)
{
    return (x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]);
}
int main()
{
   // read;
    int i,j;
    for(i=1;i<=8;i++)scanf("%d%d",&x[i],&y[i]);

    do
    {
        if(d(p[1],p[2])==d(p[2],p[3]) && d(p[2],p[3])==d(p[3],p[4]) && d(p[3],p[4])==d(p[4],p[1]) && d(p[1],p[3])==d(p[4],p[2])
           && d(p[5],p[6])==d(p[7],p[8]) && d(p[5],p[8])==d(p[6],p[7]) && d(p[5],p[7])==d(p[6],p[8]))
           {
               return printf("YES\n%d %d %d %d\n%d %d %d %d\n",p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8]),0;
           }
    }while(next_permutation(p+1,p+9));
    puts("NO");
    return 0;




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