QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#388866#4884. Battleship: New RulesunputdownableRE 1ms3724kbC++171.9kb2024-04-13 20:59:352024-04-13 20:59:36

Judging History

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

  • [2024-04-13 20:59:36]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3724kb
  • [2024-04-13 20:59:35]
  • 提交

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; };
    while(1) {
        while(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]=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: 3724kb

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: 3680kb

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

result:

ok max_C=1.00, avg_C=1.00 (100 test cases)

Test #3:

score: -100
Runtime Error

input:

100
10
0
0
1
0
1
0
0
0

output:

? 4 4
? 4 5
? 5 4
? 5 5
? 6 2
? 6 3
? 7 2
? 7 3
? 4 0

result: