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? ‘ ‘: ‘\n‘);
            }
        }
    }
    return 0;
}
时间: 2024-08-08 15:32:14

codeforce 599B Spongebob and Joke的相关文章

CodeForces 599B Spongebob and Joke

简单题. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const int maxn=100000+10; int n,m; int b[maxn],f[maxn]; int cnt[maxn]; int main() { scanf("%d%d",&n,&m); memset(cnt,

[cf 599B] Spongebob and Joke

判断题,有点绕,注意在答案不唯一时的判断条件要依据B数组判断 #include <iostream> #include <algorithm> #include <map> using namespace std; int b[110000],f[110000]; map <int,int> Map,A; int main() { int n,i,m; cin >> n >> m; for(i=1;i<=n;++i) { cin

Codeforces Round #332 (Div. 2) B. Spongebob and Joke 模拟

B. Spongebob and Joke While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence a1, a2, ..., am of length m, consisting of integers from 1

Codeforces Round #332 (Div. 二) B. Spongebob and Joke

Description While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence a1, a2, ..., am of length m, consisting of integers from 1 to n, not

[Codeforces599B] Spongebob and Joke (模拟)

题目概述: While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence a1, a2, ..., am of length m, consisting of integers from 1 to n, not neces

codeforce 599D Spongebob and Squares

很容易得到n × m的方块数是 然后就是个求和的问题了,枚举两者中小的那个n ≤ m. 然后就是转化成a*m + c = x了.a,m≥0,x ≥ c.最坏是n^3 ≤ x,至于中间会不会爆,测下1e18就好. #include<bits/stdc++.h> using namespace std; typedef long long ull; vector<ull> ns; vector<ull> ms; //#define LOCAL int main() { #i

Codeforces Round #332 (Div. 2)

好菜,不说话了,说题. A - Patrick and Shopping 从一个点出发,要经过其他两个点,然后回到原地,求最小时间花费.只有四种情况,从中选一个最小的就行了. #include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <math.h> #include <algorithm> using namespace

2017-5-18-Train: Codeforces Round #332 (Div. 2)

A. Patrick and Shopping(模拟题) Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a d1 meter long road between his house and the first sh

hdu 4969 Just a Joke(积分)

题目链接:hdu 4969 Just a Joke 题目大意:Guizeyanhua要去追一个女孩,女孩在以Guizeyanhua为圆心,半径为R的圆上匀速运动,女孩的速度为v1,Guizeyanhua的速度为v2,半径为R,Guizeyanhua腿疼只能跑距离D.现在Guizeyanhua要去追女孩,前提条件是女孩,Guizeyanhua,圆心必须保持共线. 解题思路:因为有三点要共线的条件,所以Guizeyanhua和女孩的线速度必须相同,所以有v1R=vxr(vx为Guizeyanhua在