这里只有第一个点对了,有无大佬康康

P3613 【深基15.例2】寄包柜

Tom336853 @ 2022-07-05 21:45:51

#include <iostream>
using namespace std;

int main(){
    int n, q;
    cin>> n>> q;
    int si[100001] = {0};
    int sj[100001] = {0};
    int a=0;
    for(int i=0; i<q; i++){
        cin>> a;
        if(a==1){
            int b;
            cin>> b;
            si[b] = 1;
            int c,d;
            cin>> c>> d;

            sj[c]=d;
        }
        if(a==2){
            int b, c;
            cin>>b>>c;
            if(si[b] == 1 && sj[c] != 0){
                cout<< sj[c]<< endl;
            }
            else cout<< "0"<< endl;
        }
    }
} 

by _cyle_King @ 2022-07-05 22:03:43

这做法显然有问题


by Tom336853 @ 2022-07-05 22:54:02

@_cyle_King 是我题目理解错了吗?可以举一个反例吗


by Tom336853 @ 2022-07-06 09:01:13

@Tom336853 确实有问题


by _cyle_King @ 2022-07-06 12:06:52

hack:

2 3
1 1 2 1
1 2 1 1
2 2 2

正确输出:

0

程序输出:

1

by _cyle_King @ 2022-07-06 12:07:53

参考程序:

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<map>
using namespace std;

map<int,map<int,int> >a;
int n,q;

int
main()
{
    scanf("%d%d",&n,&q);
    int op,x,y,k;
    for(int i=1;i<=q;i++)
    {
        scanf("%d%d%d",&op,&x,&y);
        if(op==1) scanf("%d",&k),a[x][y]=k;
        else printf("%d\n",a[x][y]);
    }
    return 0;
}

by Go_for_itligli666666 @ 2022-07-18 21:17:26

@_cyle_King 你这组数据不符合题目要求吧?题目说保证查询的柜子有存过东西


by _cyle_King @ 2022-07-18 22:58:46

@Go_for_itligli666666 换一组hack

2 3
1 1 2 1
1 2 2 2
2 1 2

正确答案

1

程序输出

2

by Sky_Line @ 2022-07-31 15:35:27

(先把代码放在这)
#include<bits/stdc++.h>
using namespace std;
struct node
{
    vector<int>q, w;
    int t;
}a[100010];
int n, m, k, x, y, z;
int main()
{
    scanf("%d %d", &n, &m);
    for(int i = 0; i < m; i++)
    {
        scanf("%d", &k);
        if(k == 1)
        {
            scanf("%d %d %d", &x, &y, &z);
            a[x].q.push_back(y);
            a[x].w.push_back(z);
            a[x].t++;
        }
        else if(k == 2)
        {
            scanf("%d %d", &x, &y);
            for(int j = a[x].t - 1; j >= 0; j--)
            {
                if(a[x].q[j] == y)
                {
                    printf("%d\n", a[x].w[j]);
                    break;
                }
            }
        }
    }
    return 0;
}

|