任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6370

Werewolf

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 2680    Accepted Submission(s): 806

Problem Description
"The Werewolves" is a popular card game among young people.In the basic game, there are 2 different groups: the werewolves and the villagers.

Each player will debate a player they think is a werewolf or not.

Their words are like "Player x is a werewolf." or "Player x is a villager.".

What we know is :

1. Villager won't lie.

2. Werewolf may lie.

Of cause we only consider those situations which obey the two rules above.

It is guaranteed that input data exist at least one situation which obey the two rules above.

Now we can judge every player into 3 types :

1. A player which can only be villager among all situations,

2. A player which can only be werewolf among all situations.

3. A player which can be villager among some situations, while can be werewolf in others situations.

You just need to print out the number of type-1 players and the number of type-2 players.

No player will talk about himself.

 
Input
The first line of the input gives the number of test cases T.Then T test cases follow.

The first line of each test case contains an integer N,indicating the number of players.

Then follows N lines,i-th line contains an integer x and a string S,indicating the i-th players tell you,"Player x is a S."

limits:

1≤T≤10

1≤N≤100,000

1≤x≤N

S∈ {"villager"."werewolf"}

 
Output
For each test case,print the number of type-1 players and the number of type-2 players in one line, separated by white space.
 
Sample Input
1
2
2 werewolf
1 werewolf
 
Sample Output
0 0
 
Source

题意概括:

读题意前要清空一下记忆,这里的狼人杀和实际的狼人杀规则不太一样。

每人按顺序说出一个人的角色(不能说自己的)

1、村民一定说真话

2、狼人有可能说假话。

求:

一定是村民的数量 和 一定是狼人的数量。

解题思路:

模拟了一下,感觉并不会有村民,因为没有方案可以证明出某个人一定是村民,因为狼人有“可能”说谎。

但我们可以确认哪些一定是狼人,即存在环,环的最后是 狼人边,其余都是村民边,那么被狼人边指的一定是狼人。

而用村民边指向这个狼人的角色也一定是狼人。

那么DFS,村民边建正向边,狼人边建反向边。

遍历狼人边,判断是否存在上述的环,如果存在再继续拓展。

大佬的证明:https://blog.csdn.net/weixin_39453270/article/details/81515570

AC code:

 #include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
const int MAXN = 1e5+; int N, M;
int w[MAXN];
vector<int>fa[MAXN], son[MAXN];
bool vis[MAXN];
int ans[MAXN], cnt; void add1(int a, int b)
{
fa[a].push_back(b);
} bool dfs(int a, int b)
{
bool flag = true;
for(int i = ; i < fa[a].size(); i++){
if(fa[a][i] == b) return false;
flag = dfs(fa[a][i], b);
if(!flag) return false;
}
return flag;
} void dfs2(int x)
{
if(!vis[x]) return;
vis[x] = false;
for(int i = ; i < fa[x].size(); i++){
if(vis[fa[x][i]]){
cnt++;
dfs2(fa[x][i]);
}
}
} int main()
{
//freopen("6370in.txt", "r", stdin);
int T_case, id, tot = ;
char ty[];
scanf("%d", &T_case);
while(T_case--){
cnt = ;
tot = ;
memset(vis, , sizeof(vis));
scanf("%d", &N);
for(int i = ; i <= N; i++){ fa[i].clear();son[i].clear();} for(int i = ; i <= N; i++){
scanf("%d %s", &id, &ty);
if(ty[] == 'w'){
w[++tot] = i;
son[i].push_back(id);
}
else{
add1(id, i);
}
}
for(int i = ; i <= tot; i++){
if(!vis[w[i]]) continue;
for(int k = ; k < son[w[i]].size();k++){
if(!vis[son[w[i]][k]]) continue;
if(!dfs(w[i], son[w[i]][k])){
//puts("zjy");
cnt++;
dfs2(son[w[i]][k]);
}
}
} printf("0 %d\n", cnt);
}
}

最新文章

  1. WPF standard ComboBox Items Source Change Issue
  2. iOS:集成支付宝支付
  3. 中颖4位MCU的减法汇编指令
  4. Run_Product Example Form - Oracle Forms 6i
  5. 轻松学习 red5 教程 像视频一样很详细还有代码直接可Copy
  6. start-stop-daemon 命令
  7. javaScript获取指定的cookie值
  8. Css 使div标签下沉到页面最低部
  9. Python os模块--路径、文件、系统命令等操作
  10. Jetson TX2上的demo(原创)
  11. windows下ruby使用tk编程的方法
  12. app后端设计(9)-- 动态通知
  13. Thymeleaf--:fragment
  14. Codeforces 997 C - Sky Full of Stars
  15. Java获取路径(getResource)
  16. FFMPEG 中dts和pts区别
  17. idea操作快捷键
  18. 3ds Max从入门到精通
  19. Android成长之路-实现简单动画
  20. 我在Facebook学到的10个经验

热门文章

  1. WebStorm 用法集合
  2. Silverlight &amp; Blend动画设计系列四:倾斜动画(SkewTransform)
  3. easyui+nodejs+sqlserver增删改查实现
  4. jsp servlet基础复习 Part1
  5. 我的Java编码规范
  6. crontab 切割日志
  7. jquery文本框textarea自适应高度
  8. SPOJ2666 QTREE4
  9. ASPF(Application Specific Packet Filter)
  10. c# 利用反射 从json字符串 动态创建类的实例 并动态为实例成员赋值