zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    DeepLearning之路(三)MLP
    DeepLearning之路(二)SoftMax回归
    DeepLearning之路(一)逻辑回归
    自然语言处理工具
    一个 11 行 Python 代码实现的神经网络
    对联广告
    Java多线程
    QT数据库操作
    QT笔记
    C++基础入门
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11361067.html
Copyright © 2011-2022 走看看