1148 Werewolf - Simple Version

这题我觉得真的有点烦,我想了半天还是没全对。。。还是参考大神的。。。

 1 #include <iostream>
 2 #include <stdlib.h>
 3 #include <string>
 4 #include<algorithm>
 5 #include<vector>
 6 #include<cmath>
 7 #include<map>
 8 #include<set>
 9 #include <unordered_map>
10 using namespace std;
11
12 int main(){
13     int n;
14     vector<int> arr(101);
15     cin >> n;
16     for (int i = 0; i < n; i++) {
17         cin >> arr[i + 1];
18     }
19     int w1 = -1, w2 = -1;
20     for (int i = 1; i <= n; i++) {
21         for (int j = 1; j <= n; j++) {
22             if (j == i) {
23                 continue;
24             }
25             else {
26                 vector<int> lier, wolf(n + 1, 1);
27                 wolf[i] = wolf[j] = -1;
28
29                 for (int k = 1; k <= n; k++) {
30                     if (arr[k] * wolf[abs(arr[k])] < 0) {
31                         lier.push_back(k);
32                     }
33                 }
34
35                 if (lier.size() == 2 && wolf[lier[0]] + wolf[lier[1]] == 0) {
36                     w1 = i;
37                     w2 = j;
38                     goto p1;
39
40                 }
41
42             }
43         }
44     }
45
46 p1:
47     if (w1 ==-1) {
48         cout << "No Solution" << endl;
49     }
50     else {
51         cout << w1 << ‘ ‘ << w2 << endl;
52     }
53
54     system("pause");
55 };

原文地址:https://www.cnblogs.com/wsggb123/p/10225314.html

时间: 2024-11-06 11:39:12

1148 Werewolf - Simple Version的相关文章

1148 Werewolf - Simple Version (20 分)

1148 Werewolf - Simple Version (20 分) Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and the human beings. Suppose that in a game, player #1 said: "Player #2 is a werewolf."; player #2 said: "P

1148 Werewolf - Simple Version (20 分)

Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and the human beings. Suppose that in a game, player #1 said: "Player #2 is a werewolf."; player #2 said: "Player #3 is a human."; player #3

PAT_A1148#Werewolf - Simple Version

Source: PAT A1148 Werewolf - Simple Version (20 分) Description: Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and the human beings. Suppose that in a game, player #1 said: "Player #2 is a werewolf."

A题目

1 1001 A+B Format(20) 2 1002 A+B for Polynomials(25) 3 1003 Emergency(25) 4 1004 Counting Leaves(30) 5 1005 Spell It Right(20) 6 1006 Sign In and Sign Out(25) 7 1007 Maximum Subsequence Sum(25) 8 1008 Elevator(20) 9 1009 Product of Polynomials(25) 10

PAT 2018 秋

A 1148 Werewolf - Simple Version 思路比较直接:模拟就行.因为需要序列号最小的两个狼人,所以以狼人为因变量进行模拟. 1 #include <cstdio> 2 #include <cstdlib> 3 #include <iostream> 4 #include <algorithm> 5 #include <vector> 6 7 using namespace std; 8 int N; 9 vector&l

2018.9.8pat秋季甲级考试

第一次参加pat考试,结果很惨,只做了中间两道题,还有一个测试点错误,所以最终只得了不到50分.题目是甲级练习题的1148-1151. 考试时有些紧张,第一题第二题开始测试样例都运行不正确,但是调试程序考场的vs2013不能粘贴,还得一点点输上去.浪费了很多时间. 1.Werewolf - Simple Version 之前遇到这种题目较少,所以刚开始没什么思路.后来想到的方法是假设撒谎的两个人分别是i.j,然后遍历所有i.j,找出符合条件的.当时总共用了得有一个小时,但程序一直得不到正确答案,

Matlab学习(可以用MATLAB作曲)

从网上复制了一份matlab演奏的曲调源码,很有意思!(也很好听!) (源码来源:https://www.zhihu.com/question/27850677/answer/104060849) 1.因为复制问题,使用python简单处理了下: #!/usr/bin/python# -*- coding: UTF-8 -*- def writefile(sentences): fo = open("song.m", "w") for index, item in

hdoj 1787 GCD Again【欧拉函数】

GCD Again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2673    Accepted Submission(s): 1123 Problem Description Do you have spent some time to think and try to solve those unsolved problem af

netty Getting Started--reference

reference from:http://docs.jboss.org/netty/3.1/guide/html/start.html 1.1. Before Getting Started 1.2. Writing a Discard Server 1.3. Looking into the Received Data 1.4. Writing an Echo Server 1.5. Writing a Time Server 1.6. Writing a Time Client 1.7.