Two Triangles FZU - 2270 (计算几何,叉积判断对称)

Two Triangles

FZU - 2270

Fat brother and Maze are playing a kind of special (hentai) game with some points in a two-dimensional plane. First Fat Brother would choose three different points and then Maze would choose other three different points. If both of the player’s points form a triangle, they would feel happy. Also, if these two triangles are exactly the same, they would feel even happier. The two triangles are considered the same if one can be changed from another by translation and rotation.

Now given N points in a plane, Fat Brother would like to know how many different sets of points they can choose in order to make them even happier.


Input

The first line of the data is an integer T (1 <= T <= 100), which is the number of the text cases.

Then T cases follow, each case contains an integer N (6 <= N <= 10) indicated the number of the points in the two-dimensional plane. The N lines follow, each line contains two integers x and y (0 <= x, y <= 10) shows this point’s coordinate. All the points have different coordinate in this plane.

Output

For each case, output the case number first, and then output the number of the different sets of points they can choose in order to make them even happier.

Sample Input
3
6
0 0
2 0
2 1
8 8
10 8
10 9
6
0 0
2 0
2 1
8 8
10 8
10 7
6
0 0
1 0
2 0
0 1
1 1
2 1
Sample Output
Case 1: 2
Case 2: 0
Case 3: 6
Hint

In the first case, Fat Brother can choose a set which contains first three points and Maze can choose a set which contains last three points, this makes a suitable answer. Also, Fat Brother and Maze can change the set they choose and still make a solid result.

要求两个三角形可以通过平移和旋转完全重合


所以首先要是三角形即三点不能共线,其次要全等,即三条边对应相等,最后判断是否对称,如果对称无论如何旋转都无法重合

所以利用叉积选好对应边,如果两个叉积互为相反数,则说明对称否则可以重合,这里注意一种特殊情况,等边三角形要提前判断,因为等边三角形不需要判断叉积只要全等一定可以通过旋转平移重合

直接暴力枚举六个不同的点即可

code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int book[15];
struct Node{
    int x,y;
}node[15];
int va[5],vb[5];
int cross(int a,int b,int c){
    return (node[b].x - node[a].x) * (node[c].y - node[a].y) - (node[c].x - node[a].x) * (node[b].y - node[a].y);
}
bool solve2(int a1,int b1,int c1,int a2,int b2,int c2){
    int sum1 = cross(a1,b1,c1);
    int sum2 = cross(a2,b2,c2);
//    if(sum1 == 0 || sum2 == 0)//三点共线
//        return false;
    if(sum1 + sum2 == 0)
        return false;
    return true;
}
bool solve3(int a1,int b1,int c1,int a2,int b2,int c2){
    int sum1 = cross(a1,b1,c1);
    int sum2 = cross(a2,b2,c2);
    if(sum1 == 0 || sum2 == 0)//三点共线
        return false;
    return true;
}
int dist(int n1,int n2){
    return (node[n2].x - node[n1].x) * (node[n2].x - node[n1].x) + (node[n2].y - node[n1].y) * (node[n2].y - node[n1].y);
}
int main(){
    int t,cas = 0;
    scanf("%d",&t);
    while(t--){
       memset(book,0,sizeof(book));
       int ans = 0;
       int n;
       scanf("%d",&n);
       for(int i = 0; i < n; i++){
          scanf("%d%d",&node[i].x,&node[i].y);
       }
       int a1,b1,c1,a2,b2,c2;
       for(a1 = 0; a1 < n; a1++){
          if(book[a1] == 1)
            continue;
          book[a1] = 1;
          for(b1 = a1+1; b1 < n; b1++){
             if(book[b1] == 1)
                continue;
             book[b1] = 1;
             for(c1 = b1+1; c1 < n; c1++){
                if(book[c1] == 1)
                    continue;
                book[c1] = 1;
                for(a2 = 0; a2 < n; a2++){
                   if(book[a2] == 1)
                     continue;
                   book[a2] = 1;
                   for(b2 = a2+1; b2 < n; b2++){
                      if(book[b2] == 1)
                        continue;
                      book[b2] = 1;
                      for(c2 = b2+1; c2 < n; c2++){
                         if(book[c2] == 1)
                           continue;
                         va[0] = dist(a1,b1);
                         va[1] = dist(a1,c1);
                         va[2] = dist(b1,c1);
                         vb[0] = dist(a2,b2);
                         vb[1] = dist(a2,c2);
                         vb[2] = dist(b2,c2);
                         sort(va,va+3);
                         sort(vb,vb+3);
                         if(!(va[0] == vb[0] && va[1] == vb[1] && va[2] == vb[2]))//三边不相等
                            continue;
                         if(!solve3(a1,b1,c1,a2,b2,c2))//三点共线
                            continue;
                         if(va[0] == va[1] || va[0] == va[2] || va[1] == va[2])
                            ans++;
                         else{
                            va[0] = dist(a1,b1);
                            va[1] = dist(a1,c1);
                            va[2] = dist(b1,c1);
                            vb[0] = dist(a2,b2);
                            vb[1] = dist(a2,c2);
                            vb[2] = dist(b2,c2);
                            int bb[3];
                            int p;
                            for(p = 0; p < 3; p++){
                                if(vb[p] == va[0])
                                    break;
                            }
                            if(p == 0)
                                bb[0] = c2;
                            else if(p == 1)
                                bb[0] = b2;
                            else
                                bb[0] = a2;
                            for(p = 0; p < 3; p++){
                                if(vb[p] == va[1])
                                    break;
                            }
                            if(p == 0)
                                bb[1] = c2;
                            else if(p == 1)
                                bb[1] = b2;
                            else
                                bb[1] = a2;
                            for(p = 0; p < 3; p++){
                                if(vb[p] == va[2])
                                    break;
                            }
                            if(p == 0)
                                bb[2] = c2;
                            else if(p == 1)
                                bb[2] = b2;
                            else
                                bb[2] = a2;
                            if(solve2(c1,b1,a1,bb[0],bb[1],bb[2]))
                                ans++;
                         }
                      }
                      book[b2] = 0;
                   }
                   book[a2] = 0;
                }
                book[c1] = 0;
             }
             book[b1] = 0;
          }
          book[a1] = 0;
       }
       printf("Case %d: %d\n",++cas,ans);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值