zoukankan      html  css  js  c++  java
  • The 2018 ACM-ICPC Asia Beijing Regional Contest

    训练时间:2019-03-31

    本场阿渠连出A和D,成功带我们晋级。

    I题我坚定的写Java,完全没往打表找规律上想。背锅。

    A - Jin Yong’s Wukong Ranking List (HihoCoder - 1870)

    给你n对拓扑关系,找出第一个不符合之前的拓扑关系的拓扑对。

    建图,每加入一对拓扑对 x -> y,看看从 y 是否能跑到 x 即可。

    #include <bits/stdc++.h>
    #define FOPI freopen("in.txt", "r", stdin);
    #define FOPO freopen("out.txt", "w", stdout);
    using namespace std;
    typedef long long LL;
    const int maxn = 2000 + 100;
    
    map<string, int> M;
    string s[maxn], t[maxn];
    vector<int> v[maxn];
    
    void build(int x, int y)
    {
        v[x].push_back(y);
    }
    
    int n;
    
    bool dfs(int x, int y)
    {
        for (int i = 0; i < v[x].size(); i++)
        {
            if (v[x][i] == y) return false;
            if (!dfs(v[x][i], y)) return false;
        }
        return true;
    }
    
    bool check()
    {
        M.clear();
        for (int i = 1; i <= n*2; i++) v[i].clear();
        int cnt = 0;
        for (int i = 1; i <= n; i++)
        {
            if (!M.count(s[i])) M[s[i]] = ++cnt;
            if (!M.count(t[i])) M[t[i]] = ++cnt;
            int x = M[s[i]], y = M[t[i]];
            build(x, y);
            if (!dfs(y, x))
            {
                cout << s[i] << " " << t[i] << endl;
                return false;
            }
        }
        return true;
    }
    
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    
        while(cin >> n)
        {
            for (int i = 1; i <= n; i++) cin >> s[i] >> t[i];
            if (check()) cout << 0 << endl;
        }
    }

    B - Heshen's Account Book (HihoCoder - 1871)

    坑巨多的模拟。幸好场上没开。

    #include <bits/stdc++.h>
    #define FOPI freopen("in.txt", "r", stdin);
    #define FOPO freopen("out.txt", "w", stdout);
    using namespace std;
    typedef long long LL;
    const int maxn = 200 + 100;
    
    string str[maxn];
    int l[maxn], tot[maxn];
    bool vis[maxn];
    vector<LL> ans;
    
    bool check(string s)
    {
        int len = s.length();
        for (int i = 0; i < len; i++)
            if (!isdigit(s[i])) return false;
        return true;
    }
    
    
    bool check_first(string s)
    {
        int len = s.length();
        int flag = 0;
        for (int i = len-1; i >= 0; i--)
        {
            if (isdigit(s[i])) flag++;
            else if (s[i] == ' ') return flag > 0;
            else return false;
        }
        return true;
    }
    
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    
        //FOPI;
    
        memset(vis, false, sizeof(vis));
    
        int cnt = 0;
        while(getline(cin, str[++cnt]));
        cnt--;
    
        bool flag = false;
        int i;
        for (i = 1; i <= cnt; i++)
        {
            string s = str[i];
            string last = "";
            int len = s.length();
    
            int tmp = i;
            if (check_first(s))
            {
                int j;
                for (j = i+1; j <= cnt; j++)
                    if (check(str[j])) s += str[j], vis[j] = true, tmp = cnt;
                    else { tmp = j-1; break; }
            }
    
            len = s.length();
            if (i != cnt && isdigit(s[len-1]) && isdigit(str[i+1][0]) && !vis[i+1])
            {
                vis[i+1] = true;
                for (int j = 0; j < str[i+1].length() && str[i+1][j] != ' '; j++) s += str[i+1][j];
            }
    
            stringstream ss;
            ss.str(s);
    
            string a;
            if (vis[i]) ss >> a;
            while(ss >> a)
            {
                int len = a.length();
                if (len > 1 && a[0] == '0') continue;
    
                if (isalpha(a[0]) || isalpha(a[len-1])) continue;
    
                LL sum = 0;
                for (int j = 0; j < len; j++)
                    if (isdigit(a[j])) sum = sum * 10 + a[j] - '0';
    
                ans.push_back(sum), tot[i]++;
            }
    
            i = tmp;
            if (i == cnt) break;
        }
    
        int sz = ans.size();
        for (int i = 0; i < sz-1; i++) printf("%lld ", ans[i]);
        printf("%lld
    ", ans[sz-1]);
    
        for (int i = 1; i <= cnt; i++) printf("%d
    ", tot[i]);
    }

    I - Palindromes (HihoCoder - 1878)

    打个表,找到规律。

    然后分类讨论就行了。

    #include <bits/stdc++.h>
    #define FOPI freopen("in.txt", "r", stdin);
    #define FOPO freopen("out.txt", "w", stdout);
    using namespace std;
    const int maxn = 100000 + 1000;
    
    int t;
    char s[maxn], r[maxn];
    
    int main()
    {
        scanf("%d", &t);
        for (int ca = 1; ca <= t; ca++)
        {
            scanf("%s", s);
            int len = strlen(s);
    
            if (len == 1) { printf("%c
    ", s[0]-1); continue; }
            if (len == 2 && s[1] == '0' && s[0] == '1') { printf("%d
    ", 9); continue; }
    
            if (s[0] == '1')
            {
                if (s[1] == '0')
                {
                    s[1] = '9';
                    for (int i = 1; i < len; i++) printf("%c", s[i]);
                    for (int i = len-2; i >= 1; i--) printf("%c", s[i]);
                }
                else
                {
                    for (int i = 1; i < len; i++) printf("%c", s[i]);
                    for (int i = len-1; i >= 1; i--) printf("%c", s[i]);
                }
            }
            else
            {
                s[0]--;
                printf("%s", s);
                for (int i = len-2; i >= 0; i--) printf("%c", s[i]);
            }
    
            puts("");
        }
    }
  • 相关阅读:
    数据库设计三大范式
    常用正则表达式
    全国省市县无刷新多级关联菜单
    可选择Email和用户名登录的代码
    注册与登录界面的美化
    只能输入汉字js脚本
    js确认删除对话框
    同步文本框内容的JS代码
    网站变灰代码
    悬浮右侧可展开搜索的客服代码
  • 原文地址:https://www.cnblogs.com/ruthank/p/10663823.html
Copyright © 2011-2022 走看看