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 langx at 2010-10-13 17:42:44 on Problem 2062
丑陋的代码
----------------------------
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;

const unsigned MAX_SIZE = 26, MAX_INF = 0x7FFFFFFF;

struct Card{
	int val;
	int suit;
	char owner;
};

bool visited[MAX_SIZE << 1];
Card card[MAX_SIZE << 1];
char _inc[3];
int N, k, size, Epoint;

bool compare(Card &a, Card &b){
	if(a.val == b.val)return a.suit < b.suit;
	return a.val < b.val;
}

int toCardVal(char &cval){
	switch(cval){	
		case '2':case '3':case '4':case '5':
		case '6':case '7':case '8':case '9':return cval - '0';
		case 'T': return 10;
		case 'J': return 11;
		case 'Q': return 12;
		case 'K': return 13;
		case 'A': return MAX_INF;
	}
	return 0;
}

int toCardSuit(char &csuit){
	switch(csuit){
	  case 'C': return 1;
	  case 'D': return 2;
	  case 'S': return 3;
	  case 'H': return 4;
	}
	return 0;
}

int main (){
	int p, q, r, t;
	scanf("%d",&N);
	while ( N-- ) {
		scanf("%d",&k);
		for (int i = 0; i < (k << 1); ++i  ) {
			scanf("%s",_inc);
			card[i].val = toCardVal(_inc[0]);
			card[i].suit = toCardSuit(_inc[1]);
			if(i < k){
				card[i].owner = 'A';
			}else{
				card[i].owner = 'E';
			}
		}
		size = k << 1;
		sort(card, card + size, compare);
		r = 0;t = q  = size - 1;
		while ( size ) {
			if(!visited[q]){
				visited[q] = true;--size;
				if(card[q].owner == 'E'){	
					p = t;
					while ( p >= 0 ){
						if ( !visited[p] && card[p].owner == 'A' ) {
							visited[p] = true;--size;
							t = p;
							++Epoint;
							break;
						}
						--p;
					}
				}else{
					p = r;
					while ( p < k << 1 ){
						if ( !visited[p] && card[p].owner == 'E' ) {
							visited[p] = true;--size;
							r = p;
							break;
						}
						++p;
					}
				}
			}
			--q;
		}
		printf("%d\n",Epoint);
       memset(visited,false,sizeof(visited));Epoint = 0;
	}
	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