QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#590472#6812. Draw a triangleDixiky_215Compile Error//C++202.6kb2024-09-26 00:31:142024-09-26 00:31:14

Judging History

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

  • [2024-09-26 00:31:14]
  • 评测
  • [2024-09-26 00:31:14]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll =__int128;
// using ll = long long;
int t;
ll x,y,a,b,c;
void ex_gcd(ll al,ll bl)
{
	if(bl==0LL)
	{
		x=1LL;y=0LL;return;
	}
	else
	{
		ex_gcd(bl,al%bl);
		ll tmp=x;
		x=y;y=tmp-y*(al/bl);
	}
}

int main() {
    cin.tie(nullptr) -> sync_with_stdio(false);

    mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

    long long x1,x2,y1,y2,x3,y3;
    cin>>t;
    while(t--)
    {
        cin>>x1>>y1>>x2>>y2;
    //    x1 = rnd() % 10 + 1; y1 = rnd() % 10 + 1; x2 = rnd() % 10 + 1; y2 = rnd() % 10 + 1;
        if(x1==x2)
        {
            cout<<x1+1LL<<" 1\n";
            continue;
        }
        if(y1==y2)
        {
            cout<<"1 "<<y1+1LL<<'\n';
            continue;
        }
        a=y1-y2;b=x2-x1;
        c=x2*y1-x1*y2;
        ll gcdk=__gcd(a,b);



        ll num_l=c/gcdk;
        if(c%gcdk==0LL) num_l--;
        ll num_r=c/gcdk;
        num_r++;

        ll sum1=c-num_l*gcdk;
        ll sum2=num_r*gcdk-c;
        ll num;
		if(sum1<=sum2) num=num_l;
		else num=num_r;

        ex_gcd(a,b);

		ll num1,num2,num3=0,num4=0;
		if(x==0) num1=num,num2=num;
		else num1=1e18/x,num2=-1e18/x;

		if(y==0) num3=num,num4=num;
		else num3=1e18/y,num4=-1e18/y;

		ll xx,yy,ans=1e18,ans_num;
		
		xx=x*num;yy=y*num;
		if(xx<=1e18&&xx>=-1e18&&yy<=1e18&&yy>=-1e18)
		{
			ll sumk=abs(c-gcdk*num);
			if(sumk<ans)
			{
				ans=sumk;
				ans_num=num;
			}
			
		}

		xx=x*num1;yy=y*num1;
		if(xx<=1e18&&xx>=-1e18&&yy<=1e18&&yy>=-1e18)
		{
			ll sumk=abs(c-gcdk*num1);
			if(sumk<ans)
			{
				ans=sumk;
				ans_num=num1;
			}
			
		}

		xx=x*num2;yy=y*num2;
		if(xx<=1e18&&xx>=-1e18&&yy<=1e18&&yy>=-1e18)
		{
			ll sumk=abs(c-gcdk*num2);
			if(sumk<ans)
			{
				ans=sumk;
				ans_num=num2;
			}
			
		}

		xx=x*num3;yy=y*num3;
		if(xx<=1e18&&xx>=-1e18&&yy<=1e18&&yy>=-1e18)
		{
			ll sumk=abs(c-gcdk*num3);
			if(sumk<ans)
			{
				ans=sumk;
				ans_num=num3;
			}
			
		}

		xx=x*num4;yy=y*num4;
		if(xx<=1e18&&xx>=-1e18&&yy<=1e18&&yy>=-1e18)
		{
			ll sumk=abs(c-gcdk*num4);
			if(sumk<ans)
			{
				ans=sumk;
				ans_num=num4;
			}
			
		}

		x*=ans_num;y*=ans_num;

        // cerr << x1 << " " << y1 << " " << x2 << " " << y2 << "\n";
        assert(x <= 1E18 and x >= -1E18);
        assert(y >= -1E18 and y <= 1E18);
        
        cout<<format("{}", x) <<" "<< format("{}", y) <<'\n';
		// cout<<x<<" "<<y<<"\n";
    }
    return 0;
}
/*
1
464263912 393228064 151248499 729744865
*/

Details

answer.code: In function ‘int main()’:
answer.code:74:36: error: call of overloaded ‘abs(ll)’ is ambiguous
   74 |                         ll sumk=abs(c-gcdk*num);
      |                                 ~~~^~~~~~~~~~~~
In file included from /usr/include/c++/13/cstdlib:79,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:42,
                 from answer.code:1:
/usr/include/stdlib.h:840:12: note: candidate: ‘int abs(int)’
  840 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
In file included from /usr/include/c++/13/cstdlib:81:
/usr/include/c++/13/bits/std_abs.h:79:3: note: candidate: ‘constexpr long double std::abs(long double)’
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:75:3: note: candidate: ‘constexpr float std::abs(float)’
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:71:3: note: candidate: ‘constexpr double std::abs(double)’
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:61:3: note: candidate: ‘long long int std::abs(long long int)’
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:56:3: note: candidate: ‘long int std::abs(long int)’
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
answer.code:86:36: error: call of overloaded ‘abs(ll)’ is ambiguous
   86 |                         ll sumk=abs(c-gcdk*num1);
      |                                 ~~~^~~~~~~~~~~~~
/usr/include/stdlib.h:840:12: note: candidate: ‘int abs(int)’
  840 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
/usr/include/c++/13/bits/std_abs.h:79:3: note: candidate: ‘constexpr long double std::abs(long double)’
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:75:3: note: candidate: ‘constexpr float std::abs(float)’
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:71:3: note: candidate: ‘constexpr double std::abs(double)’
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:61:3: note: candidate: ‘long long int std::abs(long long int)’
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:56:3: note: candidate: ‘long int std::abs(long int)’
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
answer.code:98:36: error: call of overloaded ‘abs(ll)’ is ambiguous
   98 |                         ll sumk=abs(c-gcdk*num2);
      |                                 ~~~^~~~~~~~~~~~~
/usr/include/stdlib.h:840:12: note: candidate: ‘int abs(int)’
  840 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
/usr/include/c++/13/bits/std_abs.h:79:3: note: candidate: ‘constexpr long double std::abs(long double)’
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:75:3: note: candidate: ‘constexpr float std::abs(float)’
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:71:3: note: candidate: ‘constexpr double std::abs(double)’
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:61:3: note: candidate: ‘long long int std::abs(long long int)’
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:56:3: note: candidate: ‘long int std::abs(long int)’
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
answer.code:110:36: error: call of overloaded ‘abs(ll)’ is ambiguous
  110 |                         ll sumk=abs(c-gcdk*num3);
      |                                 ~~~^~~~~~~~~~~~~
/usr/include/stdlib.h:840:12: note: candidate: ‘int abs(int)’
  840 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
/usr/include/c++/13/bits/std_abs.h:79:3: note: candidate: ‘constexpr long double std::abs(long double)’
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:75:3: note: candidate: ‘constexpr float std::abs(float)’
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:71:3: note: candidate: ‘constexpr double std::abs(double)’
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:61:3: note: candidate: ‘long long int std::abs(long long int)’
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:56:3: note: candidate: ‘long int std::abs(long int)’
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
answer.code:122:36: error: call of overloaded ‘abs(ll)’ is ambiguous
  122 |                         ll sumk=abs(c-gcdk*num4);
      |                                 ~~~^~~~~~~~~~~~~
/usr/include/stdlib.h:840:12: note: candidate: ‘int abs(int)’
  840 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
/usr/include/c++/13/bits/std_ab...