PAT-1148(Werewolf )思维+数学问题
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 )思维+数学问题的更多相关文章
- PAT 1148 Werewolf - Simple Version
1148 Werewolf - Simple Version (20 分) Werewolf(狼人杀) is a game in which the players are partitioned ...
- PAT 1148 Werewolf - Simple Version [难理解]
1148 Werewolf - Simple Version (20 分) Werewolf(狼人杀) is a game in which the players are partitioned i ...
- PAT(A) 1148 Werewolf - Simple Version(Java)逻辑推理
题目链接:1148 Werewolf - Simple Version (20 point(s)) Description Werewolf(狼人杀) is a game in which the p ...
- [Codeforces 1178D]Prime Graph (思维+数学)
Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是 ...
- 牛客网多校第9场 E Music Game 【思维+数学期望】
题目:戳这里 题意:鼠标点击n下,第i次点击成功的概率为p[i],连续点击成功x次可以获得x^m分,求n次点击总分数的数学期望. 解题思路:数学期望的题很多都需要转化思维,求某一个单独状态对整体答案的 ...
- PAT A1148 Werewolf - Simple Version (20 分)——暴力遍历,负负得正
Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and th ...
- 1148 Werewolf - Simple Version (20 分)
Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and th ...
- 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 ...
- 牛客网多校第5场 F take 【思维+数学期望】
题目:戳这里 思路来源:视频讲解 题意:有n个箱子按1...n标号,每个箱子有大小为di的钻石概率为pi,我们初始有个大小为0的钻石,从1到n按顺序打开箱子,遇到比手中大的箱子就换,求交换次数的数学期 ...
随机推荐
- 20162017-acmicpc-south-pacific-regional-contest-sppc-16 B.Ballon Warehouse
题意:给你一个无限长且元素均为\(0\)的排列,每次给你一对\((x,y)\),表示在所有\(x\)的后面插入一个元素\(y\),最后给你一个区间\((l,r)\),输出\([l,r-1]\)中的所有 ...
- Is It A Tree? POJ - 1308
题意: 题目给你一组单向边,当遇到输入0 0就证明这是一组边,当遇到-1 -1就要停止程序.让你判断这是不是一棵树 题解: 题目很简单,但是程序要考虑的很多 1.因为是一颗树,所以肯定不能出现环,这个 ...
- Atcoder Educational DP Contest I - Coins (概率DP)
题意:有\(n\)枚硬币,每枚硬币抛完后向上的概率为\(p[i]\),现在求抛完后向上的硬币个数大于向下的概率. 题解:我们用二维的\(dp[i][j]\)来表示状态,\(i\)表示当前抛的是第\(i ...
- 被收费绘图工具 PUA 了怎么办?来看看这个老实工具吧
本文非常适合 Electron 入门选手,墙裂推荐! 本文作者:HelloGitHub-蔡文心 大家好!这里是 HelloGitHub 推出的<讲解开源项目>系列,今天给大家带来的一款基于 ...
- 【cpp上】课后正误小题
State whether each of the following is true or false. If false, explain why. Assume the state ment u ...
- JQuery和js实现简单的霓虹灯
注意jquery文件的路径要正确. <!DOCTYPE html> <html> <head> <title></title> <me ...
- uni-app in action
uni-app in action uni-app 实战 $ npm run dev:%PLATFORM% $ npm run build:%PLATFORM% app-plus app平台生成打包资 ...
- ES2021 & Pipeline operator (|>) / 管道运算符 |>
ES2021 & Pipeline operator (|>) / 管道运算符 |> demo "use strict"; /** * * @author xg ...
- React useMemo
React useMemo react hooks https://reactjs.org/docs/hooks-reference.html#usememo useCallback & us ...
- js & Input & Paste & Clipboard & upload & Image
js & Input & Paste & Clipboard & upload & Image input paste upload image js Clip ...