QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#811999 | #9804. Guess the Polygon | 275307894a# | RE | 0ms | 0kb | C++14 | 2.2kb | 2024-12-13 10:34:05 | 2024-12-13 10:34:07 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=1e3+5,M=N*4+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(28382);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
int n,A[N],B[N],m;
using frac=pair<ll,ll>;
frac operator +(const frac &A,const frac &B){
int g=__gcd(A.se,B.se);
return frac(B.se/g*A.fi+A.se/g*B.fi,A.se/g*B.se);
}
frac operator -(const frac &A,const frac &B){
return A+frac(-B.fi,B.se);
}
frac operator *(const frac &A,const frac &B){
return frac(A.fi*B.fi,A.se*B.se);
}
frac operator /(const frac &A,const frac &B){
return A*frac(B.se,B.fi);
}
frac query(int x,int y){
cout<<"? "<<x<<' '<<y<<endl;
cin>>x>>y;
return frac(x,y);
}
void Solve(){
cin>>n;m=n;
Me(B,0);
for(int i=1;i<=n;i++){
int x,y;cin>>x>>y;
A[i]=x;B[x]++;
}
sort(A+1,A+n+1);m=unique(A+1,A+n+1)-A-1;
frac La=frac(0,1),ans=frac(0,1);
for(int i=1;i<m;i++){
int px=A[i]*3+1,py=A[i+1]*3-1;
frac w1,w2;
if(B[A[i]]>=2) w1=query(px,3);
else w1=La,px--;
if(i==n-1&&B[A[n]]==1) w2=frac(0,1),py++;
else w2=query(py,3);
frac d=(w2-w1)/frac(py-px,1);
if(px==A[i]*3+1) px--,w1=w1-d;
if(py==A[i+1]*3-1) py++,w2=w2+d;
ans=ans+(w1+w2)*frac(A[i+1]-A[i],2);
La=w2;
}
if(ans.fi<0) ans.fi*=-1,ans.se*=-1;
ll g=__gcd(ans.fi,ans.se);
cout<<"! "<<ans.fi/g<<' '<<ans.se/g<<endl;
}
int main(){
int t=1;
scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
2 4 3 0 1 3 1 1 0 0 4 3 5 3
output:
? 2 3 ? 4 3 ? 8 3