PAT Basic 1089 Wolf Kill – Simple Edition (20 points)

The following text is excerpted from “A Mind Move·Fun Math”: The “Werewolf Killing” game is divided into two camps: werewolves and good guys. In a game of “Werewolf Killing”, player No. 1 said: “No. 2 is a werewolf”, player No. 2 said: “No. 3 is a good man”, player No. 3 said: “No. 4 is a werewolf”, player No. 4 said : “No. 5 is a good person”, Player 5 said: “No. 4 is a good person”. It is known that 2 of these 5 players are playing the role of werewolves, 2 of them are not telling the truth, some werewolves lied, but not all werewolves were lying. Which two players play the role of werewolf?

This question is an upgraded version of this question: known N players have 2 people playing the role of werewolves, 2 of them are not telling the truth, some werewolves lied but not all werewolves were there lie. You are asked to find out which player number is playing the role of werewolf?

input format:

input in the first Give a positive integer in the line N (5). Then Line N, line i gives the line i’s words (1), that is, a player number. Use a positive sign to indicate a good person. The minus sign indicates a werewolf. span>

Output format:

If there is a solution, output the numbers of 2 werewolves in ascending order on a line, separated by spaces, at the beginning and end of the line No extra spaces are allowed. If the solution is not unique, the smallest sequence solution is output-that is, for two sequences [ and [, if there is 0 such that [ span class=”katex”>[ (ik), and [, then called the sequence< span class="katex">A is less than the sequenceB. If there is no solution, output No Solution. span>

Input example 1:

5

-2
+3
-4
+5
+4

Output sample 1:

1 4

Input sample Example 2:

6

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

Sample output 2 (the solution is not unique):

1 5

Input example 3:

5

-2
-3
-4
-5
-1

Sample output 3:



No Solution
#include 

#include

#include

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){
for(int j=i+1;j<=N;j++){//Suppose i and j are werewolves
vector<int> lie,a(N+1,1);
a[i]
=a[j]=-1;/ /The werewolf is -1
for(int k=1;k<=N;k++)
if(a[abs(check[k])]*check[k]<0)
lie.push_back(k);
//As long as the multiplication is negative , It’s a lie
if(lie.size()==2&&a[lie[ 0]]+a[lie[1]]==0){
cout
<" "<< j<<endl;
system(
"pause");
return 0;
}
}
}
cout
<<"No Solution"<<endl;
system(
"pause");
return 0;
}

#include 

#include

#include

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){
for(int j=i+1;j<=N;j++){//Suppose i and j are werewolves
vector<int> lie,a(N+1,1);
a[i]
=a[j]=-1;/ /The werewolf is -1
for(int k=1;k<=N;k++)
if(a[abs(check[k])]*check[k]<0)
lie.push_back(k);
//As long as the multiplication is negative , It’s a lie
if(lie.size()==2&&a[lie[ 0]]+a[lie[1]]==0){
cout
<" "<< j<<endl;
system(
"pause");
return 0;
}
}
}
cout
<<"No Solution"<<endl;
system(
"pause");
return 0;
}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 1717 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.