zoukankan      html  css  js  c++  java
  • UCF Local Programming Contest 2014

    E

    判断是否有死循环

    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <iomanip>
    #include <deque>
    #include <bitset>
    #define ll              long long
    #define PII             pair<int, int>
    #define rep(i,a,b)      for(int  i=a;i<=b;i++)
    #define dec(i,a,b)      for(int  i=a;i>=b;i--)
    #define pb              push_back
    #define mk              make_pair
    using namespace std;
    int dir[4][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } };
    const long long INF = 0x7f7f7f7f7f7f7f7f;
    const int inf = 0x3f3f3f3f;
    const double pi = 3.14159265358979323846;
    const int mod = 998244353;
    const int N = 50 + 5;
    //if(x<0 || x>=r || y<0 || y>=c)
    
    inline ll read()
    {
        ll x = 0; bool f = true; char c = getchar();
        while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
        while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
        return f ? x : -x;
    }
    
    ll gcd(ll m, ll n)
    {
        return n == 0 ? m : gcd(n, m % n);
    }
    ll lcm(ll m, ll n)
    {
        return m * n / gcd(m, n);
    }
    
    int main()
    {
        int t;
        cin >> t;
        rep(q, 1, t)
        {
            int p, s;
            cin >> p >> s;
            vector<string> name(p + 1);
            vector<vector<int>> g(p + 1,vector<int>(p+1,0));
            rep(i, 1, p)
            {
                cin >> name[i];
            }
            rep(i, 1, p)
            {
                int n;
                cin >> n;
                rep(j, 1, n)
                {
                    int t;
                    cin >> t;
                    g[i][t] = 1;
                }
            }
            rep(i, 1, p)
            {
                rep(j, 1, p)
                {
                    rep(k, 1, p)
                    {
                        g[j][k] |= g[j][i] & g[i][k];
                    }
                }
            }
            vector<bool> cycle(p + 1,0);
            rep(i, 1, p)
            {
                if (g[i][i])
                    cycle[i] = 1;
            }
            vector<bool> infi(p + 1,0);
            rep(i, 1, p)
            {
                if (g[s][i] && cycle[i])
                    infi[i] = 1;
            }
            bool change = 1;
            while (change)
            {
                change = 0;
                rep(i, 1, p)
                {
                    if (infi[i])
                    {
                        rep(j, 1, p)
                        {
                            if (g[i][j] && !infi[j])
                            {
                                infi[j] = 1;
                                change = 1;
                            }
                        }
                    }
                }
            }
            int cnt = 0;
            rep(i, 1, p)
            {
                if (infi[i])
                    cnt++;
            }
            if (cnt == 0)
                cout << "Chain Email #" << q << ":
    " << "Safe chain email!" << endl;
            else
            {
                cout << "Chain Email #" << q << ":" << endl;
                rep(i, 1, p)
                {
                    if (infi[i])
                        cout << name[i] << " ";
                }
                cout << endl;
            }
            cout << endl;
        }
        return 0;
    }


    J

    对阶乘计算

    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <iomanip>
    #include <deque>
    #include <bitset>
    #define ll              long long
    #define PII             pair<int, int>
    #define rep(i,a,b)      for(int  i=a;i<=b;i++)
    #define dec(i,a,b)      for(int  i=a;i>=b;i--)
    #define pb              push_back
    #define mk              make_pair
    using namespace std;
    int dir[4][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } };
    const long long INF = 0x7f7f7f7f7f7f7f7f;
    const int inf = 0x3f3f3f3f;
    const double pi = 3.14159265358979323846;
    const int mod = 998244353;
    const int N = 50 + 5;
    //if(x<0 || x>=r || y<0 || y>=c)
    
    inline ll read()
    {
        ll x = 0; bool f = true; char c = getchar();
        while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
        while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
        return f ? x : -x;
    }
    
    ll gcd(ll m, ll n)
    {
        return n == 0 ? m : gcd(n, m % n);
    }
    ll lcm(ll m, ll n)
    {
        return m * n / gcd(m, n);
    }
    
    int main()
    {
        int t;
        cin >> t;
        rep(q, 1, t)
        {
            int p, s;
            cin >> p >> s;
            vector<string> name(p + 1);
            vector<vector<int>> g(p + 1,vector<int>(p+1,0));
            rep(i, 1, p)
            {
                cin >> name[i];
            }
            rep(i, 1, p)
            {
                int n;
                cin >> n;
                rep(j, 1, n)
                {
                    int t;
                    cin >> t;
                    g[i][t] = 1;
                }
            }
            rep(i, 1, p)
            {
                rep(j, 1, p)
                {
                    rep(k, 1, p)
                    {
                        g[j][k] |= g[j][i] & g[i][k];
                    }
                }
            }
            vector<bool> cycle(p + 1,0);
            rep(i, 1, p)
            {
                if (g[i][i])
                    cycle[i] = 1;
            }
            vector<bool> infi(p + 1,0);
            rep(i, 1, p)
            {
                if (g[s][i] && cycle[i])
                    infi[i] = 1;
            }
            bool change = 1;
            while (change)
            {
                change = 0;
                rep(i, 1, p)
                {
                    if (infi[i])
                    {
                        rep(j, 1, p)
                        {
                            if (g[i][j] && !infi[j])
                            {
                                infi[j] = 1;
                                change = 1;
                            }
                        }
                    }
                }
            }
            int cnt = 0;
            rep(i, 1, p)
            {
                if (infi[i])
                    cnt++;
            }
            if (cnt == 0)
                cout << "Chain Email #" << q << ":
    " << "Safe chain email!" << endl;
            else
            {
                cout << "Chain Email #" << q << ":" << endl;
                rep(i, 1, p)
                {
                    if (infi[i])
                        cout << name[i] << " ";
                }
                cout << endl;
            }
            cout << endl;
        }
        return 0;
    }
  • 相关阅读:
    Android全局变量的定义与使用
    安卓4.0/4.1/4.2手机怎么打开USB调试模式
    Android中的DDMS进行调试
    Runtime.getRuntime().exec执行阻塞问题解决
    GC_EXTERNAL_ALLOC freed 与 GC_EXPLICIT freed 是什么?
    [基础]Android 应用的启动
    Android popupwindow 失去焦点或者点击空白区域时消失的解决方法
    [问题]Android listView item edittext 不能调用软键盘输入法
    Android greenDAO 数据库 简单学习之基本使用
    Java 找出四位数的所有吸血鬼数字 基础代码实例
  • 原文地址:https://www.cnblogs.com/dealer/p/13028158.html
Copyright © 2011-2022 走看看