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

原创代码,16ms

Posted by cavatina2016 at 2018-11-27 14:25:48 on Problem 2558
#include <stdio.h>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
#define MAX_N	5000


const char* pattern[3] = {
	"ACBCAB",
	"ACABC",
	"ACBABCB"
};
string states[2][3];
string res;


void init()
{
	states[0][0] = "N";
	states[0][1] = "O";
	states[0][2] = "P";

	int prev = 0, curr = 1;
	while (states[prev][0].length() < MAX_N) {
		for (int i = 0; i < 3; ++i) {
			states[curr][i] = "";
			for (int j = 0; pattern[i][j]; ++j) {
				int idx = pattern[i][j] - 'A';
				states[curr][i] += states[prev][idx];
			}
		}
		prev = (prev + 1) % 2;
		curr = (curr + 1) % 2;
	}

	res = states[prev][0];
}


int main()
{
	init();
	while (true) {
		int n; scanf_s("%d", &n);
		if (!n) break;
		while (n > MAX_N) printf("...");
		for (int i = 0; i < n; ++i) {
			printf("%c", res[i]);
		}
		printf("\n");
	}
	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