QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#841365#9804. Guess the Polygonfrankly6TL 0ms3592kbC++172.3kb2025-01-03 17:30:112025-01-03 17:30:11

Judging History

This is the latest submission verdict.

  • [2025-01-03 17:30:11]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 3592kb
  • [2025-01-03 17:30:11]
  • Submitted

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#define int long long
using namespace std;
typedef long long ll;
const int MX=1010;

int T, N;
int read()
{
    int r=0, f=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {r=r*10+ch-'0'; ch=getchar();}
    return r*f;
}
struct point
{
    int x, y;
    bool operator < (const point &a)const{
        return x<a.x;
    }
}p[MX];
int gcd(int a, int b){return b==0?a:gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}
struct frac
{
    int u, d;
    frac(int uu, int dd)
    {
        int g=gcd(uu,dd);
        u=uu/g; d=dd/g;
    }
    frac operator + (const frac &a)const{
        int D=lcm(d,a.d);
        int U=D/d*u+D/a.d*a.u;
        // cout << "U=" << U << ", D=" << D << '\n';
        return frac{U,D};
    }
    frac operator * (const int &a)const{
        int g=gcd(d,a);
        return frac{u/g*a,d/g};
    }
    frac operator * (const frac &a)const{
        int g1=gcd(u,a.d);
        int g2=gcd(d,a.u);
        // cout << "u=" << u << ", d=" << d << '\n';
        // cout << "a.u=" << a.u << ", a.d=" << a.d << '\n';
        // cout << "g1=" << g1 << ", g2=" << g2 << '\n';
        // cout << "fu=" << u/g1/g2*a.u << ", fd=" << d/g1/g2*a.d << '\n';
        return frac{u*a.u/g1/g2,d*a.d/g1/g2};
    }
    void easy()
    {
        int g=gcd(u,d);
        u/=g; d/=g;
    }
    void print(){cout << u << "/" << d << '\n';}
};
void ask(int id)
{
    cout << "? " << p[id].x << " 1\n";
    cout.flush();
}
signed main()
{
    // freopen("testdata.in","r",stdin);
    T=read();
    while(T--)
    {
        N=read();
        for(int i=1;i<=N;i++)
        {
            p[i].x=read();
            p[i].y=read();
        }
        sort(p+1,p+1+N);
        frac ans={0,1}, pre={0,1};
        for(int i=2;i<=N-1;i++)
        {
            frac h(p[i].x-p[i-1].x,2);
            ask(i);
            int u=read(), d=read();
            frac now={u,d};
            ans=ans+(pre+now)*h;
            ans.easy();
            pre=now;
        }
        frac hn(p[N].x-p[N-1].x,2);
        ans=ans+pre*hn;
        ans.easy();
        cout << "! " << ans.u << " " << ans.d << '\n';
        cout.flush();
    }
    return (0-0);
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3592kb

input:

2
4
3 0
1 3
1 1
0 0
2 1
2 1
3
0 0
999 1000
1000 999
1999 1000

output:

? 1 1
? 1 1
! 3 1
? 999 1
! 1999 2

result:

ok correct! (2 test cases)

Test #2:

score: -100
Time Limit Exceeded

input:

9
4
1 1
1 3
3 0
0 0
3 1
3 1

output:

? 1 1
? 1 1
! 9 2

result: