Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

从测试结果来看,似乎只要在2 * n次操作之后仍不能达到目标,即可输出-1,无需判重。这个结论正确吗?

Posted by zhouzp15 at 2017-01-25 16:12:49 on Problem 3087
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
using namespace std;

const int N = 2000 + 5;
int n, len;
char cards[N], tmp[N], goal[N];

int main()
{
	int T;
	scanf("%d", &T);
	for (int kase = 1; kase <= T; kase++)
	{
		scanf("%d", &n);
		scanf("%s", cards); scanf("%s", cards + n);
		scanf("%s", goal);
		len = n << 1;
		
		bool flag = false;
		for (int i = 1; i <= len; i++)
		{
			int pos = 0;
			for (int j = 0, k = n; k < len; j++, k++)
				tmp[pos++] = cards[k], tmp[pos++] = cards[j]; 
			
			tmp[len] = '\0';
			if (strcmp(tmp, goal) == 0) 
			{
				flag = true;
				printf("%d %d\n", kase, i);
				break;
			}
			strcpy(cards, tmp);
		}
		if (!flag) printf("%d %d\n", kase, -1);
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator