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\n", ans[sz-1]);

    for (int i = 1; i <= cnt; i++) printf("%d\n", 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\n", s[0]-1); continue; }
        if (len == 2 && s[1] == ‘0‘ && s[0] == ‘1‘) { printf("%d\n", 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("");
    }
}

原文地址:https://www.cnblogs.com/ruthank/p/10663823.html

时间: 2024-08-28 14:32:54

The 2018 ACM-ICPC Asia Beijing Regional Contest的相关文章

2018-2019, ICPC, Asia Yokohama Regional Contest 2018 (Gym - 102082)

2018-2019, ICPC, Asia Yokohama Regional Contest 2018 A - Digits Are Not Just Characters 签到. B - Arithmetic Progressions 题意:从给定的集合中选出最多的数构成等差数列. 题解:数字排序后,设\(dp[i][j]\)表示等差数列最后一个数字为\(a[i]\),倒数第二个数字为\(a[j]\)的最大个数.然后对于每一位枚举 \(i\),\(lower\_bound()\)找有无合法的

ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Krak&#243;w

ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik's RectangleProblem B: What does the fox say?Problem C: Magical GCDProblem D: SubwayProblem E: EscapeProblem F: DraughtsProblem G: History courseProblem H: C

2018 ICPC Asia Jakarta Regional Contest

题目传送门 题号 A B C D E F G H I J K L 状态 Ο . . Ο . . . . Ο . . Ο Ο:当场 Ø:已补 .  :  待补 A. Edit Distance Thinking:kk pai爷 Code:kk 不能直接反转,比如"010101",直接反转后就变成"101010",右移一位,然后加个0就可以了. 所以要先统计01的数量,如果0大于1,就全变成1,1大于0,就全变成0(从数量上的改变就大于s/2了),相等的话,就看首位是0

2019-2020 ICPC, Asia Jakarta Regional Contest H. Twin Buildings

As you might already know, space has always been a problem in ICPC Jakarta. To cope with this, ICPC Jakarta is planning to build two new buildings. These buildings should have a shape of a rectangle of the same size. Now, their problem is to find lan

The 2017 ACM-ICPC Asia Beijing Regional Contest

地址 Rank Solved A B C D E F G H I J 51/384 4/10 . . ? . O O . O . O O: 当场通过 ?: 赛后通过 .: 尚未通过 A Domains unsolved B K-Dimensional Foil unsolved C Graph upsolved by chelly chelly's solution 很显然的思路就是莫队+并查集 但众所周知并查集可以支持可撤销,但不是很好支持可持久化 于是就可以用上回滚莫队的套路了,回滚莫队可以

2019-2020 ICPC, Asia Jakarta Regional Contest C. Even Path

Pathfinding is a task of finding a route between two points. It often appears in many problems. For example, in a GPS navigation software where a driver can query for a suggested route, or in a robot motion planning where it should find a valid seque

2014 ACM/ICPC Asia Regional Guangzhou Online Wang Xifeng&#39;s Little Plot HDU5024

一道好枚举+模拟题目.转换思维视角 这道题是我做的,规模不大N<=100,以为正常DFS搜索,于是傻乎乎的写了起来.各种条件限制模拟过程 但仔细一分析发现对每个点进行全部八个方向的遍历100X100X100^8 .100X100个点,每个点在走的时候8中选择,TLE 于是改为另一个角度: 以符合要求的点为拐弯点,朝两个垂直的方向走,求出最远的距离.这样只要对每个点各个方向的长度知道,组合一下对应的就OK. 避免了每个点深搜. PS:搜索的时候x,y写反了,导致构图出现问题,以后用[dy][dx]

HDU 5014 Number Sequence(2014 ACM/ICPC Asia Regional Xi&#39;an Online) 题解

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5014 Number Sequence Problem Description There is a special number sequence which has n+1 integers. For each number in sequence, we have two rules: ● ai ∈ [0,n] ● ai ≠ aj( i ≠ j ) For sequence a and sequ

hdu6206 Apple 2017 ACM/ICPC Asia Regional Qingdao Online

地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6206 题目: Apple Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 530    Accepted Submission(s): 172 Problem Description Apple is Taotao's favouri