水题----B - Badge CodeForces - 1020B
In Summer Informatics School, if a student doesn't behave well, teachers make a hole in his badge. And today one of the teachers caught a group of n
students doing yet another trick.
Let's assume that all these students are numbered from 1
to n. The teacher came to student a and put a hole in his badge. The student, however, claimed that the main culprit is some other student pa
.
After that, the teacher came to student pa
and made a hole in his badge as well. The student in reply said that the main culprit was student ppa
.
This process went on for a while, but, since the number of students was finite, eventually the teacher came to the student, who already had a hole in his badge.
After that, the teacher put a second hole in the student's badge and decided that he is done with this process, and went to the sauna.
You don't know the first student who was caught by the teacher. However, you know all the numbers pi
. Your task is to find out for every student a, who would be the student with two holes in the badge if the first caught student was a
.
Input
The first line of the input contains the only integer n
(1≤n≤1000
) — the number of the naughty students.
The second line contains n
integers p1, ..., pn (1≤pi≤n), where pi indicates the student who was reported to the teacher by student i
.
Output
For every student a
from 1 to n print which student would receive two holes in the badge, if a
was the first student caught by the teacher.
Examples
3
2 3 2
2 2 3
3
1 2 3
1 2 3
Note
The picture corresponds to the first example test case.
When a=1
, the teacher comes to students 1, 2, 3, 2, in this order, and the student 2
is the one who receives a second hole in his badge.
When a=2
, the teacher comes to students 2, 3, 2, and the student 2 gets a second hole in his badge. When a=3, the teacher will visit students 3, 2, 3 with student 3
getting a second hole in his badge.
For the second example test case it's clear that no matter with whom the teacher starts, that student would be the one who gets the second hole in his badge.
题解:输入写成数组,然后循环,循环到谁num++,如果num==2输出
ac代码:
#include<iostream>
#include<cstring>
using namespace std;
int a[1100];
int main()
{
int fl,n,x;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++)
{
int b[1100]={0};
b[i]++;
x=a[i];
for(;;)
{
b[x]++;
if(b[x]==2) break;
x=a[x];
}
if(i==1) cout<<x;
else cout<<' '<<x;
}
cout<<endl;
return 0;
}
水题----B - Badge CodeForces - 1020B的更多相关文章
- 水题 Codeforces Round #302 (Div. 2) A Set of Strings
题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...
- 水题 Codeforces Round #300 A Cutting Banner
题目传送门 /* 水题:一开始看错题意,以为是任意切割,DFS来做:结果只是在中间切出一段来 判断是否余下的是 "CODEFORCES" :) */ #include <cs ...
- Codeforces Testing Round #8 B. Sheldon and Ice Pieces 水题
题目链接:http://codeforces.com/problemset/problem/328/B 水题~ #include <cstdio> #include <cstdlib ...
- Codeforces Round #356 (Div. 2)B. Bear and Finding Criminals(水题)
B. Bear and Finding Criminals time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)
Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...
- Educational Codeforces Round 7 B. The Time 水题
B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...
- Educational Codeforces Round 7 A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...
- Codeforces Gym 100531G Grave 水题
Problem G. Grave 题目连接: http://codeforces.com/gym/100531/attachments Description Gerard develops a Ha ...
- Codeforces Round #290 (Div. 2) A. Fox And Snake 水题
A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...
随机推荐
- 车辆运动控制算法——MPC
MPC是模型预测控制算法,在车辆运动跟踪轨迹的控制中发挥很大的优势 基础的不多说,下面记录我对LQR/MPC/二次规划问题的理解 我们从LQR来引出MPC LQR的能量函数,目的是求函数J最小,即用最 ...
- 新手安装配置git简洁教程
第一步,下载安装git 打开 [git官网] https://git-scm.com/,下载git对应操作系统的版本. 所有东西下载慢的话就可以去找镜像!官网下载太慢,我们可以使用淘宝镜像下载:htt ...
- BootstrapDialog.confirm确认对话框
1. 依赖文件: bootstrap.js bootstrap-dialog.js bootstrap.css bootstrap-dialog.css 2.代码 BootstrapDialog.co ...
- 不就是语法和长难句吗—笔记总结Day1
CONTENTS 第一课 简单句 第二课 并列句 第三课 名词(短语)和名词性从句 第四课 定语和定语从句 第五课 状语和状语从句 第六课 英语的特殊结构 第一课 奋斗的开始——简单句 一.什么是英语 ...
- 利用 Nginx 实现限流
在当下互联网高并发时代中,项目往往会遇到需要限制客户端连接的需求.我们熟知的 Nginx 就提供了有这样的功能,可以简单的实现对客户端请求频率,并发连接和传输速度的限制…. Nginx 限流 Ngin ...
- Linux CentOS 7 下dotnet core webpai + nginx 部署
参考:https://www.jianshu.com/p/b1f573ca50c7 跟着做到,配置nginx访问dotnet core网站时,报错了. 错误如下所示—— 查看nginx的错误日志: c ...
- 多线程下的list
前言 list 是 Python 常用的几个基本数据类型之一.正常情况下我们会对 list 有增删改查的操作,显然易见不会有任何问题.那么如果我们试着在多线程下操作list 会有问题吗? 多线程下的 ...
- 从别人的代码中学习golang系列--02
这篇博客还是整理从https://github.com/LyricTian/gin-admin 这个项目中学习的golang相关知识 作者在项目中使用了https://github.com/googl ...
- Demo_2:Qt实现猜字小游戏
1 环境 系统:windows 10 代码编写运行环境:Qt Creator 4.4.1 (community) Github: 2 简介 参考视频:https://www.bilibili.co ...
- 使用 Egg + Vue 的第一个线上小产品——远程工作职位信息收集站点 yuancheng.works
小插曲 开始很纠结,买了一个 yuancheng.works 域名会不会冒犯到 yuancheng.work 站长. 还在群里咨询了 @Phodal 等前辈.重新搞一个新域名,yuancheng.wo ...