码迷,mamicode.com
首页 > 其他好文 > 详细

哪几个人参加了会议?

时间:2014-09-24 02:08:25      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:style   color   io   os   ar   for   sp   on   c   


有人邀请A,B,C,D,E,F6个人参加一项会议,这6个人有些奇怪,因为他们有很多要求,已知:

1.A,B两人至少有1人参加会议。
2.A,E,F3人中有2人参加会议。
3.B和C两人一致决定,要么两人都去,要么两人都不去。
4.A,D两人中只1人参加会议。
5.C,D两人中也只要1人参加会议。

6.如果D不去,那么E也决定不去。那么最后究竟有哪几个人参加了会议呢?


简单推理,暴力枚举~

答案是:A,B,C,F


#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#define ms(x,y) memset(x,y,sizeof(x))
const int MAXN=1000+10;
const int INF=1<<30;
using namespace std;
int n=6;
int A[100];

bool J1()
{
	if(A[1] || A[2]) return 1;
	return 0;
}

bool J2()
{
	if((A[1] && A[5] && A[6]==0) || (A[1] && A[5]==0 && A[6]) || (A[1]==0 && A[5] && A[6])) return 1;
	return 0;
}


bool J3()
{
	if(A[2] && A[3]) return 1;
	if(A[2]==0 && A[3]==0) return 1;
	return 0;
}


bool J4()
{
	if(A[1] && A[4]==0) return 1;
	if(A[1]==0 && A[4]) return 1;
	return 0;
}


bool J5()
{
	if(A[3] && A[4]==0) return 1;
	if(A[3]==0 && A[4]) return 1;
	return 0;
}


bool J6()
{
	if(A[4]==0 && A[5]) return 0;
	return 1;
}

bool judge()
{
	if(J1() && J2() && J3() && J4() && J5() && J6()) return 1;
	return 0;
}

void dfs(int cnt, int mark)
{
	A[cnt]=mark;
	if(cnt==n){
		if(judge()){
			for(int i=1; i<=n; i++) 
				if(A[i]) cout<<char(i+'A'-1)<<" ";
			cout<<endl;
		}
		return;
	}
	dfs(cnt+1, 0);
	dfs(cnt+1, 1);
}

int main()
{
	//freopen("in.txt","r",stdin);
	dfs(0,0);
	return 0;
}


哪几个人参加了会议?

标签:style   color   io   os   ar   for   sp   on   c   

原文地址:http://blog.csdn.net/u013351484/article/details/39507691

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!