QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#591157#6812. Draw a triangleDixiky_215Compile Error//C++202.8kb2024-09-26 14:32:152024-09-26 14:32:16

Judging History

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

  • [2024-09-26 14:32:16]
  • 评测
  • [2024-09-26 14:32:15]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll =__int128;
// using ll = long long;
int t;
ll x,y,a,b,c;
ll d[15];
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);
	}
}
void print(__int128 x)
{
	if (!x) return;
	if (x < 0) putchar('-'),x = -x;
	print(x / 10);
	putchar(x % 10 + '0');
	
}
ll minl,gcdk,ans_x,ans_y;
bool check(ll k,ll aa,ll bb)
{
	if(k*gcdk==c) return 0;
	ll xx=x*k,yy=y*k;
	ll sumk,numk;
	if(xx<-1e18)
	{
		sumk=-1e18-xx;
		numk=sumk/aa;
		if(!(sumk%aa==0))
		{
			if(numk<0) numk--;
			else numk++;
		}
		xx+=numk*aa;
		yy-=numk*bb;
	}
	if(xx>1e18)
	{
		sumk=xx-1e18;
		numk=sumk/aa;
		if(!(sumk%aa==0))
		{
			if(numk<0) numk--;
			else numk++;
		}
		xx-=numk*aa;
		yy+=numk*bb;
	}
	if(yy<-1e18)
	{
		sumk=-1e18-yy;
		numk=sumk/bb;
		if(!(sumk%bb==0))
		{
			if(numk<0) numk--;
			else numk++;
		}
		xx-=numk*aa;
		yy+=numk*bb;
	}
	if(yy>1e18)
	{
		sumk=yy-1e18;
		numk=sumk/bb;
		if(!(sumk%bb==0))
		{
			if(numk<0) numk--;
			else numk++;
		}
		xx+=numk*aa;
		yy-=numk*bb;
	}
	if(xx<=1e18&&yy<=1e18&&xx>=-1e18&&yy>=-1e18)
	{
		sumk=c-k*gcdk;
		if(sumk<0) sumk=-sumk;
		if(sumk<minl)
		{
			ans_x=xx;ans_y=yy;
			minl=sumk;
		}
		return 1;
	}
	return 0;
}
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;
		gcdk=__gcd(a,b);
		
		ll numk=c/gcdk;
		int tot=0;
		d[++tot]=numk;
		d[++tot]=numk-1;
		d[++tot]=numk+1;
		d[++tot]=numk-2;
		d[++tot]=numk+2;
		
		ex_gcd(a,b);
		ll aa=b/gcdk,bb=a/gcdk;
		num=0;minl=1e18*2;
		for(int i=1;i<=tot;i++)
		{
			if(d[i]*gcdk==c) continue;
			check(d[i],aa,bb);
		}
	
		if(numk<0)
		{
			ll l=-numk,r=0,mid;
			while(l<=r)
			{
				mid=(l+r)/2;
				if(check(mid,aa,bb)) r=mid-1;
				else l=mid+1;
			}
		}
		else
		{
			ll l=0,r=numk,mid;
			while(l<=r)
			{
				mid=(l+r)/2;
				if(check(mid,aa,bb)) l=mid+1;
				else r=mid-1;
			}
		}
		
		// cerr << x1 << " " << y1 << " " << x2 << " " << y2 << "\n";
		assert(ans_x <= 1E18 and ans_x >= -1E18);
		assert(ans_y >= -1E18 and ans_y <= 1E18);

		cout<<format("{}", ans_x) <<" "<< format("{}", ans_y) <<'\n';
//		cout<<ans_x<<" "<<ans_y<<"\n";
		
//		print(ans_x);
//		cout<<" ";
//		print(ans_y);
//		cout<<'\n';
	}
	return 0;
}
/*
1
464263912 393228064 151248499 729744865
*/

詳細信息

answer.code: In function ‘int main()’:
answer.code:131:17: error: ‘num’ was not declared in this scope; did you mean ‘numk’?
  131 |                 num=0;minl=1e18*2;
      |                 ^~~
      |                 numk