QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#625857#6812. Draw a triangleSound_MediumWA 53ms3632kbC++232.6kb2024-10-09 21:26:382024-10-09 21:26:45

Judging History

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

  • [2024-10-09 21:26:45]
  • 评测
  • 测评结果:WA
  • 用时:53ms
  • 内存:3632kb
  • [2024-10-09 21:26:38]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
#define PII pair<int,int>
#define x first
#define y second
int n, m;

void solve () {
    vector<pair<int,int>>p(2);
    for(int i=0;i<2;i++){
        cin>>p[i].first>>p[i].second;
    }
    sort(p.begin(),p.end(),[](PII a,PII b){
        return a.x<b.x||a.x==b.x&&a.y<b.y;
    });
    PII a=p[0],b=p[1];
    if(a.x==b.x){
        cout<<a.x+1<<" "<<a.y<<endl;
        return ;
    }
    else if(a.y==b.y){
        cout<<a.x<<" "<<a.y+1<<endl;
        return ;
    }
    auto fy=[&](int x)->int{
        {}
        return (int)(a.y*(b.x-a.x)-a.x*(b.y-a.y)+x*(b.y-a.y))/(b.x-a.x);
    };
    auto area=[&](PII a,PII b,PII c){
        return abs((a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y));
    };
    if(a.y>b.y){
        int gc=gcd((b.x-a.x),(a.y-b.y));
        // cerr<<gc<<endl;
        if(gc==(b.x-a.x)){
            cout<<a.x<<" "<<a.y-1<<endl;return ;
        }
        int l = a.x, r = a.x+(b.x-a.x)/(gc)-1;
        int ans1, ans2;
        auto f=[&](int x)->int{
            {}
            PII c={x,fy(x)};
            PII d={x,fy(x)+1};
            return min(area(a,b,c),area(a,b,d));
        };
        // for(int i=l;i<=r;i++){
        //     cout<<f(i)<<" ";
        // }
        while (l < r)
        {
            int mid1 = l + (r - l) / 3;
            int mid2 = r - (r - l) / 3;
            ans1 = f(mid1), ans2 = f(mid2);
            if (ans1 >= ans2)r = mid2 - 1; // 极大值
            else l = mid1 + 1;
        }
        cout<<l<<" "<<fy(l)<<endl;
    } 
    else{
        int gc=gcd(abs(b.x-a.x),abs(a.y-b.y));
        // cerr<<gc<<endl;
        if(gc==abs(b.x-a.x)){
            // cerr<<"*";
            cout<<a.x+1<<" "<<a.y<<endl;return ;
        }
        int l = a.x+1, r = a.x+(b.x-a.x)/(gc);

        int ans1, ans2;
        auto f=[&](int x)->int{
            {}
            PII c={x,fy(x)};
            PII d={x,fy(x)+1};
            return min(area(a,b,c),area(a,b,d));
            
        };
        // for(int i=l;i<=r;i++){
        //     cout<<f(i)<<" "<<fy(i)-a.y<<" "<<i-a.x<<"\n";
        // }
        while (l < r)
        {
            int mid1 = l + (r - l) / 3;
            int mid2 = r - (r - l) / 3;
            ans1 = f(mid1), ans2 = f(mid2);
            if (ans1 >= ans2)r = mid2 - 1; // 极大值
            else l = mid1 + 1;
        }
        cout<<l<<" "<<fy(l)<<endl;
    }
}
signed main () {
    int T = 1; 
    std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin>>T;
    while (T --) solve ();
    return 0;
}

详细

Test #1:

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

input:

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

output:

2 0
1 1
1 0

result:

ok T=3 (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 53ms
memory: 3632kb

input:

50000
66620473 -33485015 66620223 -33485265
43307886 98029243 43307636 98028994
-88895230 -3180782 -88895480 -3181030
-90319745 20018595 -90319995 20018348
-56783257 84789686 -56783507 84789440
-81798038 90629147 -81798288 90628902
98942945 -939146 98942695 -939390
-42532151 -57203475 -42532401 -572...

output:

66620224 -33485265
43307761 98029118
-88895356 -3180906
-90319870 20018471
-56783413 84789532
-81798263 90628926
98942778 -939308
-42532223 -57203544
53500019 -30665786
27114873 46988959
-2657650 26865234
40614125 17923365
-47650081 96037542
92954179 -64535027
86508704 -51415317
-82017908 17392378
7...

result:

wrong answer wa on query #2 (test case 2)