挖土机T1 60分求调
  • 板块学术版
  • 楼主Gym081030
  • 当前回复0
  • 已保存回复0
  • 发布时间2022/10/16 12:08
  • 上次更新2023/10/27 07:17:40
查看原帖
挖土机T1 60分求调
525545
Gym081030楼主2022/10/16 12:08
#include<iostream>
namespace IO
{
	template<typename T>
	void read(T& x)
	{
		x = 0;
		int w = 1; char ch = getchar();
		while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); }
		while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); }
		x *= w;
	}
	template<typename T>
	void write(T x)
	{
		if (x < 0) { putchar('-');x = ~x + 1; }
		if (x > 9) {write(x / 10); }
		putchar(x % 10 + '0');
	}
}
using namespace std;
using namespace IO;
typedef struct node
{
	int a;
	int b;
	int opt;
}Node;
int ans_a, ans_b;
int n;
Node paper[1001];
int gcd(int x, int y)
{
	if (!y)
		return x;
	return gcd(y, x % y);
}
inline int lcm(int x, int y)
{
	return x * y / gcd(x, y);
}
int main()
{
	//freopen("explore.in", "r", stdin);
	//freopen("explore.out", "w", stdout);
	read(n);
	for (register int i = 1; i <= n; ++i)
	{
		read(paper[i].a), read(paper[i].b), read(paper[i].opt);
		if (paper[i].opt == 1)
		{
			if (i == 1)
			{
				int t = gcd(paper[i].a, paper[i].b);
				ans_a = paper[i].a / t;
				ans_b = paper[i].b / t;
				//write(ans_a), putchar(' ');
				//write(ans_b), putchar('\n');
				continue;
			}
			int t1, t2, t;
			t1 = paper[i].b;
			t2 = ans_b;
			t = lcm(t1, t2);
			t1 = t / t1;
			t2 = t / t2;
			ans_a *= t2;
			paper[i].a *= t1;
			ans_a += paper[i].a;
			ans_b = t;
			t = gcd(ans_a, ans_b);
			ans_a /= t;
			ans_b /= t;
			//write(ans_a), putchar(' ');
			//write(ans_b), putchar('\n');
		}
		if (paper[i].opt == 2)
		{
			if (i == 1)
			{
				int t = gcd(paper[i].a, paper[i].b);
				ans_a = paper[i].a / t;
				ans_b = paper[i].b / t;
				//write(ans_a), putchar(' ');
				//write(ans_b), putchar('\n');
				continue;
			}
			int t1, t2, t;
			t1 = paper[i].b;
			t2 = ans_b;
			t = lcm(t1, t2);
			t1 = t / t1;
			t2 = t / t2;
			ans_a *= t2;
			paper[i].a *= t1;
			ans_a -= paper[i].a;
			ans_b = t;
			t = gcd(ans_a, ans_b);
			ans_a /= t;
			ans_b /= t;
			/*if (ans_a < 0)
			{
				if (ans_opt == 1)
					ans_opt == 0;
				else
					ans_opt == 1;
				ans_a *= -1;
			}*/
		}
	}
	if (ans_b < 0)
	{
		ans_a *= -1;
		ans_b *= -1;
	}
	if (gcd(ans_a, ans_b) == ans_b)
	{
		write(ans_a / ans_b);
	}
	else
	{
		write(ans_a), putchar('/');
		write(ans_b);
	}
	//fclose(stdin);
	//fclose(stdout);
	return 0;
}
2022/10/16 12:08
加载中...