逻辑推理与判断(委派任务)

来源:互联网 发布:2017最新交友软件 编辑:程序博客网 时间:2024/06/06 17:59
/**************************************** *  File Name  : reasoning.c *  Creat Data : 2015.1.26*  Author     : ZY *****************************************/ /*逻辑推理与判断*//*委派任务*//*某侦察队接到一项紧急任务,要求在A,B,C,D,E,F六个队员中尽可能多的挑若干人,但有以下限制条件:1.A和B两个人至少去一人(a+b>1)2.A和D不能一起去(a+d!=2)3.A,E和F三人中要派两人去(a+e+f==2)4.B和C都去或都不去((b+c == 2)||(b+c == 0))5.C和D两个人中去一个(c+d == 1)6.若D不去,则E也不去((d+e == 0)||d == 1)问应当那几个人去?*/#include <stdio.h>int main(void){int a,b,c,d,e,f;for(a = 0;a < 2;a++){for(b = 0;b < 2;b++){for(c = 0;c < 2;c++){for(d = 0;d < 2;d++){for(e = 0;e < 2;e++){for(f = 0;f < 2;f++){if((a+b > 1)&&(a+d != 2)&&(a+e+f == 2)&&((b+c == 2)||(b+c == 0))&&(c+d == 1)&&((d+e == 0)||d == 1)){printf("A will %s be assigned.\n",a?"":"not");printf("B will %s be assigned.\n",b?"":"not");printf("C will %s be assigned.\n",c?"":"not");printf("D will %s be assigned.\n",d?"":"not");printf("E will %s be assigned.\n",e?"":"not");printf("F will %s be assigned.\n",f?"":"not");}}}}}}}return 0;}





/*某参观团按以下条件限制从A,B,C,D,E五个地方中选定若干个参观点1.如去A则必须去B(a+b == 2||b == 1)2.D,E两地只能去一地(d+e == 1)3.B,C两地只能去一地(b+c == 1)4.C,D两地都去或都不去(c+d == 2||c+d == 0)5.若去E地,A,D也必去(e+a+d == 3||a == 1||d == 1) 问该团最多能去哪几个地方*/#include <stdio.h>int main(void){int a,b,c,d,e;for(a = 0;a < 2;a++){for(b = 0;b < 2;b++){for(c = 0;c < 2;c++){for(d = 0;d < 2;d++){for(e = 0;e < 2;e++){if((a+b == 2||b == 1)&&(d+e == 1)&&(b+c == 1)&&(c+d == 2||c+d == 0)&&(e+a+d == 3||a == 1||d == 1)){printf("A will %s be assigned.\n",a?"":"not");printf("B will %s be assigned.\n",b?"":"not");printf("C will %s be assigned.\n",c?"":"not");printf("D will %s be assigned.\n",d?"":"not");printf("E will %s be assigned.\n",e?"":"not");printf(a?"A   ":"A not  ");printf(b?"B   ":"B not  ");printf(c?"C   ":"C not  ");printf(d?"D   ":"D not  ");printf(e?"E   ":"E not  ");}}}}}}printf("\n");return 0;}


0 0
原创粉丝点击