一共有5个红领巾,编号分别为A、B、C、D、E,老奶奶被他们其中一个扶过了马路。
五个红领巾各自说话:
A :我和E都没有扶老奶奶
B :老奶奶是被C和E其中一个扶过大街的
C :老奶奶是被我和D其中一个扶过大街的
D :B和C都没有扶老奶奶过街
E :我没有扶老奶奶
已知五个红领巾中有且只有2个人说的是真话,请问是谁扶这老奶奶过了街?
若有多个答案,在一行中输出,编号之间用空格隔开。
大一上学期刚学枚举的时候,做过类似的题,当时还不清楚做法,没想到快大四了还能见到这道题 总之五个人要不然就是扶了或者没扶,都枚举出来,然后算出命题的值,有两个命题为真的话就输出这种情况。然后题意又说只有一个人扶了,那就找其中只有一个人扶了的情况,结果就发现是A,B和E
#include <iostream> #include <cstring> #include <string> #include <vector> #include <queue> #include <cstdio> #include <set> #include <math.h> #include <algorithm> #include <queue> #include <iomanip> #define INF 0x3f3f3f3f #define MAXN 505 #define Mod 99999999 using namespace std; int main() { for(int a=0; a<=1; ++a) for(int b=0; b<=1; ++b) for(int c=0; c<=1; ++c) for(int d=0; d<=1; ++d) for(int e=0; e<=1; ++e) { int t=0; if(!a&&!e) t++; if(c||e) t++; if(c||d) t++; if(!b&&!c) t++; if(!e) t++; //if(t==2) //cout<<a<<b<<c<<d<<e<<endl; } cout<<"A B E"; return 0; }