Problem:
Problem B:
Polygonal Line Search
Multiple polygonal lines are given on the
xy
-plane.
Given a list of polygonal lines and a template,
you must find out polygonal lines
which have the same shape as the template.
A polygonal line consists of several line segments parallel to
x
-axis or
y
-axis.  It is defined by a list of
xy
-coordinates of vertices from the start-point to the end-point in order,
and always turns 90 degrees at each vertex.
A single polygonal line does not pass the same point twice.



Two polygonal lines  have the same shape when they
fully overlap each other only with rotation and translation
within
xy
-plane (i.e. without magnification or a flip).
The vertices given in reverse order from the start-point to the end-point is the
same as that given in order.
Figure 1 shows examples of polygonal lines.
In this figure, polygonal lines A and B have the same shape.
Write a program that answers polygonal lines which have the same shape  as
the template.
Figure 1: Polygonal lines
Input
The input consists of multiple datasets.
The end of the input is indicated by a line which contains a zero.
A dataset is given as follows.
n
Polygonal line
0
Polygonal line
1
Polygonal line
2
...
Polygonal line
n
n
is the number of polygonal lines for the object of search on
xy
-plane.
n
is an integer, and  1 <=
n
<= 50.
Polygonal line
0
indicates the template.
A polygonal line is given as follows.
m
x
1
y
1
x
2
y
2
...
x
m
y
m
m
is the number of the vertices of a polygonal line (3 <=
m
<= 10).
x
i
and
y
i
, separated by a space,
are the
x
- and
y
-coordinates
 of a vertex, respectively (-10000 <
x
i
< 10000, -10000 <
y
i
< 10000).
Output
For each dataset in the input, your program should report numbers assigned to the polygonal lines that have the same shape as the template, in ascending order.
Each number must be written in a separate line without any other characters such as leading or trailing spaces.
Five continuous "+"s must be placed in a line at the end of each dataset.
Sample Input
5
5
0 0
2 0
2 1
4 1
4 0
5
0 0
0 2
-1 2
-1 4
0 4
5
0 0
0 1
-2 1
-2 2
0 2
5
0 0
0 -1
2 -1
2 0
4 0
5
0 0
2 0
2 -1
4 -1
4 0
5
0 0
2 0
2 1
4 1
4 0
4
4
-60 -75
-60 -78
-42 -78
-42 -6
4
10 3
10 7
-4 7
-4 40
4
-74 66
-74 63
-92 63
-92 135
4
-12 22
-12 25
-30 25
-30 -47
4
12 -22
12 -25
30 -25
30 47
3
5
-8 5
-8 2
0 2
0 4
8 4
5
-3 -1
0 -1
0 7
-2 7
-2 16
5
-1 6
-1 3
7 3
7 5
16 5
5
0 1
0 -2
8 -2
8 0
17 0
0
Output for the Sample Input
1
3
5
+++++
3
4
+++++
+++++

Submitted solutions:

code_snippet: #include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T>inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void init() {

}

using matrix = vector<vector<int>>;
matrix makeRotationMatrix(double theta) {
    matrix res(3, vector<int>(3, 0));
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            res[i][j] = (i == j ? cos(theta) : i ? sin(theta) : -sin(theta));
        }
    }
    res[2][2] = 1;
    return res;
}

matrix mul(matrix A, matrix B) {
    matrix res(A.size(), vector<int>(B.front().size(), 0));
    for (int i = 0; i < A.size(); i++) {
        for (int k = 0; k < B.size(); k++) {
            for (int j = 0; j < B.front().size(); j++) {
                res[i][j] += A[i][k] * B[k][j];
            }
        }
    }
    return res;
}

void solve(int n) {
    int m;
    scanf("%d", &m);
    vector<vector<pair<int, int>>> keyvec(2, vector<pair<int, int>>(m));
    for (int i = 0; i < m; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        keyvec[0][i] = make_pair(x, y);
        keyvec[1][i] = make_pair(x, y);
    }
    reverse(begin(keyvec[1]), end(keyvec[1]));
    for (int c = 0; c < 2; c++) {
        int X, Y;
        tie(X, Y) = keyvec[c][0];
        for (int i = 1; i < m; i++) {
            int x, y;
            tie(x, y) = keyvec[c][i];
            keyvec[c][i] = make_pair(x - X, y - Y);
        }
        keyvec[c][0] = make_pair(0, 0);
    }

    vector<vector<pair<int, int>>> vec(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &m);
        vec[i].resize(m);
        for (int j = 0; j < m; j++) {
            int x, y;
            scanf("%d%d", &x, &y);
            if (j == 0) vec[i][j] = make_pair(x, y);
            else vec[i][j] = make_pair(x - vec[i][0].first, y - vec[i][0].second);
        }
        vec[i][0] = make_pair(0, 0);
    }

    const long double PI = acos(-1.0);
    const long double theta[] = {0, PI / 2, PI, PI * 1.5};
    set<int> ans;
    for (int c = 0; c < 2; c++) {
        for (int i = 0; i < n; i++) {
            for (auto e : theta) {
                auto cpvec = vec[i];
                auto rotmat = makeRotationMatrix(e);
                for (int j = 0; j < (int)cpvec.size(); j++) {
                    matrix mat(3);
                    mat[0].emplace_back(cpvec[j].first);
                    mat[1].emplace_back(cpvec[j].second);
                    mat[2].emplace_back(1);
                    mat = mul(rotmat, mat);
                    cpvec[j] = make_pair(mat[0][0], mat[1][0]);
                }
                if (cpvec == keyvec[c]) {
                    ans.insert(i);
                }
            }
        }
    }

    for (int e : ans) {
        printf("%d\n", e + 1);
    }
    puts("+++++");
}

