A1148
Description:
N个人依次发言,正数代表该数字人为人,负数代表该数字人为狼,这些人里有两只狼,一只撒谎一只没撒谎,求出这个序列的狼人,无解则输出No Solution;
思路:
这种题一定要仔细捋清逻辑关系;对于本题,可以使用二重循环枚举假设下标对应人为狼人,然后检查这种假设下每人说的话是否能满足题意(一人说谎、一狼说谎),若满足则输出两下标,遍历完毕仍无解则无解;
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
using namespace std
;
int a
[105], n
;
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif
scanf("%d", &n
);
bool havAns
= false;
for(int i
= 1; i
<= n
; i
++) scanf("%d", &a
[i
]);
for(int i
= 1; i
< n
; i
++){
for(int j
= i
+1; j
<= n
; j
++){
vector
<int>cnt
;
for(int l
= 1; l
<= n
; l
++){
if((a
[l
]>0&&(a
[l
]==i
||a
[l
]==j
))
|| (a
[l
]<0&&(a
[l
]!=-i
&&a
[l
]!=-j
)))
cnt
.push_back(l
);
}
if(cnt
.size()==2){
if(cnt
[0]==i
&&cnt
[1]==j
)continue;
else if(cnt
[0]!=i
&&cnt
[0]!=j
&&cnt
[1]!=i
&&cnt
[1]!=j
)continue;
else{
printf("%d %d\n", i
, j
);
havAns
= true;
break;
}
}
}
if(havAns
) break;
}
if(!havAns
) printf("No Solution\n");
return 0;
}