QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#388878#4884. Battleship: New RulesunputdownableTL 0ms3744kbC++172.9kb2024-04-13 21:04:022024-04-13 21:04:03

Judging History

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

  • [2024-04-13 21:04:03]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3744kb
  • [2024-04-13 21:04:02]
  • 提交

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;
    if(N&1) return Answer(-1,-1);
    n=N/2-1;
    for(int i=1; i<=n; ++i) 
        for(int u=1; u<=n; ++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 dx=cx-1; dx<=cx+1; ++dx) {
                    for(int dy=cy-1; dy<=cy+1; ++dy) if(nxt[dx][dy]==O) {
                        if(dx<1) continue;
                        if(dx>n) continue;  
                        if(dy<1) continue;
                        if(dy>n) continue;
                        cx=dx; cy=dy;
                        goto eee;       
                    }
                }
                for(int dx=cx-2; dx<=cx+2; ++dx) {
                    for(int dy=cy-2; dy<=cy+2; ++dy) if(nxt[dx][dy]==O) {
                        if(dx<1) continue;
                        if(dx>n) continue;  
                        if(dy<1) continue;
                        if(dy>n) continue;
                        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: 0ms
memory: 3684kb

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: 0ms
memory: 3744kb

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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