HDU 6370 Werewolf 【并查集】

任意门: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:

1T10

1N100,000

1xN

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.youkuaiyun.com/weixin_39453270/article/details/81515570

AC code:

 1 #include <bits/stdc++.h>
 2 #define INF 0x3f3f3f3f
 3 #define LL long long
 4 using namespace std;
 5 const int MAXN = 1e5+10;
 6 
 7 int N, M;
 8 int w[MAXN];
 9 vector<int>fa[MAXN], son[MAXN];
10 bool vis[MAXN];
11 int ans[MAXN], cnt;
12 
13 void add1(int a, int b)
14 {
15     fa[a].push_back(b);
16 }
17 
18 bool dfs(int a, int b)
19 {
20     bool flag = true;
21     for(int i = 0; i < fa[a].size(); i++){
22         if(fa[a][i] == b) return false;
23         flag = dfs(fa[a][i], b);
24         if(!flag) return false;
25     }
26     return flag;
27 }
28 
29 void dfs2(int x)
30 {
31     if(!vis[x]) return;
32     vis[x] = false;
33     for(int i = 0; i < fa[x].size(); i++){
34         if(vis[fa[x][i]]){
35             cnt++;
36             dfs2(fa[x][i]);
37         }
38     }
39 }
40 
41 int main()
42 {
43     //freopen("6370in.txt", "r", stdin);
44     int T_case, id, tot = 0;
45     char ty[10];
46     scanf("%d", &T_case);
47     while(T_case--){
48         cnt = 0;
49         tot = 0;
50         memset(vis, 1, sizeof(vis));
51         scanf("%d", &N);
52         for(int i = 1; i <= N; i++){ fa[i].clear();son[i].clear();}
53 
54         for(int i = 1; i <= N; i++){
55             scanf("%d %s", &id, &ty);
56             if(ty[0] == 'w'){
57                 w[++tot] = i;
58                 son[i].push_back(id);
59             }
60             else{
61                 add1(id, i);
62             }
63         }
64         for(int i = 1; i <= tot; i++){
65             if(!vis[w[i]]) continue;
66             for(int k = 0; k < son[w[i]].size();k++){
67                 if(!vis[son[w[i]][k]]) continue;
68                 if(!dfs(w[i], son[w[i]][k])){
69                     //puts("zjy");
70                     cnt++;
71                     dfs2(son[w[i]][k]);
72                 }
73             }
74         }
75 
76         printf("0 %d\n", cnt);
77     }
78 }

 

【无人机】基于改进粒子群算法的无人机路径规划研究[和遗传算法、粒子群算法进行比较](Matlab代码实现)内容概要:本文围绕基于改进粒子群算法的无人机路径规划展开研究,重点探讨了在复杂环境中利用改进粒子群算法(PSO)实现无人机三维路径规划的方法,并将其与遗传算法(GA)、标准粒子群算法等传统优化算法进行对比分析。研究内容涵盖路径规划的多目标优化、避障策略、航路点约束以及算法收敛性和寻优能力的评估,所有实验均通过Matlab代码实现,提供了完整的仿真验证流程。文章还提到了多种智能优化算法在无人机路径规划中的应用比较,突出了改进PSO在收敛速度和全局寻优方面的优势。; 适合人群:具备一定Matlab编程基础和优化算法知识的研究生、科研人员及从事无人机路径规划、智能优化算法研究的相关技术人员。; 使用场景及目标:①用于无人机在复杂地形或动态环境下的三维路径规划仿真研究;②比较不同智能优化算法(如PSO、GA、蚁群算法、RRT等)在路径规划中的性能差异;③为多目标优化问题提供算法选型和改进思路。; 阅读建议:建议读者结合文中提供的Matlab代码进行实践操作,重点关注算法的参数设置、适应度函数设计及路径约束处理方式,同时可参考文中提到的多种算法对比思路,拓展到其他智能优化算法的研究与改进中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值