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

無聊的水題啊

Posted by KatrineYang at 2016-11-16 09:28:54 on Problem 1525
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>

using namespace std;

bool board[34];
int sum;
int FLAG = -233;
void init(){
	for(int i = 0; i < 34; i++) board[i] = 0;
	sum = 0;
	int tmp;
	while(1){
		cin >> tmp;
		if(!tmp) break;
		board[tmp] = 1;
		sum += tmp;
	}
}

int shang[34] = {0,0,0,0,1,2,3,0,0,4,5,6,0,0,7,8,9,10,11,12,13,14,15,16,17,18,19,20,23,24,25,28,29,30};
int xia[34] = {0,4,5,6,9,10,11,14,15,16,17,18,19,20,21,22,23,24,25,26,27,0,0,28,29,30,0,0,31,32,33,0,0,0};
int zuo[34] = {0,0,1,2,0,4,5,0,7,8,9,10,11,12,0,14,15,16,17,18,19,0,21,22,23,24,25,26,0,28,29,0,31,32};
int you[34] = {0,2,3,0,5,6,0,8,9,10,11,12,13,0,15,16,17,18,19,20,0,22,23,24,25,26,27,0,29,30,0,32,33,0};

int solve(){
	for(int i = 33; i > 0; i--){
		//顺序:下,右,左,上
		if(board[i]) continue;
		if(board[xia[xia[i]]] && board[xia[i]]){
			board[i] = 1; board[xia[xia[i]]] = 0; board[xia[i]] = 0;
			return xia[i]+xia[xia[i]]-i;
		}
		if(board[you[you[i]]] && board[you[i]]){
			board[i] = 1; board[you[you[i]]] = 0; board[you[i]] = 0;
			return you[i]+you[you[i]]-i;
		}
		if(board[zuo[zuo[i]]] && board[zuo[i]]){
			board[i] = 1; board[zuo[zuo[i]]] = 0; board[zuo[i]] = 0;
			return zuo[i]+zuo[zuo[i]]-i;
		}
		if(board[shang[shang[i]]] && board[shang[i]]){
			board[i] = 1; board[shang[shang[i]]] = 0; board[shang[i]] = 0;
			return shang[i]+shang[shang[i]]-i;
		}
	}
	return FLAG;
}

int main(int argc, char **argv){
	int n;
	cin >> n;
	cout << "HI Q OUTPUT" << endl;
	while(n--){
		init();
		int sub;
		while((sub = solve()) != FLAG){
			sum -= sub;
		}
		cout << sum << endl;
	}
	cout << "END OF OUTPUT" << endl;
	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