您的位置:首页 > 其它

zoj 3432 Find the Lost Sock(zoj月赛,受打击了 = =)

2010-11-14 17:43 357 查看
详见


http://blog.sina.com.cn/s/blog_677a3eb30100mjy9.html


终于有解题报告了 = =



一直TLE。



我尝试了N种方法,包括我最讨厌的链表 = =,它就是TLE,我哭。



而且学会了个用scanf输入字符串(包括空格的)



scanf("%[^/n]",str);



后来实在过不去,就尝试,看哪种读入数据方法好。



gets() < scanf("%[^/n]",str) < scanf("%c",&str[0]) 第三个是最慢的,一个字符一个字符读入。



上面的解题报告我好佩服啊,位运算!!总是被我忽略 = =。。



就是啊 异或运算,算到最后,留下的,肯定是没有匹配到的。。。强大。。



我就贴个我的链表 TLE的吧。。。



#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
using namespace std;
typedef struct NODE
{
	char str[10];
	struct NODE *next;
}NODE;
NODE s,temp[3000000];
int main(void)
{
	int n;
	char ss[10];
	while( scanf("%d",&n)!= EOF )
	{
		getchar();
		memset(temp,0,sizeof(temp));
		temp[0].str[0] = 'a';
		s = temp[0];	
		for(int i=1; i<=2*n-1; i++)
		{
			gets(temp[i].str);	
			int flag = 0;		
			NODE *p = &s;
			while( p->next != NULL )
			{
				if( strcmp(p->next->str,temp[i].str) == 0 )
				{
					flag = 1;
					p -> next = p->next -> next;
					break;
				}
				else	
					p = p->next;
			}
			
			if( flag == 0 )
			{
				NODE *aa = &temp[i];
				p->next = aa;
			}
		} 
		NODE *pp = &s;
		puts(pp->next->str);
	}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: