nefu 643 按位异或应用

来源:互联网 发布:不会英语怎么学编程 编辑:程序博客网 时间:2024/05/18 03:46

http://acm.nefu.edu.cn/JudgeOnline/problemshow.php?problem_id=643

description

This time,suddenly,teacher Li wants to find out who have missed interesting DP lesson to have fun.The students who are found out will get strictly punishment.Because,teacher Li wants all the students master the DP algorithm.    However,Li doesn't want to waste the class time to call over the names of students.So he let the students to write down their names in one paper.To his satisfaction,this time, only one student has not come.    He can get the name who has not come to class,but,it is troublesome,and,teacher always have many things to think about,so,teacher Li wants you, who is in the ACM team, to pick out the name.

input

There are several test cases.The first line of each case have one positive integer N.N is the  number of the students,and N will not greater than 500,000.   Then,following N lines,each line contains one name of students who have attended class.The N-1 lines are presented after N lines.These N-1 lines indicates the names of students who have come to class this time,one name in one line.   The length of student's name is not greater than 30.   Process to the end of file.

output

 For each test case, first print a line saying "Scenario #k", where k is the number of the test case.Then output the name of the student who have not come to class.One case per line.Print a blank line after each test case, even after the last one.

sample_input

3ABCBC

sample_output

Scenario #1A
这道题比赛的时候我以为用map可以,可是数据太厉害了,怎么弄都超时。又改成了异或,这样就对了。

按位异或:

 孙常峰学长 17:15:56 1^1=01^0=1孙常峰学长 17:16:33 然后拓展开孙常峰学长 17:16:42 101 ^ 101 ^ 111 = 111孙常峰学长 17:16:47 即 A^A^B=B孙常峰学长 17:16:52 A^A^A=A孙常峰学长 17:17:14 有偶数个A异或就会相互抵消Yran 17:17:33 字符串也行嘛Yran 17:17:35 ??、孙常峰学长 17:17:51 再举个例子Yran 17:18:03 恩孙常峰学长 17:18:05 ABCABCBCD按位异或孙常峰学长 17:18:20 A^A^B = BB^B^C = CC^C^D = D孙常峰学长 17:18:29 发现关键了没有Yran 17:18:49 你是说一位一位的来的孙常峰学长 17:18:52 不理解的话我们把一个字符'A'换成asc2码孙常峰学长 17:18:58 'A' = 65孙常峰学长 17:19:01 'B' = 66孙常峰学长 17:19:29 65 1000001孙常峰学长 17:19:38 66 1000010孙常峰学长 17:20:03 'A' ^ 'A' ^ 'B'1000001 ^ 1000001 ^ 1000010孙常峰学长 17:20:09 你说是多少孙常峰学长 17:20:11 结果Yran 17:20:30 1000010孙常峰学长 17:20:40  是不是'B'孙常峰学长 17:20:42 这就说明Yran 17:20:46 我去Yran 17:20:53 你接着说孙常峰学长 17:21:01 对字符按位异或孙常峰学长 17:21:07 还能保持异或的性质孙常峰学长 17:21:21 即 偶数个 相同的抵消孙常峰学长 17:21:41 我们再拓展,把字符拓展成字符串孙常峰学长 17:21:57 "ABC" "ABC""BCD"孙常峰学长 17:22:06 对第一位的字符孙常峰学长 17:22:12 "A" "A" "B"孙常峰学长 17:22:18 异或起来孙常峰学长 17:22:26 再对第二位 ,第三位异或孙常峰学长 17:22:28 结果就是孙常峰学长 17:22:33 "BCD"孙常峰学长 17:22:36 没了Yran 17:25:49 有点明白了,孙常峰学长 17:25:57 才有点啊孙常峰学长 17:26:02 我再说几个性质孙常峰学长 17:26:17 0异或任何数都是任何数孙常峰学长 17:26:27 0 ^ A = AYran 17:26:30 恩恩Yran 17:26:34 继续说孙常峰学长 17:26:44 异或满足结合律孙常峰学长 17:26:52 A^B^C = A^(B^C)孙常峰学长 17:27:08 交换律孙常峰学长 17:27:13 A^B^A = A^A^B孙常峰学长 17:27:24 没了孙常峰学长 17:27:34 总之题意就是孙常峰学长 17:27:42 A^B^C^D^A^C^D孙常峰学长 17:27:56 =A^A^C^C^D^D^B孙常峰学长 17:27:58 =B



我的代码:

#include <stdio.h>#include <string.h>#include <algorithm>#include <stdio.h>int main(){    char a[35],b[35];    int n;    int k=1;    while(~scanf("%d",&n))    {        if(n<=0)            break;        memset(b,0,sizeof(b));        memset(a,0,sizeof(a));        for(int i=0;i<2*n-1;i++)        {            scanf("%s",a);            int m=strlen(a);            int kk=strlen(b);            for(int j=0;j<m||j<kk;j++)                b[j]=b[j]^a[j];        }        printf("Scenario #%d\n%s\n\n",k++,b);    }    return 0;}



0 0
原创粉丝点击