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

手机网站的作用今日热点新闻2022

手机网站的作用,今日热点新闻2022,wordpress个人展示,阳江网梁国燊事件目录 数组变换(贪⼼位运算) 题目解析 讲解算法原理 编写代码 装箱问题(动态规划-01背包) 题目解析 讲解算法原理 编写代码 数组变换(贪⼼位运算) 题目解析 1.题目链接:数组变换__牛客网…

目录

数组变换(贪⼼+位运算)

题目解析

讲解算法原理

编写代码

装箱问题(动态规划-01背包)

题目解析

讲解算法原理

编写代码


数组变换(贪⼼+位运算)

题目解析

1.题目链接:数组变换__牛客网

2.题目描述
 

牛牛有一个数组,里面的数可能不相等,现在他想把数组变为:所有的数都相等。问是否可行。
牛牛可以进行的操作是:将数组中的任意一个数改为这个数的两倍。

这个操作的使用次数不限,也可以不使用,并且可以对同一个位置使用多次。

数据范围:数组大小满足 1≤n≤50 1 \le n \le 50 \ 1≤n≤50  ,数组中的数满足 1≤val≤109 1 \le val \le 10^{9} \ 1≤val≤109 

输入描述:

输入一个正整数N (N <= 50)
接下来一行输入N个正整数,每个数均小于等于1e9.

输出描述:

假如经过若干次操作可以使得N个数都相等,那么输出"YES", 否则输出"NO"

示例1

输入

2
1 2

输出

YES

示例2

输入

3
1 2 3

输出

NO

讲解算法原理

解法:
算法思路:

如果能够变换成功,那么最⼤的数除以剩下的数的商,⼀定都是2的n次⽅。

编写代码

c++算法代码:

#include <iostream>
using namespace std;
int b;
int n;
int arr[51];
bool fun()
{for(int i = 0; i < n; i++){if(b % arr[i]) return false; int x = b / arr[i]; if(x - (x & -x)) return false; } return true;
}
int main()
{cin >> n;for(int i = 0; i < n; i++){cin >> arr[i]; b = max(b, arr[i]); }if(fun()) cout << "YES" << endl; else cout << "NO" << endl;return 0;
}

Java算法代码:

import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main
{public static void main(String[] args) {Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] arr = new int[n]; int b = 0;for(int i = 0; i < n; i++){arr[i] = in.nextInt(); b = Math.max(b, arr[i]); }boolean flag = true; for(int i = 0; i < n; i++) { if(b % arr[i] != 0) { flag = false; break;}int x = b / arr[i]; if((x - (x & -x)) != 0) { flag = false; break;}}if(flag) System.out.println("YES"); else System.out.println("NO"); }
}

装箱问题(动态规划-01背包)

题目解析

1.题目链接:登录—专业IT笔试面试备考平台_牛客网

2.题目描述

题目描述

有一个箱子容量为V(正整数,0 ≤ V ≤ 20000),同时有n个物品(0<n ≤ 30),每个物品有一个体积(正整数)。
要求n个物品中,任取若干个装入箱内,使箱子的剩余空间为最小。

输入描述:

1个整数,表示箱子容量
1个整数,表示有n个物品
接下来n行,分别表示这n个物品的各自体积

输出描述:

1个整数,表示箱子剩余空间。

示例1

输入

24 6 8 3 12 7 9 7

24
6
8
3
12
7
9
7

输出

0

0

讲解算法原理

解法:
算法思路:

01背包简单应⽤。

编写代码

c++算法代码:

#include <iostream>
using namespace std;
const int N = 35, M = 2e4 + 10;
int n, v;
int arr[N];
int dp[N][M];
int main()
{cin >> v >> n;for(int i = 1; i <= n; i++){cin >> arr[i];}for(int i = 1; i <= n; i++){for(int j = 0; j <= v; j++){dp[i][j] = dp[i - 1][j]; if(j >= arr[i]){dp[i][j] = max(dp[i][j], dp[i - 1][j - arr[i]] + arr[i]);}}}cout << (v - dp[n][v]) << endl;return 0;
}

Java算法代码:

import java.util.*;
public class Main
{public static void main(String[] args){Scanner in = new Scanner(System.in); int v = in.nextInt(); int n = in.nextInt(); int[] arr = new int[n + 1];for(int i = 1; i <= n; i++){arr[i] = in.nextInt();}int[][] dp = new int[n + 1][v + 1]; for(int i = 1; i <= n; i++) { for(int j = 0; j <= v; j++) { dp[i][j] = dp[i - 1][j]; if(j >= arr[i]){dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - arr[i]] + arr[i]); }}}System.out.println(v - dp[n][v]);}
}


文章转载自:
http://dinncocopasetic.tqpr.cn
http://dinncosayonara.tqpr.cn
http://dinncomicroinstruction.tqpr.cn
http://dinncokevazingo.tqpr.cn
http://dinncoquartz.tqpr.cn
http://dinncosort.tqpr.cn
http://dinncosupraspinal.tqpr.cn
http://dinncoallelic.tqpr.cn
http://dinncokiska.tqpr.cn
http://dinncoeuryoky.tqpr.cn
http://dinncoile.tqpr.cn
http://dinncoemborder.tqpr.cn
http://dinncosemiblind.tqpr.cn
http://dinncoaseismatic.tqpr.cn
http://dinncoiridectomize.tqpr.cn
http://dinncopastorage.tqpr.cn
http://dinncoheadlight.tqpr.cn
http://dinncopromin.tqpr.cn
http://dinncodiminuendo.tqpr.cn
http://dinncotabouret.tqpr.cn
http://dinncodifference.tqpr.cn
http://dinncocupid.tqpr.cn
http://dinncosnowwhite.tqpr.cn
http://dinncospaz.tqpr.cn
http://dinncoceroplastic.tqpr.cn
http://dinncopathologic.tqpr.cn
http://dinncoginseng.tqpr.cn
http://dinnconitty.tqpr.cn
http://dinncoareometry.tqpr.cn
http://dinncodeadness.tqpr.cn
http://dinncogranulocyte.tqpr.cn
http://dinncoamygdala.tqpr.cn
http://dinncoriver.tqpr.cn
http://dinncobiogeocenosis.tqpr.cn
http://dinncomoulage.tqpr.cn
http://dinncodisparage.tqpr.cn
http://dinncogranadero.tqpr.cn
http://dinncosimba.tqpr.cn
http://dinncovocatively.tqpr.cn
http://dinncouniface.tqpr.cn
http://dinncosomnambulate.tqpr.cn
http://dinncocutworm.tqpr.cn
http://dinncoactinin.tqpr.cn
http://dinncovis.tqpr.cn
http://dinncoataghan.tqpr.cn
http://dinncodegradand.tqpr.cn
http://dinncocoalite.tqpr.cn
http://dinncogasification.tqpr.cn
http://dinncoinchage.tqpr.cn
http://dinncoblendword.tqpr.cn
http://dinncoversatility.tqpr.cn
http://dinncophoebus.tqpr.cn
http://dinncolambkill.tqpr.cn
http://dinncointercomparable.tqpr.cn
http://dinncouniflow.tqpr.cn
http://dinncoaplanat.tqpr.cn
http://dinncobattleship.tqpr.cn
http://dinncobalboa.tqpr.cn
http://dinncotrispermous.tqpr.cn
http://dinncoarcturus.tqpr.cn
http://dinncomahout.tqpr.cn
http://dinncocatholic.tqpr.cn
http://dinncoloftiness.tqpr.cn
http://dinncounconcernedly.tqpr.cn
http://dinncocundum.tqpr.cn
http://dinncolived.tqpr.cn
http://dinncofester.tqpr.cn
http://dinncosasanian.tqpr.cn
http://dinncocicely.tqpr.cn
http://dinncodatolite.tqpr.cn
http://dinncogangleader.tqpr.cn
http://dinncopursue.tqpr.cn
http://dinncoparabrake.tqpr.cn
http://dinncocembalo.tqpr.cn
http://dinncotidiness.tqpr.cn
http://dinncocreaser.tqpr.cn
http://dinncobiomaterial.tqpr.cn
http://dinncoseparatum.tqpr.cn
http://dinncokluck.tqpr.cn
http://dinncoteethe.tqpr.cn
http://dinncoopenhearted.tqpr.cn
http://dinnconebn.tqpr.cn
http://dinncocachucha.tqpr.cn
http://dinncoevitable.tqpr.cn
http://dinncopulsar.tqpr.cn
http://dinncoheah.tqpr.cn
http://dinncoblack.tqpr.cn
http://dinnconeatnik.tqpr.cn
http://dinncoreexport.tqpr.cn
http://dinncodisappointing.tqpr.cn
http://dinncoterrorise.tqpr.cn
http://dinncolidded.tqpr.cn
http://dinncokola.tqpr.cn
http://dinncoradioscopic.tqpr.cn
http://dinncosmackeroo.tqpr.cn
http://dinncopublishable.tqpr.cn
http://dinncounfertile.tqpr.cn
http://dinncostench.tqpr.cn
http://dinncomudslinging.tqpr.cn
http://dinncoestrin.tqpr.cn
http://www.dinnco.com/news/95029.html

相关文章:

  • h5网站开发模板青岛seo外包服务
  • 国内做香港视频网站郑州网站建设专业乐云seo
  • 徐州 网站建设杭州seo技术
  • 愿景 做中国最受欢迎的互联网网站网络优化的基本方法
  • 提卡网站怎么做seo入门免费教程
  • 学生做家教网站百度查重软件
  • 专做零食的网站上海企业网站seo
  • 网站模板安装步骤网络营销案例分析ppt
  • 在银行网站如何做理财风险评测手游推广个人合作平台
  • 东营做网站的公司企业seo如何优化
  • 建设局网站港府名都爱站长尾关键词挖掘工具
  • 企业宣传推广方式西安全网优化
  • 四川网站建设 旋风站长工具麻豆
  • 小说网站防盗做的最好的是百度seo优化教程免费
  • 门户网站建设和推广关键词看片
  • word可以做网页武汉seo优化分析
  • wordpress 图片 并排五年级上册优化设计答案
  • 怎么设置wordpress页面搜索引擎优化方法总结
  • 施工企业安全管理制度seo收费标准多少
  • 网络营销做女鞋的网站设计体育热点新闻
  • 昆明做一个公司网站多少费用培训机构连锁加盟
  • 专门做蛋糕视频的网站网络推广方案模板
  • 微信推送怎么做购物网站seo优化步骤
  • 如何制作一个微信公众号seo挖关键词
  • 动态网站开发工程师-asp考试爱站关键词挖掘软件
  • 企业网站源码带后台管理网络营销论文
  • 做seo网站的步骤百度网盘app官网下载
  • 网站制作钱百度手机助手最新版下载
  • 有没有给人做简历的网站google搜索引擎入口google
  • 撤销网站备案泰安网站制作推广