QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#865812#9804. Guess the PolygonHanoistTL 2ms3968kbC++142.5kb2025-01-21 23:16:462025-01-21 23:16:46

Judging History

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

  • [2025-01-21 23:16:46]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:3968kb
  • [2025-01-21 23:16:46]
  • 提交

answer

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#include<functional>
#include<utility>
#include<cassert>
using namespace std;
inline int read(){
    int x = 0,f = 1;
    char c = getchar();
    while(c < '0' || c > '9'){
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9'){
        x = (x << 3) + (x << 1) + (c ^ 48);
        c = getchar();
    }
    return x * f;
}
const int N = 1011;
struct point{
    long double x,y;
}a[N];
bool cmp(point a,point b){
    return a.x < b.x;
}
struct frac{
    long double u,v;
};
long long gcd(long long x,long long y){
    if(!y) return x;
    return gcd(y,x % y);
}
inline frac add(frac x,frac y){
    frac ret;
    ret = (frac){x.u * y.v + x.v * y.u,x.v * y.v};
    long long d = gcd((long long)ret.u,(long long )ret.v);
    ret = {ret.u / d,ret.v / d};
    return ret;
}
inline frac mul(frac x,frac y){
    frac ret;
    ret = (frac){x.u * y.u,x.v * y.v};
    long long d = gcd((long long)ret.u,(long long )ret.v);
    ret = {ret.u / d,ret.v / d};
    return ret;
}
map<long double,bool> mp;
int n;
frac ask(frac x){
    frac ret;
    printf("? %.Lf %.Lf\n",x.u,x.v);
    fflush(stdout);
    scanf("%Lf %Lf",&ret.u,&ret.v);
    return ret;
}
void ans(frac x){
    printf("! %.Lf %.Lf\n",x.u,x.v);
    fflush(stdout);
}
int main(){
    int i,j,t;
    frac half = {1,2};
    t = read();
    while(t--){
        bool flag = 0;
        n = read();
        mp.clear();
        for(i = 1;i <= n;i++){
            scanf("%Lf %Lf",&a[i].x,&a[i].y);
            if(mp[a[i].x]) flag = 1;
            mp[a[i].x] = 1;
        }
        sort(a + 1,a + n + 1,cmp);
        frac temp,p,q = {0,1.0};
        frac res = {0.0,1.0};
        if(!flag){
            for(i = 2;i < n;i++){
                temp = (frac){a[i].x,1.0}; 
                p = ask(temp);
                res = add(res,mul(add(p,q),(frac){a[i].x - a[i - 1].x,2.0}));
                q = p;
            }
            res = add(res,mul(q,(frac){a[n].x - a[n - 1].x,2.0}));
        }
        else{
            int lst = 1;
            for(i = 2;i <= n;i++){
                if(a[i].x == a[lst].x) continue;
                //printf("%Lf %Lf\n",a[i].x,a[lst].x);
                temp = (frac){a[i].x + a[lst].x,2.0}; 
                p = ask(temp);
                res = add(res,mul(p,(frac){a[i].x - a[lst].x,1.0}));
                lst = i;
            }
        }
        ans(res);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

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

result:

ok correct! (2 test cases)

Test #2:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

9
4
1 1
1 3
3 0
0 0
3 2
1 2
4
0 0
1 3
1 1
3 0
1 2
3 2
4
0 0
3 0
1 2
1 1
1 2
1 2
4
0 0
3 0
1 2
1 1
1 1
1 2
4
0 0
3 0
1 1
1 2
1 2
1 1
3
1000 0
0 0
0 1000
500 1
4
0 0
1000 0
1000 1000
0 1000
1000 1
5
0 1
1000 1000
1000 0
0 1000
1 0
1999 2
1000 1
9
4 1000
3 1
2 1000
3 1000
1 1
2 1
0 0
1 1000
4 0
500 1
1...

output:

? 1 2
? 4 2
! 5 2
? 1 2
? 4 2
! 7 2
? 1 2
? 4 2
! 3 2
? 1 2
? 4 2
! 2 1
? 1 2
? 4 2
! 5 2
? 1000 2
! 500000 1
? 1000 2
! 1000000 1
? 1 2
? 1001 2
! 1999999 2
? 1 2
? 3 2
? 5 2
? 7 2
! 4003 2

result:

ok correct! (9 test cases)

Test #3:

score: 0
Accepted
time: 2ms
memory: 3968kb

input:

78
8
951 614
927 614
957 614
957 604
937 614
942 619
951 610
927 604
10 1
25 2
21 2
10 1
7
562 260
602 250
582 255
587 260
602 260
562 250
577 260
10 1
15 2
15 2
10 1
3
454 98
494 68
455 68
117 4
3
526 589
566 559
527 559
117 4
3
854 496
854 466
894 466
15 1
3
797 264
827 254
857 264
10 1
3
719 737
...

output:

? 1864 2
? 1879 2
? 1893 2
? 1908 2
! 317 1
? 1139 2
? 1159 2
? 1169 2
? 1189 2
! 375 1
? 455 1
! 585 1
? 527 1
! 585 1
? 1748 2
! 600 1
? 827 1
! 300 1
? 1478 2
! 600 1
? 162 1
! 400 1
? 1489 2
? 1499 2
? 1544 2
! 275 1
? 1869 2
? 1879 2
? 1889 2
? 1899 2
? 1909 2
? 1919 2
? 1929 2
? 1939 2
? 1949 ...

result:

ok correct! (78 test cases)

Test #4:

score: -100
Time Limit Exceeded

input:

34
24
123 815
168 800
133 795
27 827
153 805
28 830
178 780
138 810
78 830
192 772
148 790
88 810
43 825
183 795
103 805
163 785
118 800
93 825
63 835
73 815
58 820
198 790
48 840
108 820
10 3
95 6
15 2
95 6
15 2
95 6
15 2
95 6
15 2
95 6
15 2
95 6
15 2
95 6
15 2
95 6
15 2
95 6
15 2
95 6
15 2
15 1
24...

output:

? 28 1
? 43 1
? 48 1
? 58 1
? 63 1
? 73 1
? 78 1
? 88 1
? 93 1
? 103 1
? 108 1
? 118 1
? 123 1
? 133 1
? 138 1
? 148 1
? 153 1
? 163 1
? 168 1
? 178 1
? 183 1
? 192 1
! 1925 1
? 54 1
? 69 1
? 74 1
? 84 1
? 89 1
? 99 1
? 104 1
? 114 1
? 119 1
? 129 1
? 134 1
? 144 1
? 149 1
? 159 1
? 164 1
? 174 1
? ...

result: