UVA 10132-File Fragmentation(map还原字符串)

File Fragmentation

The Problem

Your friend, a biochemistry major, tripped while carrying a tray of computer files through the lab. All of the files fell to the ground and broke. Your friend picked up all the file fragments and called you to ask for help putting them back together again.

Fortunately, all of the files on the tray were identical, all of them broke into exactly two fragments, and all of the file fragments were found. Unfortunately, the files didn‘t all break in the same place, and the fragments were completely mixed up by their
fall to the floor.

You‘ve translated the original binary fragments into strings of ASCII 1‘s and 0‘s, and you‘re planning 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 following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.

Input will consist of a sequence of ``file fragments‘‘, one per line, terminated by the end-of-file marker. Each fragment consists of a string of ASCII 1‘s and 0‘s.

Output

For each test case, the output must follow the description below. The outputs 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 original files. If there are 2N fragments in the input, it should be possible to concatenate these fragments together in pairs to make N copies of the output string. If there is no unique
solution, any of the possible solutions may be output.

Your friend is certain that there were no more than 144 files on the tray, and that the files were all less than 256 bytes in size.

Sample Input

1

011
0111
01110
111
0111
10111

Sample Output

01110111

题意:一些相同的文件由01构成,不小心把每份文件摔成两份,给出你摔坏后的文件组成,让你求出原文件

思路:暴力。把每个字符串与都链接一下,然后用map每个链接后的文件的数量,然后找出输入数量的一半以上的文件,则为原文件。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
using namespace std;
const int inf=0x3f3f3f3f;
char str[1010][310];
struct node {
    char site[310];
} x[10010];
int main()
{
    int T,i,j;
    char a[20],r1[1010],r2[1010];
    int cnt,t;
    scanf("%d",&T);
    getchar();
    gets(a);
    while(T--) {
        cnt=t=0;
        while(gets(str[cnt])!=NULL) {
            if(str[cnt][0]=='\0') break;
            cnt++;
        }
        map<string,int >q;
        for(i=0; i<cnt; i++)
            for(j=i+1; j<cnt; j++) {
                strcpy(r1,str[i]);
                strcat(r1,str[j]);
                if(!q[r1])
                    strcpy(x[t++].site,r1);
                q[r1]++;
                strcpy(r2,str[j]);
                strcat(r2,str[i]);
                if(!q[r2])
                    strcpy(x[t++].site,r2);
                q[r2]++;

            }
        for(i=0; i<t; i++)
            if(q[x[i].site]>=cnt/2) {
                printf("%s\n",x[i].site);
                break;
            }
            if(T)
                printf("\n");
    }
    return 0;
}
时间: 2024-10-18 09:08:16

UVA 10132-File Fragmentation(map还原字符串)的相关文章

UVA - 10132 File Fragmentation

题目大意:输入有点恶心,首先是case数,然后一个空行,然后再输入信息,然后又以一个空行结束该组数据,如果是最后一组数据了,不以空行结束,而是直接以EOF结束.输出,case之间有一个空行,最后一个case后面不要加空行 每组case的信息,就是N行的串,串中只有01,串的个数一定是偶数.原本有很多个一样的长串,每个长串都分成了两个短串但是分割的位置不一定相同即两个短串不一定是平分的(就是输入中的那些串).你要把这偶数个短串拼回那个长串(即2N个短串拼回N个相同的长串),如果有多种可能,任意一种

File Fragmentation

很弱的数据,随便搞 #include <iostream> #include <cstdio> #include <map> #include <string> #include <cstring> #include <vector> #include <algorithm> using namespace std; void debug() { cout<<"yes"<<end

UVA File Fragmentation(文件复原)

Description Question 2: File Fragmentation The Problem Your friend, a biochemistry major, tripped while carrying a tray of computer files through the lab. All of the files fell to the ground and broke. Your friend picked up all the file fragments and

UVA 10815-Andy&#39;s First Dictionary(字符串模拟+排序+重复删除)

Andy's First Dictionary Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description Problem B: Andy's First Dictionary Time limit: 3 seconds Andy, 8, has a dream - he wants to produce his very own dictionary. This

UVA - 10298 Power Strings (KMP求字符串循环节)

Description Problem D: Power Strings Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponentiati

UVA 12718 Dromicpalin Substrings(寻找字符串连续子串的回文)

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4456 题意:寻找给出字符串的字串中是回文的个数(注意:字串中字母换位置后能组成回文也要算在内,例如:aab之类的可以换位置为:aba 也是一个回文). 思路:只需统计每个字母出现的次数,再统计出现次数中

File Fragmentation Uva 10132

思路:最长的碎片和最短的碎片的组合中肯定有答案.所以先求长度,然后组合他们,最后检测组合结果字符串是否确保输入的碎片字符串都在其开始或结尾处. 总结:代码编写边注释,当你注释写不好的时候,说明你的思路也不是很清晰,请停下来思考,理清思路.下面这段代码是我注释得最详细的,因为我体会到,当自己写的程序不能AC的时候,搜搜看看别人没有注释的代码会更加让自己烦躁. #include<stdio.h> #include<string.h> void Reverse(char *strDest

UVa 156 Ananagrams(STL,map)

 Ananagrams  Most crossword puzzle fans are used to anagrams--groups of words with the same letters in different orders--for example OPTS, SPOT, STOP, POTS and POST. Some words however do not have this attribute, no matter how you rearrange their let

UVA - 10340 - All in All (字符串处理!)

题目链接:All in All Problem E All in All Input: standard input Output: standard output Time Limit: 2 seconds Memory Limit: 32 MB You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated st