Werewolf

PAT-1148

  • 题目的要点是不管n规模多大,始终只有两个狼人
  • 说谎的是一个狼人和一个好人
  • 紧紧抓住这两点进行实现和分析
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n+1);
for (int i = 1; i <= n; i++) cin >> v[i];//自己说的话
//假设i和j是狼人
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
vector<int> lie, a(n + 1, 1);
a[i] = a[j] = -1;//1表示好人,-1表示和j是狼人(只有两个狼人)
for (int k = 1; k <= n; k++)
if (v[k] * a[abs(v[k])] < 0) //k说的是假话
lie.push_back(k);
if (lie.size() == 2 && a[lie[0]] + a[lie[1]] == 0) {//说假话的一个是狼人一个是好人
cout << i << " " << j;
return 0;
}
}
}
cout << "No Solution";
return 0;
}

PAT-1148(Werewolf )思维+数学问题的更多相关文章

  1. PAT 1148 Werewolf - Simple Version

    1148 Werewolf - Simple Version (20 分)   Werewolf(狼人杀) is a game in which the players are partitioned ...

  2. PAT 1148 Werewolf - Simple Version [难理解]

    1148 Werewolf - Simple Version (20 分) Werewolf(狼人杀) is a game in which the players are partitioned i ...

  3. PAT(A) 1148 Werewolf - Simple Version(Java)逻辑推理

    题目链接:1148 Werewolf - Simple Version (20 point(s)) Description Werewolf(狼人杀) is a game in which the p ...

  4. [Codeforces 1178D]Prime Graph (思维+数学)

    Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是 ...

  5. 牛客网多校第9场 E Music Game 【思维+数学期望】

    题目:戳这里 题意:鼠标点击n下,第i次点击成功的概率为p[i],连续点击成功x次可以获得x^m分,求n次点击总分数的数学期望. 解题思路:数学期望的题很多都需要转化思维,求某一个单独状态对整体答案的 ...

  6. PAT A1148 Werewolf - Simple Version (20 分)——暴力遍历,负负得正

    Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and th ...

  7. 1148 Werewolf - Simple Version (20 分)

    Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and th ...

  8. Codeforces Round #304 (Div. 2) D 思维/数学/质因子/打表/前缀和/记忆化

    D. Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes input s ...

  9. 牛客网多校第5场 F take 【思维+数学期望】

    题目:戳这里 思路来源:视频讲解 题意:有n个箱子按1...n标号,每个箱子有大小为di的钻石概率为pi,我们初始有个大小为0的钻石,从1到n按顺序打开箱子,遇到比手中大的箱子就换,求交换次数的数学期 ...

随机推荐

  1. 2020牛客暑期多校训练营 (第二场) All with Pairs

    传送门:All with Pairs 题意:给你n个字符串,求出,f(si,sj)的意思是字符串 si 的前缀和字符串 sj 后缀最长相等部分. 题解:先对所有的字符串后缀hash,用map记录每个h ...

  2. Linux core dump使用

    什么是 core dump? core dump是一个当进程意外终止时包含进程内存内容的文件.当程序崩溃的时候,core dump由kernel触发.core dump可以作为程序崩溃时的事后快照(p ...

  3. 80x86/Pentium微机原理及接口技术-微处理器-学习笔记

    80x86/  Pentium微机原理及接口技术 1.    计算机基础... 1 1.1常用术语... 1 1.2计算机中数与编码的表示方法... 1 1.2.1进制表示及进制转换... 1 1.2 ...

  4. [APUE] 进程控制

    APUE 一书的第八章学习笔记. 进程标识 大家都知道使用 PID 来标识的. 系统中的一些特殊进程: PID = 0: 调度进程,也称为交换进程 (Swapper) PID = 1: init 进程 ...

  5. Vue3.0新特性

    Vue3.0新特性 Vue3.0的设计目标可以概括为体积更小.速度更快.加强TypeScript支持.加强API设计一致性.提高自身可维护性.开放更多底层功能. 描述 从Vue2到Vue3在一些比较重 ...

  6. hardsource bug

    hardsource bug webpack crashed bug memory stackoverflow [hardsource:32210703] Could not freeze refs ...

  7. 使用 js 实现十大排序算法: 快速排序

    使用 js 实现十大排序算法: 快速排序 QuickSort 快速排序 /** * * @author xgqfrms * @license MIT * @copyright xgqfrms * @c ...

  8. React Creating Elements All In One

    React Creating Elements All In One https://reactjs.org/docs/react-api.html#creating-react-elements h ...

  9. TypeScript Generics

    TypeScript Generics https://www.typescriptlang.org/docs/handbook/generics.html 泛型 1 Generic Interfac ...

  10. nodejs 调用win32 api

    video 教程文件 win32 api >node -v v12.16.1 >npm install -g node-gyp >npm i @saleae/ffi >node ...