【CodeForces - 939A】Love Triangle(模拟)
Love Triangle
Descriptions:
正如你所知道的,没有男性飞机也没有女性飞机。然而,地球上的每一个平面都喜欢另一个平面。地球上有n个平面,编号从1到n,编号i的平面喜欢编号fi的平面,其中1≤fi≤n且fi≠i。
我们把平面A喜欢平面B,平面B喜欢平面C,平面C喜欢平面a的情况称为“三角恋”。
Input
第一行包含一个整数n(2≤n≤5000)——面数。
第二行包含n个整数f1 f2…, fn(1≤fi≤n, fi≠i),表示第i个平面喜欢第fi个平面。
Output
输出"YES"如果地球上有一个由平面组成的三角恋。否则,输出"NO"。
Input5
2 4 5 1 3
OutputYES
Input5
5 5 5 5 1
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 1100000
using namespace std;
int n;
int a[Maxn];
int main()
{
cin>>n;
for(int i=;i<=n;i++)
cin>>a[i];
int f=;
for(int i=;i<=n;i++)
{
int cnt=;//三角恋 当前次数为1
int init=i;
int x=i;
int y;
while(cnt<=&&x<=n)
{
y=a[x];
x=y;
cnt++;
}
if(x==init)
{
f=;
cout<<"YES"<<endl;
break;
}
}
if(f==)
cout<<"NO"<<endl; }
【CodeForces - 939A】Love Triangle(模拟)的更多相关文章
- Codeforces 738D. Sea Battle 模拟
D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...
- Codeforces 626A Robot Sequence(模拟)
A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- CodeForces - 589D(暴力+模拟)
题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...
- Codeforces 767B. The Queue 模拟题
B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces 939A题,B题(水题)
题目链接:http://codeforces.com/problemset/problem/939/A A题 A. Love Triangle time limit per test 1 second ...
- hdu4488 Faulhaber’s Triangle(模拟题)
Faulhaber’s Triangle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- Codeforces 704A Thor 队列模拟
题目大意:托尔有一部手机可执行三种操作 1.x APP产生一个新消息 2.读取x App已产生的所有消息 3.读取前t个产生的消息 问每次操作后未读取的消息的数量 题目思路: 队列模拟,坑点在于竟然卡 ...
- CodeForces - 939A,解题报告
题意:给出一个n个点有向图,问是否存在三个点,这三个点构成一个回路.n<=5000 模拟即可. 注意是必须三个点 多了居然不行. import java.util.*; public class ...
- Vasya And The Mushrooms CodeForces - 1016C (前缀和模拟)
大意: 给定2*n的矩阵, 每个格子有权值, 走到一个格子的贡献为之前走的步数*权值, 每个格子只能走一次, 求走完所有格子最大贡献. 沙茶模拟打了一个小时总算打出来了 #include <io ...
随机推荐
- sqlite3.OperationalError: no such table: account_user
你可能是在项目中安装了多个app, 首先删除相关app的migration文件中的子文件 执行建表的时候使用: python manage.py makemigrations appname pyth ...
- C# 泛型(4) 持续更新
泛型可以创建独立于被包含类型的类和方法. C++模板与泛型相似. 泛型优点性能 System.Collections 和 System.Collections.Generic 名称空间泛型和非泛型集合 ...
- Bootstrap-轮播图-No.4
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...
- “景驰科技杯”2018年华南理工大学程序设计竞赛 A. 欧洲爆破(思维+期望+状压DP)
题目链接:https://www.nowcoder.com/acm/contest/94/A 题意:在一个二维平面上有 n 个炸弹,每个炸弹有一个坐标和爆炸半径,引爆它之后在其半径范围内的炸弹也会爆炸 ...
- Codeforces Round #589 (Div. 2) E. Another Filling the Grid(DP, 组合数学)
链接: https://codeforces.com/contest/1228/problem/E 题意: You have n×n square grid and an integer k. Put ...
- python中导包简介
以pycharm中为例 1.创建一个python package,就是创建一个包,注意,创建Directory和创建python package之间的不同,前者只是一个文件夹,不是包,后者是包.包里有 ...
- JetBrains IDE 基本快捷键
转载自:https://nextfe.com/jetbrains-ide-shortcuts/ 一个好的手艺人很熟悉他的工具.软件开发者也不例外.所以,在编程的过程中,值得了解一些键盘快捷键,以免因为 ...
- nodejs豆瓣爬虫
从零开始nodejs系列文章,将介绍如何利Javascript做为服务端脚本,通过Nodejs框架web开发.Nodejs框架是基于V8的引擎,是目前速度最快的Javascript引擎.chrome浏 ...
- chrome获取xpath元素-f12工具
Chrome浏览器获取XPATH的方法----通过开发者工具获取 引用源:https://blog.csdn.net/li6727975/article/details/46126079 版权声明 ...
- ubuntu 安装eclipse for c++
linux的GUI和windos比起来实在逊色,虽然它的终端模式(命令行模式)非常强大.linux发行版ubuntu的GUI相对其他版本要华丽一些,所以最近由redhat转向ubuntu进行linux ...