当前位置:网站首页>非传递骰子(春季每日一题 51)
非传递骰子(春季每日一题 51)
2022-06-22 05:31:00 【sweetheart7-7】
为了消磨牛棚里的时光,奶牛们喜欢玩简单的骰子游戏。
其中一种游戏使用两个骰子 X X X 和 Y Y Y 进行。
两个骰子均被投掷,获胜的骰子是显示的数字较大的骰子。
如果两者显示相同的数字,则重新投掷(只要持续打平,骰子可能会被重新投掷多次)。
如果骰子 X X X 比骰子 Y Y Y 赢的概率更大,我们称骰子 X X X 击败骰子 Y Y Y。
考虑以下三个的 4 4 4 面骰子:
骰子 A A A 在各面上有数字 4 , 5 , 6 4,5,6 4,5,6 和 7 7 7。
骰子 B B B 在各面上有数字 2 , 4 , 5 2,4,5 2,4,5 和 10 10 10。
骰子 C C C 在各面上有数字 1 , 4 , 8 1,4,8 1,4,8 和 9 9 9。
这些骰子满足一个相当奇妙的性质: A A A 击败 B B B, B B B 击败 C C C,并且 C C C 也击败 A A A。
可以看出,三个骰子都不是「最佳的」,因为没有任意一个骰子可以击败其他两个骰子。
在这种情况下,当没有两个骰子打平,也没有一个骰子是最佳的,我们称这三个骰子的集合为「非传递的」。
在非传递的三个骰子的集合中,每个骰子击败一个其他骰子,并输给另一个其他骰子。
给定两个 4 4 4 面骰子 A A A 和 B B B 各面上的数字,请帮助奶牛们求出是否有方法为第三个骰子 C C C 的各面分配数字,使得这个骰子的集合是非传递的。
所有骰子面上的数字必须是 1 1 1 到 10 10 10 的整数。
输入格式
每个测试用例包含多个独立的子测试用例,必须全部回答正确才能通过整个测试用例。
输入的第一行包含 T T T,为你需要求解的子测试用例的数量。
以下 T T T 行,每行描述了一个子测试用例,包含 8 8 8 个整数:骰子 A A A 的 4 4 4 面上的整数,以及骰子 B B B 的 4 4 4 面上的整数。
所有的数均在 1 1 1 到 10 10 10 之间,不一定排序。
可能同一个数会出现多次,即使在同一个骰子上也可能出现多个相同的数。
输出格式
输出 T T T 行。如果有可能为骰子 C C C 分配数字使得第 k k k 个测试用例成为一个非传递的骰子集合,则第 k k k 行输出 y e s yes yes,否则输出 n o no no。
数据范围
1 ≤ T ≤ 10 1≤T≤10 1≤T≤10,
所有骰子面上的数字均是 1 1 1 到 10 10 10 的整数。
输入样例:
3
4 5 6 7 2 4 5 10
2 2 2 2 1 1 1 1
1 1 1 1 2 2 2 2
输出样例:
yes
no
no
样例解释
第一个子测试用例对应题目中的例子。
在第二个子测试用例中,不存在骰子 C C C 可以使得这个骰子集合是非传递的。
同理第三个子测试用例的答案也是 n o no no。
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 10;
int t;
int n = 4;
int a[3][N];
int get(int a[], int b[]){
int r1 = 0, r2 = 0;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
if(a[i] > b[j]) r1++;
else if(a[i] < b[j]) r2++;
return r1 > r2;
}
bool check(int a[][N]){
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
for(int k = 0; k < 3; k++)
if(i != j && i != k && j != k){
if(get(a[i], a[j]) && get(a[j], a[k]) && get(a[k], a[i]))
return true;
}
return false;
}
int main(){
cin >> t;
while(t--){
for(int i = 0; i < n; i++) cin >> a[0][i];
for(int i = 0; i < n; i++) cin >> a[1][i];
bool flag = false;
for(int i = 1; i <= 10; i++)
for(int j = 1; j <= 10; j++)
for(int k = 1; k <= 10; k++)
for(int l = 1; l <= 10; l++){
a[2][0] = i, a[2][1] = j, a[2][2] = k, a[2][3] = l;
if(check(a)) {
flag = true;
break;
}
}
if(flag) puts("yes");
else puts("no");
}
return 0;
}
边栏推荐
- 旅行家的预算(洛谷)
- 大厂晋升学习方法四:Play 学习法
- Link a static library‘s all sections
- 独立站优化清单丨如何有效提升站内转化率?
- Development prospect forecast and investment strategy analysis report of global and Chinese manganese oxide nano powder industry 2022-2028
- 數據的存儲(進階)
- SCM future employment development direction, learn SCM must know some entry-level knowledge and industry prospects, read the benefit
- Remove then add string from variable of Makefile
- Learning method 3 for promotion of large enterprises: chain learning method
- 机器学习笔记 七:强大的神经网络表述
猜你喜欢

错误:note: module requires Go 1.17

Go语言使用zap日志库

vscode 远程连接错误:Server status check failed - waiting and retrying

移动端 realm数据库使用及解耦,跨线程安全使用 OC realm

CLion安装下载

The first week of wechat applet development: page setup, page Jump and data binding

Sogou input method cannot output Chinese

Record local project startup error: invalid source distribution: 8

关于背包问题的总结

Xshell下载安装(解决评估过期问题)
随机推荐
Tongda OA vulnerability analysis collection
QEMU ARM interrupt system architecture
Xshell下载安装(解决评估过期问题)
OPTEE notes
Want to put Facebook ads but don't know where to start? This article takes you to know more about
QEMU ARM interrupt system architecture 2
企业如何把ERP项目自动施行?
微信小程序给子组件赋值方式
数据的存储(进阶)
open source hypervisor
Use and decoupling of the mobile terminal's realm database, and use OC realm safely across threads
Cookie setting and reading in C #
参数序列化
A reminder to cross-border sellers who are still "shopping"!
Global and Chinese carbon conductive filler market demand trend and future prospect report 2022-2027
基于CRU中的tmp数据进行年平均气温分析
中小企业签署ERP合同时,需要留意这几点
Overview analysis and investment forecast report of semiconductor refrigeration devices in the world and China 2022-2027
Implementation of lazy loading of pictures (summary and sorting)
How can enterprises implement ERP projects automatically?