这个保证实际上没有保证。
查看原帖
这个保证实际上没有保证。
575994
Hisaishi_Kanade楼主2022/10/16 13:45
#include <stdio.h>
#include <assert.h>
#define int long long
class frac
{
	private:
		inline int gcd(int x,int y)
		{
			return !y?x:gcd(y,x%y);
		}
	public:
		int a,b;
		frac()
		{
			a=0;
			b=1;
		}
		frac(int x,int y)
		{
			a=x;
			b=y;
		}
		inline void operator+=(const frac &other)
		{
			int aa,bb,gg;
			aa=a*other.b+other.a*b;
			bb=b*other.b;
			assert(aa<=2000000000);
			assert(bb<=2000000000);
			gg=gcd(aa,bb);
			a=aa/gg;
			b=bb/gg;
		}
		inline void operator-=(const frac &other)
		{
			int aa,bb,gg;
			aa=a*other.b-other.a*b;
			bb=b*other.b;
			assert(aa<=2000000000);
			assert(bb<=2000000000);
			gg=gcd(aa,bb);
			a=aa/gg;
			b=bb/gg;
			if(a<0&&b<0)
			{
				a=-a;
				b=-b;
			}else if(a>0&&b<0)
			{
				a=-a;
				b=-b;
			}
		}
}dfrac;
signed main()
{int t,x,y,z;
	scanf("%lld",&t);
	while(t--)
	{
		scanf("%lld %lld %lld",&x,&y,&z);
		if(z==1)
			dfrac+=frac(x,y);
		else
			dfrac-=frac(x,y);
	}
	if(dfrac.b==1)
		printf("%lld",dfrac.a);
	else
		printf("%lld/%lld",dfrac.a,dfrac.b);
}

RE掉5个点。所以是不是要修正数据。

2022/10/16 13:45
加载中...