璟雯院

珺璟如晔,雯华若锦

用户工具

站点工具


icpc:problems:usaco22jan_non-transitive_dice_b
problems
名称Non-Transitive Dice B
题目编号USACO22JAN_B2
题目链接luogu.com.cn/…
来源USACO
算法分类入门_函数, 模拟
难易程度容易

Non-Transitive Dice B

想法

大模拟,直接枚举4个位置的值即可。不过这道题的亮点是用函数来构造同种模式的判断,这个架构非常值得学习。

代码实现

#include<iostream>
using namespace std;
 
bool x_win_y(int x[4], int y[4])
{
	int x_cnt = 0, y_cnt = 0;
	for (int i = 0; i < 4; ++i) {
		for (int j = 0; j < 4; ++j) {
			if(x[i] < y[j])y_cnt++;
			else if(x[i] > y[j])x_cnt++;
		}
	}
	return x_cnt > y_cnt;
}
 
int main()
{
	int a[4], b[4], c[4], T;
	cin >> T;
	while(T--)
	{
		for (int i = 0; i < 4; ++i)
			cin >> a[i];
		for (int i = 0; i < 4; ++i)
			cin >> b[i];
 
		bool flag = false;
		for (c[0] = 1; c[0] <= 10 && !flag; ++c[0])
			for (c[1] = c[0]; c[1] <= 10 && !flag; ++c[1])
				for (c[2] = c[1]; c[2] <= 10 && !flag; ++c[2])
					for (c[3] = c[2]; c[3] <= 10 && !flag; ++c[3]) {
						if(x_win_y(a, b) && x_win_y(b, c) && x_win_y(c, a))
							flag = true;
						else if(x_win_y(a, c) && x_win_y(c, b) && x_win_y(b, a))
							flag = true;
					}
 
		if(flag)
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
 
	return 0;
}
/app/www/public/data/pages/icpc/problems/usaco22jan_non-transitive_dice_b.txt · 最后更改: 2023/02/07 09:28 由 温婕莺