水题----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 ...
随机推荐
- Python分支结构与流程控制
Python分支结构与流程控制 分支结构 if 语句 分支结构在任何编程语言中都是至关重要的一环,它最主要的目的是让计算机拥有像人一样的思想,能在不同的情况下做出不同的应对方案,所以if语句不管是在什 ...
- 字节流,读取 a.txt 文件内容,并打印出来
import java.io.FileInputStream;import java.io.IOException; /** 字节流,读取 a.txt 文件内容,并打印出来 */public clas ...
- github Pull Request合入全流程介绍
图解全流程 详细步骤 1. fork仓库 2. clone fork仓库到本地 3. 关联upstream原仓库 在fork本地仓库输入下面命令进行关联: git remote add upstrea ...
- JavaWeb项目在浏览器点击几次就阻塞了
问题描述 在学习JavaWeb项目时,通过IDE启动项目后,在浏览器点击几次页面中的链接就阻塞了,浏览器一直转圈圈无法加载,后台日志也没有输出. 第一次遇见这种情况,没有日志完全无法分析到底是什么问题 ...
- 一.2.序列化使用之用户资源功能app
1.环境准备:(1).新建功能app: (python36env) [vagrant@CentOS7 devops]$ python manage.py startapp users ---建议以后用 ...
- vs 打开项目,发现项目中通过nuget引用的dll都不可用的解决方法
把项目文件夹下的package文件删除,再重新生成项目,就会自动从nuget上下载了.
- 新建Maven项目出错
创建完项目后出现 弹出个窗口 出现如下信息 问题: Maven新建项目出现 Could not calculate build plan:plugin 错误解决办法 解决办法: 删除本地.m2仓库中 ...
- Html5标签——Html5新增标签的含义和使用
HTML 5 是一个新的网络标准,目标在于取代现有的 HTML 4.01, XHTML 1.0 and DOM Level 2 HTML 标准.它希望能够减少浏览器对于需要插件的丰富性网络应用服务(p ...
- JavaScript图形实例:H分形
H分形是由一个字母H演化出迷宫一样场景的分形图案,其构造过程是:取一个中心点(x,y),以此中心点绘制一条长为L的水平直线和两条长为H的竖直直线,构成一个字母“H”的形状:再以两条竖直直线的上下共4个 ...
- Maven 专题(六):Maven核心概念详解(二)
5 仓库 5.1 分类 [1]本地仓库:为当前本机电脑上的所有 Maven 工程服务.[2]远程仓库: (1)私服:架设在当前局域网环境下,为当前局域网范围内的所有 Maven 工程服务 ...