QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#388910#4884. Battleship: New RulesunputdownableTL 3ms3660kbC++172.4kb2024-04-13 21:22:482024-04-13 21:22:48

Judging History

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

  • [2024-04-13 21:22:48]
  • 评测
  • 测评结果:TL
  • 用时:3ms
  • 内存:3660kb
  • [2024-04-13 21:22:48]
  • 提交

answer

#include <bits/stdc++.h>
// #define int long long
#define i64 long long
#define pii pair <int, int> 
using namespace std;
const pii O=make_pair(0,0);
int n,N;
inline void Answer(int x,int y) {
    cout<<"! "<<x<<' '<<y<<endl;
    int res; cin>>res;
    if(res==-1) exit(0);
}
inline int qry(int x,int y) {
    cout<<"? "<<x<<' '<<y<<endl;
    int res; cin>>res;
    if(res==-1) exit(0);
    return res;
}
pii nxt[502][502];
inline pii Q(int x,int y) {
    int A=qry(x*2,y*2),B=qry(x*2,y*2+1);
    int C=qry(x*2+1,y*2),D=qry(x*2+1,y*2+1);
    if(!A&&!B&&!C&&!D) return O;
    if(A&&B) return make_pair(-1,0);
    if(A&&C) return make_pair(0,-1);
    if(D&&B) return make_pair(0,1);
    if(D&&C) return make_pair(1,0);
    if(A) return make_pair(-1,-1);
    if(B) return make_pair(-1,1);
    if(C) return make_pair(1,-1);
    if(D) return make_pair(1,1);
}
inline void work() {
    cin>>N;
    assert(N<=10);
    if(N&1) return Answer(-1,-1);
    n=N/2-1;
    for(int i=0; i<=n+1; ++i) 
        for(int u=0; u<=n+1; ++u)
            nxt[i][u]=O;
    int cx=(n+1)/2,cy=(n+1)/2;
    auto f=[&](int&x,int&y,pii d) { 
        x+=d.first; y+=d.second; 
        if(x<1) x=1;
        if(x>n) x=n;
        if(y<1) y=1;
        if(y>n) y=n;
    };
    while(1) {
        if(nxt[cx][cy]!=O) {
            int sumx=cx,sumy=cy,cnt=1,px=cx,py=cy;
            f(px,py,nxt[cx][cy]);
            while(px!=cx||py!=cy) {
                sumx+=px;
                sumy+=py;
                ++cnt;
                f(px,py,nxt[px][py]);
            }
            cx=floor(1.0*sumx/cnt+0.5);
            cy=floor(1.0*sumy/cnt+0.5);
            if(nxt[cx][cy]!=O) {
                for(int d=1; ; d++) {
                    for(int dx=cx-d; dx<=cx+d; ++dx) {
                        for(int dy=cy-d; dy<=cy+d; ++dy) if(1<=dx&&dx<=n&&1<=dy&&dy<=n&&nxt[dx][dy]==O) {
                            cx=dx; cy=dy;
                            goto eee;       
                        }
                    }
                }
            }
            eee:;
        }
        if((nxt[cx][cy]=Q(cx,cy))==O) return Answer(cx*2,cy*2);
        f(cx,cy,nxt[cx][cy]);
    }
}
signed main() {
    // freopen("localinput","r",stdin);
    // freopen("localoutput","w",stdout);
    ios::sync_with_stdio(0);
    int T; cin>>T;
    while(T--) work();
    // fprintf(stderr,"%.4lf\n",1.0*clock()/CLOCKS_PER_SEC);
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3660kb

input:

2
3
1
4
0
0
0
0
1

output:

! -1 -1
? 2 2
? 2 3
? 3 2
? 3 3
! 2 2

result:

ok max_C=1.00, avg_C=0.50 (2 test cases)

Test #2:

score: 0
Accepted
time: 3ms
memory: 3600kb

input:

100
4
0
0
0
0
1
4
0
0
0
0
1
4
0
0
0
0
1
4
0
0
0
0
1
4
0
0
0
0
1
4
0
0
0
0
1
4
0
0
0
0
1
4
0
0
0
0
1
4
0
0
0
0
1
4
0
0
0
0
1
4
0
0
0
0
1
4
0
0
0
0
1
4
0
0
0
0
1
4
0
0
0
0
1
4
0
0
0
0
1
4
0
0
0
0
1
4
0
0
0
0
1
4
0
0
0
0
1
4
0
0
0
0
1
4
0
0
0
0
1
4
0
0
0
0
1
4
0
0
0
0
1
4
0
0
0
0
1
4
0
0
0
0
1
4
0
0
0
...

output:

? 2 2
? 2 3
? 3 2
? 3 3
! 2 2
? 2 2
? 2 3
? 3 2
? 3 3
! 2 2
? 2 2
? 2 3
? 3 2
? 3 3
! 2 2
? 2 2
? 2 3
? 3 2
? 3 3
! 2 2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