zoukankan      html  css  js  c++  java
  • codeforce 599B Spongebob and Joke

    一道水题WA那么多发,也是醉了。f看成函数的话,其实就是判断一下反函数存不存在。

    坑点,只能在定义域内判断,也就是只判断b[i]。没扫一遍前不能确定Impossible。

    #include<bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    
    const int maxn = 1e5+10;
    
    int f[maxn], b[maxn], a[maxn];
    int g[maxn];
    bool mul[maxn];
    
    //#define LOCAL
    int main()
    {
    #ifdef LOCAL
        freopen("in.txt","r",stdin);
    #endif
        int n, m; scanf("%d%d",&n,&m);
        bool Abm = false;
        for(int i = 1; i <= n; i++){
            scanf("%d", f+i);
            if(g[f[i]]) mul[f[i]] = true;
            g[f[i]] = i;
        }
        for(int i = 1; i <= m; i++){
            scanf("%d", b+i);
        }
        bool Imp = false;
        for(int i = 1; i <= m; i++){
            if(!g[b[i]]) {
                Imp = true; break;
            }
            if(mul[b[i]]){
                Abm = true;
            }
            a[i] = g[b[i]];
        }
        if(Imp) puts("Impossible");
        else {
            if(Abm) puts("Ambiguity");
            else {
                puts("Possible");
                for(int i = 1; i <= m; i++){
                    printf("%d%c", a[i], i != m? ' ': '
    ');
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    每日一题(文化课)一题---------19/7/30
    XXXXX,这个域名
    CF1037E. Trips
    bzoj3124: [Sdoi2013]直径 树形dp two points
    luogu P3952 时间复杂度 模拟
    AGC016D
    CF444E. DZY Loves Planting
    模拟赛
    HDU 3949 XOR [线性基|高斯消元]
    博客搬家
  • 原文地址:https://www.cnblogs.com/jerryRey/p/4983234.html
Copyright © 2011-2022 走看看