int main(void) {
	int a, b, c, x, y, z, n, m, p;
	string s;
	while (cin >> n, n) {
		solve(n);
		//break;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3500
final_rank: 2

code_snippet: #include<iostream>
#include<cstring>
using namespace std;

#define MAX_N 1355

int x[MAX_N][4], y[MAX_N][4];
int X[MAX_N][MAX_N], Y[MAX_N][MAX_N];
int n, m, M ,cnt;

int main() {
	while (true) {
		if (cnt >= 1) { cout << "+++++" << endl; }
		cnt++;
		memset(x, 0, sizeof(x));
		memset(y, 0, sizeof(y));
		memset(X, 0, sizeof(X));
		memset(Y, 0, sizeof(Y));
		cin >> n;
		if (n == 0) { break; }
		cin >> M;
		for (int i = 0; i < M; i++) {
			cin >> x[i][0] >> y[i][0];
		}
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < M; j++) {
				x[j][i + 1] = -y[j][i];
				y[j][i + 1] = x[j][i];
			}
		}
		for (int i = 1; i <= n; i++) {
			cin >> m;
			for (int j = 0; j < m; j++) {
				cin >> X[i][j] >> Y[i][j];
			}
			int same = 8;
			if (M != m) { same = 0; }
			else {
				for (int j = 0; j < 4; j++) {
					int X1 = x[0][j] - X[i][0], Y1 = y[0][j] - Y[i][0];
					for (int k = 1; k < M; k++) {
						if ((x[k][j] - X[i][k] != X1 || y[k][j] - Y[i][k] != Y1) && same == 8 - j) {
							same--;
						}
					}
				}
				for (int j = 0; j < 4; j++) {
					int X1 = x[0][j] - X[i][M - 1], Y1 = y[0][j] - Y[i][M - 1];
					for (int k = 1; k < M; k++) {
						if ((x[k][j] - X[i][M - 1 - k] != X1 || y[k][j] - Y[i][M - 1 - k] != Y1) && same == 4 - j) {
							same--;
						}
					}
				}
			}
			if (same >= 1) { cout << i << endl; }
		}
	}
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 15552
final_rank: 3

code_snippet: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 1LL<<50

void turn(vector<vector<pii> > &line , vector<pii> p){
    line.pb(p);
    vector<pii> tmp;
    rep(i,p.size()){
        tmp.pb(pii( p[i].first*-1 , p[i].second*-1 ));
    }
    line.pb(tmp);
    tmp.clear();

    
    rep(i,p.size()){
        tmp.pb(pii( p[i].second*-1 , p[i].first ));
    }
    line.pb(tmp);
    tmp.clear();

    
    rep(i,p.size()){
        tmp.pb(pii( p[i].second , p[i].first*-1 ));
    }
    line.pb(tmp);
    tmp.clear();
}


void pre(vector<vector<pii> > &line , vector<pii> p){
    int y,x;
    y=p[0].first,x=p[0].second;
    vector<pii> tmp;
    rep(i,p.size())tmp.pb(pii( p[i].first-y , p[i].second-x ));
    turn(line,tmp);

    reverse(all(p));
    y=p[0].first,x=p[0].second;
    tmp.clear();
    rep(i,p.size())tmp.pb(pii( p[i].first-y , p[i].second-x ));
    turn(line,tmp);
}

bool same(vector<pii> line,vector<pii> a){
    if(a.size()!=line.size())return false;
    rep(i,a.size()){
        if(line[i].first!=a[i].first)return false;
        if(line[i].second!=a[i].second)return false;
    }
    return true;
}

bool is(vector<vector<pii> > line , int t){
    for(int i=t*8;i<t*8+8;i++){
        if(same(line[i],line[0])){
            return true;
        }
    }
    return false;
}


int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        vector<vector<pii> > line;
        rep(i,n+1){
            int m;
            cin>>m;
            vector<pii> tmp;
            rep(j,m){
                int x,y;
                cin>>x>>y;
                tmp.pb(pii(y,x));
            }
            pre(line,tmp);
        }
        
        for(int i=1;i<n+1;i++){
            if(is(line,i)){
                cout<<i<<endl;
            }
        }
        cout<<"+++++"<<endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 1300
final_rank: 1