枚举假设所有两个人是狼人:
若发现恰有两个人说谎, 且其一为狼, 则为所求;
规定:0-村民, 1-狼人;
说谎:事先将假设为狼人的玩家身份赋1, 并按发言核对,若发言与假设矛盾则认定当前发言玩家说谎;
最小序列:从1开始枚举,则首个符合条件的一组狼人为所求最小序列;
#include <cstdio>
#include <vector>
#include <cstdlib>
using namespace std;
bool trans( int n )
{ return n > 0 ? 0:1; } //0-村民 1-狼人;
int main()
{
int N;
scanf("%d", &N);
vector<int> statement(N + 1);
for( int i = 1; i <= N; ++i )
scanf("%d", &statement[i]);
for( int i = 1; i < N; ++i )
for( int j = i + 1, nLier; j <= N; ++j )
{
vector<int> status(N + 1), Lying(N + 1);
nLier = 0;
status[i] = status[j] = 1;
for( int k = 1; k <= N; ++k )
if( nLier > 2 )
break;
else if( status[ abs( statement[k] ) ] != trans( statement[k] ) )
{
++nLier;
Lying[k] = 1;
}
if( nLier == 2 && Lying[i] + Lying[j] == 1 )
{
printf("%d %d", i, j);
return 0;
}
}
printf("No Solution");
}