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

数据比较水,把char变量定义为int型,调试了4个多小时。提交50多次,哭了。。

Posted by ym94 at 2019-07-23 16:47:21 on Problem 2996
所有数据的白色和黑色都是一样的数量(真水)
然后 根本不用管什么吃不吃,直接记录 然后排序输出。
发一下我的优先队列,代码。
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<map>
#include<queue>
#include<vector>
#include<iostream>
#define Max
#define inf 0x3f3f3f3f
using namespace std;
struct Node{
	char x;//列 
	int y;//行 
	char id; //id 
};
int table[]={999,4,999,999,999,999,999,999,999,999,1,999,999,5,999,6,2,3,999,999};
struct cmp1{  //what 
	bool operator()(struct Node a,struct Node b)
	{
		if(a.id!=b.id)
		{
			return table[a.id-'A']>table[b.id-'A'];
		}
		else if(a.y!=b.y) //w的 1
		{
			return a.y>b.y;
		}
		else
		{
			return a.x>b.x;
		}
	}
};
struct cmp2{  //black 
	bool operator()(struct Node a,struct Node b)
	{
		if(a.id!=b.id)
		{
			return (table[a.id-'a']>table[b.id-'a']);
		}
		else if(a.y!=b.y) //大的 
		{
			return a.y<b.y;
		}
		else
		{
			return a.x>b.x;
		}
	}
};
priority_queue <struct Node,vector<struct Node>, cmp1> qw;//白色
priority_queue <struct Node,vector<struct Node>, cmp2> qb;//黑色 
char laji[100];

int main()
{
	int temp1,temp2,temp3,temp4,x,y;
	char value;
	struct Node temp;
	for(int i=8;i>=1;i--)
	{
		scanf("%s",laji);
		getchar();
		for(char j='a';j<='h';j++)
		{
			scanf("%c%c%c%c",&temp1,&temp2,&value,&temp4);
			if(value>='A'&&value<='Z')  //w 
			{
				temp.id=value;
				temp.x=j;
				temp.y=i;
				qw.push(temp);
			}
			else if(value>='a'&&value<='z')
			{
				temp.id=value;
				temp.x=j;
				temp.y=i;
				qb.push(temp);
			}
		}
		getchar();
		getchar();
	}
	scanf("%s",laji);
	getchar();
	cout<<"White: ";  //我曾以为是不是printf的问题(遇到了,迷!),然而并不是
	if(qw.size())//出队
	{
		temp=qw.top();
		qw.pop();
		if(temp.id!='P')
			printf("%c",temp.id);
		printf("%c%d",temp.x,temp.y);
	}
	while(qw.size())
	{
		temp=qw.top();
		qw.pop();
		printf(",");
		if(temp.id!='P')
			printf("%c",temp.id);
		printf("%c%d",temp.x,temp.y);
	}
	cout<<endl;
	cout<<"Black: ";
	if(qb.size())
	{
		temp=qb.top();
		qb.pop();
		if(temp.id!='p')
			printf("%c",temp.id-32);
		printf("%c%d",temp.x,temp.y);
	}
	while(qb.size())
	{
		temp=qb.top();
		qb.pop();
		printf(",");
		if(temp.id!='p')
			printf("%c",temp.id-32);
		printf("%c%d",temp.x,temp.y);
	}
	cout<<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