CodeForces-939A
链接:
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的更多相关文章
- Codeforces 939A题,B题(水题)
题目链接:http://codeforces.com/problemset/problem/939/A A题 A. Love Triangle time limit per test 1 second ...
- CodeForces - 939A,解题报告
题意:给出一个n个点有向图,问是否存在三个点,这三个点构成一个回路.n<=5000 模拟即可. 注意是必须三个点 多了居然不行. import java.util.*; public class ...
- 【CodeForces - 939A】Love Triangle(模拟)
Love Triangle Descriptions: 正如你所知道的,没有男性飞机也没有女性飞机.然而,地球上的每一个平面都喜欢另一个平面.地球上有n个平面,编号从1到n,编号i的平面喜欢编号fi的 ...
- CCPC-Wannafly Summer Camp 2019 Day1
A - Jzzhu and Cities CodeForces - 449B 题意:n座城市,m条路,k条铁路啥的吧,然后要求最多能删多少条铁路保持1到$n$的最短路不变. 思路:因为铁路是从1出发的 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- java:struts2.3框架1(struts2快速配置,各文件之间的关系,基础代码简化版,XML中的通配符)
1.struts2快速配置: A.到http://struts.apache.org下载struts2开发包struts-2.3.32-all.zip B.新建web项目并添加struts2依赖的ja ...
- docker搭建环境的时候常用的命令有哪些
1.docker搭建环境的时候常用的命令有哪些 docker如果要删除镜像,现在停止container docker ps 查询正在运行的镜像docker stop +containerid停止后再删 ...
- MySQL改密
一.未进入之前: 1.grep password /var/log/mysqld.log 得出默认密码2.更改密码 mysqladmin -uroot -p'd-tlbwIgP3e2' pa ...
- TensorFlow学习笔记0-安装TensorFlow环境
TensorFlow学习笔记0-安装TensorFlow环境 作者: YunYuan 转载请注明来源,谢谢! 写在前面 系统: Windows Enterprise 10 x64 CPU:Intel( ...
- 模版include的用法
from flask import Flask,render_template app = Flask(__name__) @app.route('/') def hello_world(): ret ...
- 超详细的CentOS8Linux新功能介绍 镜像iso下载安装
在这文章中,我们会使用图解的方式演示 CentOS 8 的安装方法. CentOS8中软件和系统管理请参照https://www.cnblogs.com/fusheng11711/p/11809963 ...
- hue数据导出
1/ 执行要下载的sql语句 2/ 执行完成后,点击下面导出 3.选择所有 4.选择每个人对应的文件夹,没有自己名称的可以创建一个 5.选择导出 6.右面是导出执行时的界面 7.选择已经执行的文件 ...
- springboot - 应用实践(N)使用springboot内置的@Scheduled
1.springboot开箱即用,内置调度任务的使用. 建一个简单的springboot工程,pom.xml: <?xml version="1.0" encoding=&q ...
- nginx配置本地域名反向代理实现本地多域名80访问
什么是反向代理? 代理:通过客户机的配置,实现让一台服务器代理客户机,客户的所有请求都交给代理服务器处理. 反向代理:用一台服务器,代理真实服务器,用户访问时,不再是访问真实服务器,而是代理服务器. ...
- Python文件的几种读写方式
1). "w "写模式,它是不能读的,如果用w模式打开一个已经存在的文件,会清空以前的文件内容,重新写 "w+ "是读写内容,只要沾上w,肯定会清空原来的文件2 ...