UVa 10132 File Frangentation(考え方問題)

3412 ワード

10132-File Frangentation
Time limit:3.000 seconds 
http://uva.onlinejudge.org/index.php?option=com_オンラインjudge&Itemid=8&category=113&page=show_problem&problem=1073
Your friend、a biochemistry major、tripped while carrying a try of computter files through the lab.All of the files fell to the ground and brook.Your friend picked up all the file frame and carement the the put
Fortunatery,all of the files on the trany were dentical,all of them brook e in to exactly two fragments,and all of the file franges wers.Unfortunally,the files dn din'all break the same the france the france
You've translated the original binary frangemens of ASCII 1's and 0's,and you're planing to write a program to determine the bit pattern the files contained.
Input
The input begins with a single positive integer on a line by itself indicating the number of the cases follwing,each of the m as described below.This line is followe by blank line,and the the is also bloce e e bloce e e e.com blace.com blace e e block.intwo.com.intblace.com。
Input will consist of a sequence of`file fragment s',one per line,terminated by the end-off-file marker.Each frame consists of a sting of ASCII 1's and 0's.
Output
For each test case,the output must follow the description below.The out puts of two consecutive cases will be separated by a blank line.
Output is a single line of ASCII 1's and 0's giving the bit pattern of the ori ginal files.If there re 2 N frame nts in the input,it shoud be possible to cacontens the framents togethe in pairs the make-the
Your friend is certain that there were no more than 144 files on the tray,and that the files wers less than 256 bytes in size.
Sample Input
1

011
0111
01110
111
0111
10111
Sample Output
01110111
英語を習う=v=
1.all of the files on the tray were identical、all of them brook into exactly two frame nts.
書類ケースの中の書類は全部同じです。すべての書類がちょうど二つの部分に割れました。
2. If there isのunique solution、any of the possible solutions may be output.
唯一の解がないなら、可能な答えはすべて出力であることができます。しかし、テーマはSpecial Judgeではないので、ファイルの綴り方は一つだけです。
一番短いピースの長さ+一番長いピースの長さ=元のファイルの長さです。だから並べ替えたs[0]と一番長いピースを合わせたファイルを比較して、s[1]と他のピースを合わせたファイルを比較します。同じかどうかを見てください。
完全コード:
/*0.015s*/

#include<cstdio>
#include<cstring>
#include<cstdlib>

char s[160][260], a[260], b[260];
int n, len;

int cmp(const void* a, const void* b)
{
	return strlen((char*)a) < strlen((char*)b);
}

bool judge()
{
	for (int i = n - 1; i >= 0; --i)
	{
		if (strlen(s[1]) + strlen(s[i]) != len) continue;
		strcpy(b, s[1]);
		strcat(b, s[i]);
		if (strcmp(a, b) == 0) return true;
		///           a   (     ) ,                  
		strcpy(b, s[i]);
		strcat(b, s[1]);
		if (strcmp(a, b) == 0) return true;
	}
	return false;
}

int main()
{
	int T, i, min, max;
	scanf("%d
", &T); while (T--) { n = 0; while (gets(s[n]) && s[n][0]) ++n; qsort(s, n, sizeof(s[0]), cmp); min = strlen(s[0]); max = strlen(s[n - 1]); len = min + max; for (i = n - 1; i >= 0 && (int)strlen(s[i]) == max; --i)/// s[0] { strcpy(a, s[0]); strcat(a, s[i]); if (judge()) break; strcpy(a, s[i]); strcat(a, s[0]); if (judge()) break; } puts(a); if (T) putchar(10); } return 0; }