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

这是我1691的代码 求大神指点 感激不尽

Posted by haojiawei at 2013-03-17 14:04:20 on Problem 1691
#include<iostream>
using namespace std;
#define	MIN INT_MAX;
struct node
{
	int rx,ry,lx,ly;
	int t;                   //要求的颜色
	int yn;                  //当前节点是否已经着色
};
node s[100];
int m,n;
int judge_1(node x,node y)   //判断x是否在y上方
{
	if(x.ry==y.ly)
	{
		if(x.rx<=y.rx&&x.rx>y.lx)
			return 1;
		if(x.lx>=y.lx&&x.lx<y.rx)
			return 1;
		if(x.lx<=y.lx&&x.rx>=y.rx)
			return 1;
	}
	return 0;
}
int judge(node x)             //判断是否可以着色
{
	if(x.yn)
		return 0;
	for(int i=0;i<n;i++)
	{
		if(judge_1(s[i],x)&&!s[i].yn)//如果节点s[i]在x上方且没有着色  则返回“0”
			return 0;
	}
	return 1;

}
void get(int x)
{
	if(x<m)
		m=x;
}

void dfs(int k,int num,int count)//从节点“k”开始收索
{
	s[k].yn=1;               //标记该节点已经着色
	if(num==n)               //收索一次后判断结果是否优于当前值
	{
		get(count);          
		return;
	}
	for(int i=0;i<n;i++)      //从任何可着色节点收索
		if(judge(s[i]))
		{
			if(s[k].t==s[i].t)
			{
				dfs(i,num+1,count);
				s[i].yn=0;
			}
			else
			{
				dfs(i,num+1,count+1);
				s[i].yn=0;

			}
		}
	
	
}
void dfs()              //从不同点开始着色
{
	for(int i=0;i<n;i++)
		dfs(i,1,1);		
}
int main()
{
	int c;
	cin>>c;
	while(c--)
	{
		cin>>n;
		for(int i=0;i<n;i++)
		{
			cin>>s[i].ly>>s[i].lx>>s[i].ry>>s[i].rx>>s[i].t;
			s[i].yn=0;
		}
		m=MIN;
		dfs();
		cout<<m<<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