QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#508505#2615. Surround the CatZhouShang#WA 4ms3840kbC++143.4kb2024-08-07 16:36:562024-08-07 16:36:58

Judging History

你现在查看的是最新测评结果

  • [2024-08-07 16:36:58]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:3840kb
  • [2024-08-07 16:36:56]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
vector <pair<int,int>> sp;
map <pair<int,int>,int> id;
int dis[305],xx[305],yy[305],f[305],bd[305];
vector <int> v[305];
int dx[6]={1,0,-1,-1,0,1},dy[6]={1,1,0,-1,-1,0};
void print(int x,int y){
    printf("%d %d\n",x,y);
    fflush(stdout);
}
int main() {
    sp.push_back({8,0}),sp.push_back({9,2}),sp.push_back({9,3}),sp.push_back({8,4});
    sp.push_back({9,6}),sp.push_back({9,7});
    sp.push_back({8,8}),sp.push_back({7,9}),sp.push_back({6,9}),sp.push_back({4,8});
    sp.push_back({3,9}),sp.push_back({2,9});
    sp.push_back({0,8}),sp.push_back({-2,7}),sp.push_back({-3,6}),sp.push_back({-4,4});
    sp.push_back({-6,3}),sp.push_back({-7,2});
    for(int i=0;i<18;i++) sp.push_back({-sp[i].first,-sp[i].second});
    int cnt=0;
    for(int i=9;i>=0;i--)
        for(int j=i-9;j<=9;j++) {
            id[{i, j}] = ++cnt, xx[cnt] = i, yy[cnt] = j;
            if(j==i-9||j==9) bd[cnt]=1;
        }
    for(int i=-1;i>=-9;i--)
        for(int j=-9;j<=i+9;j++) {
            id[{i, j}] = ++cnt, xx[cnt] = i, yy[cnt] = j;
            if(j==-9||j==i+9) bd[cnt]=1;
        }
    for(int i=1;i<=cnt;i++){
        for(int j=0;j<6;j++){
            int tx=xx[i]+dx[j],ty=yy[i]+dy[j];
            if(id.count({tx,ty})) v[i].push_back(id[{tx,ty}]);
        }
    }
    int x=0,y=0;
    while(1){
        scanf("%d%d",&x,&y);
//        cout<<"--->"<<x<<" "<<y<<endl;
        vector <pair<int,int>> must;
        for(int i=0;i<6;i++){
            int tx=x+dx[i],ty=y+dy[i];
            if(id.count({tx,ty})&&f[id[{tx,ty}]]==0){
                if(bd[id[{tx,ty}]]) must.push_back({tx,ty});
            }
        }
        if(must.size()>1){
            return 1;
        }
        if(must.size()==1){
            print(must[0].first,must[0].second);
            f[id[{must[0].first,must[0].second}]]=1;
        }
        else{
            memset(dis,-1,sizeof(dis));
            queue <int> q;
            dis[id[{x,y}]]=0,q.push(id[{x,y}]);
            while(!q.empty()){
                int temp=q.front();
                q.pop();
                for(auto t:v[temp]) if(!f[t]&&dis[t]==-1)
                        dis[t]=dis[temp]+1,q.push(t);
            }
            int ch=-1,mn=INT_MAX;
            for(auto temp:sp){
                if(dis[id[{temp.first,temp.second}]]!=-1&&dis[id[{temp.first,temp.second}]]<mn)
                    mn=dis[id[{temp.first,temp.second}]],ch=id[{temp.first,temp.second}];
            }
            if(ch!=-1){
                print(xx[ch],yy[ch]);
                f[ch]=1;
            }
            else{
                for(int i=1;i<=cnt;i++)
                    if(!f[i]&&(xx[i]!=x||yy[i]!=y)){
                        print(xx[i],yy[i]);
                        f[i]=1;
                        break;
                    }
            }
        }
        int fl=0;
        for(int i=0;i<6;i++){
            int tx=x+dx[i],ty=y+dy[i];
            if(id.count({tx,ty})){
                if(f[id[{tx,ty}]]==0)
                    fl=1;
            }
        }
        if(!fl){
//            puts("WIN!!!");
            break;
        }
//        else{
//            for(int i=0;i<6;i++){
//                int tx=x+dx[i],ty=y+dy[i];
//                if(id.count({tx,ty})&&f[id[{tx,ty}]]==0){
//                    x=tx,y=ty;
////                    break;
//                }
//            }
//        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 3840kb

input:

0 0
1 1
1 2
2 3
3 4
4 5
4 6
5 7
4 7
3 7
4 7
3 7
4 7
3 7
4 7
5 7
6 7
7 7
6 7
5 7
6 7
5 7
4 7
3 7
2 7
3 7
4 7
3 7
2 7
1 7
2 7
1 7
2 7
3 7
4 7
5 7
6 7
7 7
7 6
7 5
7 6
7 5
7 6
7 7
7 6
7 5
7 4
7 3
7 4
7 3
7 2
7 1
7 2
7 3
7 4
7 5
7 6
7 7
6 7
5 7
6 7
5 7
4 7
5 7
4 7
5 7
4 7
5 7
6 7
5 7
4 7
3 7
4 7
5 7
4 7
...

output:

8 0
8 4
4 8
8 8
7 9
6 9
3 9
9 7
2 9
0 8
9 6
-2 7
-3 6
-4 4
9 3
9 2
6 -3
7 -2
4 -4
-6 3
-7 2
-8 0
-8 -4
-9 -2
-9 -3
-9 -6
3 -6
-9 -7
2 -7
-8 -8
-4 -8
0 -8
-7 -9
-6 -9
-3 -9
-2 -9
9 0
9 1
9 4
9 5
9 8
9 9
8 -1
8 1
8 2
8 3
8 5
8 6
8 7
8 9
7 -1
7 0
7 1
7 2
7 3
7 4
7 5
7 6
7 7
7 8
6 -2
6 -1
6 0
6 1
6 2
6 ...

result:

wrong answer Cat reaches the boundary -9 -8