PAT Basic 1089 werewolf kill - simple version (20 minutes)

The following text is taken from "inspiration · fun math": "Werewolf kill" game is divided into a werewolf, good two camps. In a game of "werewolf kill" game, the No. 1 player said: "No. 2 is a werewolf," No. 2 player, said: "No. 3 is a good man," No. 3 player said: "No. 4 is a werewolf," No. 4 player said : "No. 5 is a good man," No. 5 player said: "No. 4 is a good man." This is known to have five players who played werewolf role 2, there are two people that's not the truth, but not all have to lie werewolf werewolves are lying. Which role plays werewolf number two player?

The title is an upgraded version of the problem: the known  N 2 players who have played the role of werewolf, there are two people that's not the truth, but not all have to lie werewolf werewolves are lying. We ask you to find out what role to play werewolf a few numbers of players?

Input formats:

In the first line input is given a positive integer  N ( . 5). Then  N rows, the  i-th row of the given  number i say player ( 1), i.e., a player number with a positive number represents a good negative sign indicates Wolfman.

Output formats:

If a solution, in an ascending order output line 2 werewolf number, separated by a space therebetween, end to end row may not have extra space. If the solution is not unique, the minimum output sequence solutions - i.e., for two sequences  [and  [, if there is  0 such that  [( I K), and the  sequence [, called  A sequence is less than  B. If no solution is output  No Solution.

Sample Input 1:

5
-2
+3
-4
+5
+4

Output Sample 1:

1 4

Sample Input 2:

6
+6
+3
+1
-5
-2
+4

Output Sample 2 (solution is not unique):

1 5

Sample Input 3:

5
-2
-3
-4
-5
-1

Sample Output 3:

No Solution

#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main()
{
    int N;cin>>N;
    int check[N+1];
    for(int i=1;i<=N;i++) cin>>check[i];
    for(int i=1;i<N;i++){
        for(int j=i+1;j<=N;j++){//假设i,j是狼人
            vector<int> lie,a(N+1,1);
            a[i]=a[j]=-1;//狼人为-1
            for(int k=1;k<=N;k++)
                if(a[abs(check[k])]*check[k]<0)
                    lie.push_back (K); // long multiplication is negative, was lying 
            IF (lie.size () == 2 && A [Lie [ 0 ]] + A [Lie [ . 1 ]] == 0 ) {
                cout<<i<<" "<<j<<endl;
                system("pause");
                return 0;
            }
        }
    }
    cout<<"No Solution"<<endl;
    system("pause");
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/littlepage/p/11706514.html