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按顺序打开箱子,遇到比手中大的箱子就换,求交换次数的数学期 ...
随机推荐
- Codeforces Round #646 (Div. 2) C. Game On Leaves(树上博弈)
题目链接:https://codeforces.com/contest/1363/problem/C 题意 有一棵 $n$ 个结点的树,每次只能取叶子结点,判断谁能最先取到结点 $x$ . 题解 除非 ...
- 【2020杭电多校】Distinct Sub-palindromes 找规律
题目链接:Distinct Sub-palindromes 题意: 给你一个长度n,你需要找出来一些串,这些串由A...Z和a...z构成.我们设长度为n的所有串中所包含回文子串最少的数量为ans.问 ...
- POJ 3189
题意: 给你B个谷仓和n头牛,每个谷仓最多容纳m头牛.此时每头牛对每一个谷仓都有一个喜悦值,你需要把每一头牛都安排某个谷仓内,并且找出来那个每一头牛对它所住的谷仓打的分值,我们对这所有的分值取一个区间 ...
- 【POJ 1148】Utopia Divided
Utopia Divided 题目链接:POJ 1148 题目大意 在一个坐标系中,一个点一开始在原点,然后被要求每次走到一个规定的象限内. 你有一些互不相同的数,每次你可以选每选过的两个,正负性可以 ...
- Yocto项目介绍及入门 -- 嵌入师工程师必备利器
目录 写在前面 1. Yocto项目是什么 2. Yocto项目有什么用 3. 如何快速上手Yocto项目 4. 带你通过Yocto项目编译一个自定义镜像文件 写在前面 博主目前从事BMC工作,由于公 ...
- URL parser All In One
URL parser All In One const url = new URL(`https://admin:1234567890@cdn.xgqfrms.xyz:8080/logo/icon.p ...
- React Hooks: useImperativeHandle All In One
React Hooks: useImperativeHandle All In One useImperativeHandle https://reactjs.org/docs/hooks-refer ...
- LeetCode 高效刷题路径
LeetCode 高效刷题路径 Hot 100 https://leetcode.com/problemset/hot-100/ https://leetcode-cn.com/problemset/ ...
- App Store Previewer
App Store Previewer App Store 模拟器 https://www.storepreviewer.com/ xgqfrms 2012-2020 www.cnblogs.com ...
- css border-radius & yin-yang & taiji
css border-radius & yin-yang & taiji solution css border-radius & tabs effect https://co ...