#include <cstring>
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

const int N = 100;

int t, n;
string codes[N], ips[N];
int arr[N][128];

int calc( int a, int b ) {
	if( ips[a] != ips[b] )
		return 0;
	int result = 0;
	for( int i = 0; i < 128; i ++ )
		result += min(arr[a][i], arr[b][i]);
	return result;
}

int main() {
	freopen("cheaters.in", "r", stdin);
	freopen("cheaters.out", "w", stdout);
	for( cin >> t; t--; ) {
		cin >> n;
		for( int i = 0; i < n; i ++ )
			cin >> ips[i] >> codes[i];
		for( int i = 0; i < n; i ++ ) {
			for( int j = 0; j < 128; j ++ )
				arr[i][j] = 0;
			for( int j = 0; j < codes[i].length(); j ++ )
				arr[i][codes[i][j]] ++;
		}
		int a = -1, b = -1, r = -1, c = 0;
		for( int i = 0; i < n; i ++ )
			for( int j = i + 1; j < n; j ++ ) {
				int t = calc( i, j );
				if( t == r )
					c ++;
				else if( t > r ) {
					r = t;
					c = 1;
					a = i + 1;
					b = j + 1;
				}
			}
		if( c > 1 ) 
			cout << "Impossible" << endl;
		else
			cout << a << " " << b << endl;
	}
	return 0;
}

 
implementation/iaumc3_cheaters.txt · Last modified: 2009/07/19 12:57 by hadi
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki