当前位置: 首页 > wzjs >正文

如何在工商局网站做企业年报毕设网站开发需要做什么

如何在工商局网站做企业年报,毕设网站开发需要做什么,图片交易网站如何建设,小程序 手机网站问题背景 在一排多米诺骨牌中, t o p s [ i ] tops[i] tops[i] 和 b o t t o m s [ i ] bottoms[i] bottoms[i] 分别代表第 i i i 个多米诺骨牌的上半部分和下半部分。(一个多米诺是两个从 1 1 1 到 6 6 6 的数字同列平铺形成的 —— 该平铺的每一半…

问题背景

在一排多米诺骨牌中, t o p s [ i ] tops[i] tops[i] b o t t o m s [ i ] bottoms[i] bottoms[i] 分别代表第 i i i 个多米诺骨牌的上半部分和下半部分。(一个多米诺是两个从 1 1 1 6 6 6 的数字同列平铺形成的 —— 该平铺的每一半上都有一个数字。)
我们可以旋转第 i i i 张多米诺,使得 t o p s [ i ] tops[i] tops[i] b o t t o m s [ i ] bottoms[i] bottoms[i] 的值交换。
返回能使 t o p s tops tops 中所有值或者 b o t t o m s bottoms bottoms 中所有值都相同的最小旋转次数。
如果无法做到,返回 − 1 -1 1

数据约束

  • 2 ≤ t o p s . l e n g t h ≤ 2 × 1 0 4 2 \le tops.length \le 2 \times 10 ^ 4 2tops.length2×104
  • b o t t o m s . l e n g t h = t o p s . l e n g t h bottoms.length = tops.length bottoms.length=tops.length
  • 1 ≤ t o p s [ i ] , b o t t o m s [ i ] ≤ 6 1 \le tops[i], bottoms[i] \le 6 1tops[i],bottoms[i]6

解题过程

结果要求所有元素都相同,那这意味着如果最后能实现,那么取初始状态的任意一个元素,它或它的翻转状态一定被包含在结果中。
为了方便起见,分别取 t o p [ 0 ] top[0] top[0] b o t t o m [ 0 ] bottom[0] bottom[0] 作为目标,分别计算最小次数,再取其中较小的那个就可以了。

具体实现

class Solution {public int minDominoRotations(int[] tops, int[] bottoms) {int res = Math.min(minRot(tops, bottoms, tops[0]), minRot(tops, bottoms, bottoms[0]));return res == Integer.MAX_VALUE ? -1 : res;}private int minRot(int[] tops, int[] bottoms, int target) {int toTop = 0;int toBottom = 0;for (int i = 0; i < tops.length; i++) {int x = tops[i];int y = bottoms[i];if (x != target && y != target) {return Integer.MAX_VALUE;}if (x != target) {toTop++; } else if (y != target) {toBottom++;}}return Math.min(toTop, toBottom);}
}
http://www.dtcms.com/wzjs/806234.html

相关文章:

  • 巨人科技网站建设在演示文稿上网站怎么做
  • 中国建设建筑教育网站wordpress5.0老版编辑器
  • 专业网站设计联系电话建设网上银行个人登录入口
  • 品牌网站排名软件wordpress修改logo地址
  • 工行网站跟建设网站区别自助建设网站软件
  • 汉化版网站开发软件万网商标注册
  • 网络营销的相关知识广安seo
  • 保定市住房保障和城乡建设局网站甘肃省建设厅网站首页
  • 乐清 网站建设安徽质量工程建设网站
  • wordpress作者页面显示评论搜索引擎seo优化怎么做
  • 黑龙江省建设网站wordpress打开慢 cdn
  • 便宜点的网站空间做古玩的网站
  • 网站开发美学 2.0wordpress 评论ajax
  • 想开网站建设公司软件开发的八个步骤
  • 网络推广网站公司济宁建设企业网站
  • 宁波网站建设服务报价招标文件范本
  • 响应式网站开发视频平和县建设局网站
  • 药品加工厂做网站厦门做网站排名
  • 网站平台建设心得网站模板文件在哪里下载
  • 网页做得好的网站免费的cms模板
  • 重庆做网站的深圳百度开户
  • 作业做哪些类型的网站广州做seo的公司
  • 网站优化中友情链接怎么做python培训机构哪家好
  • 商贸公司的网站建设万网网站到期后续费一年多少钱
  • 华米手表官方网站迁移wordpress到阿里云
  • wordpress 邀请码seo在线培训
  • 同一个服务器做两个网站功能型网站建设
  • 网站建设费用请示外贸货源
  • 我和你99谁做的网站彭水网站建设推广
  • 网站建设与维护案例英语不行如何编程做网站