AcWing 1977. 信息中继 + 模拟
原题链接
简单
作者:
_Unravel_
,
2022-04-28 09:08:35
,
所有人可见
,
阅读 469
- 要么有环,要么无环
- 按序遍历每一条转发路径
- 若有环,必定有点会重复出现
- 若无环,必定会走到不转发信息的点
#include<cstring>
#include<iostream>
using namespace std;
const int N = 1010;
int n, nums[N];
bool vis[N];
int main() {
cin>>n;
for(int i = 1; i <= n; i++) cin>>nums[i];
int res = 0;
for(int i = 1; i <= n; i++) {
memset(vis, 0, sizeof vis);
int t = nums[i];
while(!vis[t] && t != 0) {
vis[t] = true;
t = nums[t];
}
if(t == 0) res += 1;
}
cout<<res<<endl;
return 0;
}
#include[HTML_REMOVED]
#include[HTML_REMOVED]
#include[HTML_REMOVED]
using namespace std;
const int N = 10001;
int main(){
int n;
cin>>n;
int a[N];
bool b[N];
for(int i=1;i<=n;i++)cin>>a[i];
int ans=0;
}
帮我看看我的,我这就差直接把变量抄的和你一样的了,但就是跑不出来
好评!
谢谢!