链接:

https://vjudge.net/problem/CodeForces-939A

题意:

As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are n planes on Earth, numbered from 1 to n, and the plane with number i likes the plane with number fi, where 1 ≤ fi ≤ n and fi ≠ i.

We call a love triangle a situation in which plane A likes plane B, plane B likes plane C and plane C likes plane A. Find out if there is any love triangle on Earth.

思路:

刚开始以为拓扑排序,想了下直接找就行了,判断i 和 F[F[F[i]]].

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string>
#include <assert.h>
#define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL; const int MAXN = 5e3+10;
int F[MAXN];
int n; int main()
{
cin >> n;
for (int i = 1;i <= n;i++)
cin >> F[i];
bool flag = false;
for (int i = 1;i <= n;i++)
if (F[F[F[i]]] == i)
flag = true;
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl; return 0;
}

CodeForces-939A的更多相关文章

  1. Codeforces 939A题,B题(水题)

    题目链接:http://codeforces.com/problemset/problem/939/A A题 A. Love Triangle time limit per test 1 second ...

  2. CodeForces - 939A,解题报告

    题意:给出一个n个点有向图,问是否存在三个点,这三个点构成一个回路.n<=5000 模拟即可. 注意是必须三个点 多了居然不行. import java.util.*; public class ...

  3. 【CodeForces - 939A】Love Triangle(模拟)

    Love Triangle Descriptions: 正如你所知道的,没有男性飞机也没有女性飞机.然而,地球上的每一个平面都喜欢另一个平面.地球上有n个平面,编号从1到n,编号i的平面喜欢编号fi的 ...

  4. CCPC-Wannafly Summer Camp 2019 Day1

    A - Jzzhu and Cities CodeForces - 449B 题意:n座城市,m条路,k条铁路啥的吧,然后要求最多能删多少条铁路保持1到$n$的最短路不变. 思路:因为铁路是从1出发的 ...

  5. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  6. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  7. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  8. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  9. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  10. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. LeetCode.942-DI字符串匹配(DI String Match)

    这是悦乐书的第361次更新,第388篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第223题(顺位题号是942).给定仅包含I(增加)或D(减少)的字符串S,令N = S ...

  2. #Java学习之路——基础阶段二(第十三篇)

    我的学习阶段是跟着CZBK黑马的双源课程,学习目标以及博客是为了审查自己的学习情况,毕竟看一遍,敲一遍,和自己归纳总结一遍有着很大的区别,在此期间我会参杂Java疯狂讲义(第四版)里面的内容. 前言: ...

  3. Shell编程、part5

    本节内容 1. 三剑客简介 2. sed命令详解 3. awk命令详解 文本处理三剑客 在 Shell 下使用这些正则表达式处理文本最多的命令有下面几个工具: |                 命令 ...

  4. python基础--导入模块

    一,import的使用1, 模块就是一组功能的集合体,我们的程序可以导入模块来复用模块中的功能一个模块就是包含了一组功能的python文件,例如demo.py 可以通过import来使用这个文件定义d ...

  5. 10大IT社区

    技术社区导航 http://tooool.org/ 1. cnblogs 人多内容质量最高 2.csdn csdn的注册人数多,但新手多 3.java eye java eye注册用户刚突破10万,但 ...

  6. HDU 2973 YAPTCHA (威尔逊定理)

    YAPTCHA Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  7. MySQL出现 Access denied for user 'root'@'localhost' (using password:YES) 解决办法

    1.先停止MySQL服务,然后在MySQL安装目录(我的是C:\Program Files (x86)\MySQL\MySQL Server 5.1)找到my.ini文件,在最后一行添加skip-gr ...

  8. 在子类中,若要调用父类中被覆盖的方法,可以使用super关键字

    在子类中,若要调用父类中被覆盖的方法,可以使用super关键字. package text; class Parent {    int x;    public Parent()    {      ...

  9. Nmap Windows 版本时区显示乱码

    Nmap 版本 $ nmap --version Nmap version 7.80 ( https://nmap.org ) Platform: i686-pc-windows-windows Co ...

  10. Java编程思想读书笔记 第十章 内部类

    非静态内部类作用: 最基本的作用:名字隐藏和组织代码 用例:内部类不访问外部类的元素时可以直接new.(bad style!) 用例:通过外部类的非静态方法返回内部类的引用,这样隐含了内部类对象和其对 ...