Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.6 kB
4
Indexable
Never
#include <stdio.h>
#define INT_MAX 1000007
char str[7];
int pooh_turn(int n, int a, int b);
int piglet_turn(int n, int a, int b);
int check[2][10001], use[2][10001];
int i;
int main(){
	int N, A, B;
	for(i = 0; i < 10001; i++) check[0][i] = INT_MAX;
	for(i = 0; i < 10001; i++) check[1][i] = INT_MAX;
	int T;
	scanf("%d", &T);
	while(T--){
		scanf("%d%d%d%s", &N, &A, &B, &str);
		if(str[1] == 'o'){
			if(pooh_turn(N, A, B) == 1) printf("Pooh\n");
			else printf("Piglet\n");
		}
		else{
			if(piglet_turn(N, A, B) == 1) printf("Piglet\n");
			else printf("Pooh\n");
		}
		for(i = 0; i < 10001; i++) check[0][i] = INT_MAX;
	    for(i = 0; i < 10001; i++) check[1][i] = INT_MAX;
	    for(i = 0; i < 10001; i++) use[0][i] = 0;
	    for(i = 0; i < 10001; i++) use[1][i] = 0;
	}
	return 0;
}
int pooh_turn(int n, int a, int b){
	int j;
	if(check[0][n] == INT_MAX){
		if(n <= a){
			check[0][n] = 1;
			return 1;
		}
		else{
			for(j = 1; j <= a; j++){
				if(piglet_turn(n - j, a, b) == 0) use[0][n] = 1;
			}
			if(use[0][n] == 1){
				check[0][n] = 1;
				return 1;
			}
			else{
				check[0][n] = 0;
				return 0;
			}
		}
	}
	else return check[0][n];
}
int piglet_turn(int n, int a, int b){
	int j;
	if(check[1][n] == INT_MAX){
		if(n <= b){
			check[1][n] = 1;
			return 1;
		}
		else{
			for(j = 1; j <= b; j++){
				if(pooh_turn(n - j, a, b) == 0) use[1][n] = 1;
			}
			if(use[1][n] == 1){
				check[1][n] = 1;
				return 1;
			}
			else{
				check[1][n] = 0;
				return 0;
			}
		}
	}
	else return check[1][n];
}