当前位置:网站首页>等价多米诺骨牌对的数量-c语言实现
等价多米诺骨牌对的数量-c语言实现
2022-04-22 22:15:00 【Mr Gao】
等价多米诺骨牌对的数量
给你一个由一些多米诺骨牌组成的列表 dominoes。
如果其中某一张多米诺骨牌可以通过旋转 0 度或 180 度得到另一张多米诺骨牌,我们就认为这两张牌是等价的。
形式上,dominoes[i] = [a, b] 和 dominoes[j] = [c, d] 等价的前提是 ac 且 bd,或是 ad 且 bc。
在 0 <= i < j < dominoes.length 的前提下,找出满足 dominoes[i] 和 dominoes[j] 等价的骨牌对 (i, j) 的数量。
示例:
输入:dominoes = [[1,2],[2,1],[3,4],[5,6]]
输出:1
int f(int n){
if(n==1) return 0;
int i;
int s=0;
for(i=1;i<=n-1;i++){
s=s+i;
}
return s;
}
int numEquivDominoPairs(int** dominoes, int dominoesSize, int* dominoesColSize){
int r[dominoesSize][2];
int i,j;
int p=1;
int rs[dominoesSize];
rs[0]=1;
r[0][0]=dominoes[0][0];
r[0][1]=dominoes[0][1];
for(i=1;i<dominoesSize;i++){
int l=0;
// printf("i %d %d ",dominoes[i][0],dominoes[i][1]);
for(j=0;j<p;j++){
// printf("j%d %d ",r[j][0],r[j][1]);
// printf("rs[j] %d j %d i %d ",rs[j],j,i);
if(dominoes[i][0]==r[j][0]&&dominoes[i][1]==r[j][1]){
rs[j]++;
l=1;
break;
}
if(dominoes[i][1]==r[j][0]&&dominoes[i][0]==r[j][1]){
rs[j]++;
l=1;
break;
}
}
if(l==0){
r[p][0]=dominoes[i][0];
r[p][1]=dominoes[i][1];
rs[p]=1;
p++;
}
}
int max=0;
for(i=0;i<p;i++){
printf("rs[j] %d ",rs[i]);
max=max+f(rs[i]);
}
return max;
}
版权声明
本文为[Mr Gao]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_43327597/article/details/124350945
边栏推荐
猜你喜欢

How to use opcua protocol on appinventor?

安装scVI及使用教程

2.57-编写程序show_short, show_long和show_double,它们分别打印类型为short, long和double的C语言对象的字节表示。请试着在几种机器上运行。

2.55-在你能够访问的不同机器上,使用show_bytes(文件show_bytes.c)编译并运行示例代码。确定这些机器使用的字节顺序。

餐饮行业收银系统源码,C# .NET + MSSQL WPF

【Paper】2019_Distributed fixed-time consensus-based formation tracking for multiple nonholonomic whee

GBase 8s V8.8 SQL 指南:教程-6.2.1(2)

静态和动态控制数码管

41.0:GemBox. Spreadsheet|. Document|. Pdf|. Presentation

41.0:GemBox.Spreadsheet|.Document|.Pdf|.Presentation
随机推荐
Quickly calculate the number of divisors -- from basic to advanced
公众号配置伪静态防止出现页面路径加载问题
MySql--- 数据类型
TOOLS. INI‘does not contain a valid tool path
GBase 8s V8.8 SQL 指南:教程-6.1.2(2)
用forEach和ES6实现tab切换
【玩转Lighthouse】搭建即收即毁的临时邮箱系统
CAS统一身份认证(二):Overlay配置管理
Advanced multithreading (8) -- thread pool
MTP管理课养成计划-第2天学习笔记
Flutter hybrid development
GBase 8s V8. 8 SQL Guide: Tutorial - 6.2.1 (2)
Advanced multithreading (6) -- locking mechanism
【Paper】2019_ Distributed fixed-time consensus-based formation tracking for multiple nonholonomic whee
加法逆元(a^a=0)异或操作,这个并没有性能上的优势,只是一个智力游戏
Rasa课程、Rasa培训、Rasa面试、Rasa实战系列之Rasa全新全局词槽映射的 3 大方法
Centos7安装mysql
GBase 8s V8.8 SQL 指南:教程-6.2.2(1)
Redis应用解决问题
GBase 8s V8. 8 SQL Guide: Tutorial - 6.2.1 (4)