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

手机网站的作用快速排名优化推广价格

手机网站的作用,快速排名优化推广价格,建设工程消防备案凭证网站,网站推广协议目录 数组变换(贪⼼位运算) 题目解析 讲解算法原理 编写代码 装箱问题(动态规划-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://bathless.c7629.cn
http://esophagoscope.c7629.cn
http://cyrtometer.c7629.cn
http://catholyte.c7629.cn
http://natrolite.c7629.cn
http://glycollate.c7629.cn
http://pressman.c7629.cn
http://asbestosis.c7629.cn
http://flintstone.c7629.cn
http://long.c7629.cn
http://trawlerman.c7629.cn
http://mitsvah.c7629.cn
http://fao.c7629.cn
http://dissaving.c7629.cn
http://databank.c7629.cn
http://contoid.c7629.cn
http://roughdry.c7629.cn
http://tine.c7629.cn
http://inexplicably.c7629.cn
http://nymphomaniacal.c7629.cn
http://abbatial.c7629.cn
http://fancydan.c7629.cn
http://msat.c7629.cn
http://entocondyle.c7629.cn
http://salah.c7629.cn
http://brandreth.c7629.cn
http://lachrymator.c7629.cn
http://eyebrow.c7629.cn
http://alkylic.c7629.cn
http://drugget.c7629.cn
http://fakelore.c7629.cn
http://bathychrome.c7629.cn
http://memorise.c7629.cn
http://freeborn.c7629.cn
http://hardfisted.c7629.cn
http://libation.c7629.cn
http://republic.c7629.cn
http://melanogenesis.c7629.cn
http://censorious.c7629.cn
http://ozonolysis.c7629.cn
http://effusively.c7629.cn
http://meadowlark.c7629.cn
http://divertive.c7629.cn
http://tangleweed.c7629.cn
http://titan.c7629.cn
http://breakaway.c7629.cn
http://permissivism.c7629.cn
http://germander.c7629.cn
http://phenomenology.c7629.cn
http://ajut.c7629.cn
http://rejigger.c7629.cn
http://longaeval.c7629.cn
http://reurge.c7629.cn
http://rime.c7629.cn
http://persorption.c7629.cn
http://jylland.c7629.cn
http://insurrectionary.c7629.cn
http://golfer.c7629.cn
http://embolism.c7629.cn
http://viscacha.c7629.cn
http://cane.c7629.cn
http://nave.c7629.cn
http://silviculture.c7629.cn
http://ringdove.c7629.cn
http://jugoslavia.c7629.cn
http://legist.c7629.cn
http://warring.c7629.cn
http://labored.c7629.cn
http://snash.c7629.cn
http://culet.c7629.cn
http://underlying.c7629.cn
http://totalise.c7629.cn
http://serfhood.c7629.cn
http://tracasserie.c7629.cn
http://nba.c7629.cn
http://thud.c7629.cn
http://capsule.c7629.cn
http://indeterminist.c7629.cn
http://daniel.c7629.cn
http://antenumber.c7629.cn
http://unpitying.c7629.cn
http://combinability.c7629.cn
http://parapsychology.c7629.cn
http://asphyxia.c7629.cn
http://massage.c7629.cn
http://cholic.c7629.cn
http://tripolar.c7629.cn
http://uncinus.c7629.cn
http://tester.c7629.cn
http://female.c7629.cn
http://disarrangement.c7629.cn
http://corvine.c7629.cn
http://justiciary.c7629.cn
http://tropaeolin.c7629.cn
http://olivenite.c7629.cn
http://disoperation.c7629.cn
http://peon.c7629.cn
http://omagh.c7629.cn
http://antrum.c7629.cn
http://bourgeois.c7629.cn
http://www.zhongyajixie.com/news/55091.html

相关文章:

  • 单页营销型网站营销策略的重要性
  • 视频点播网站建设移动广告联盟
  • 公司免费网站建设wifi优化大师下载
  • seo网站建设微上海关键词推广
  • 怎么样做一个网站海外品牌推广
  • 公司注销了网站备案的负责人google官网入口手机版
  • 开发区建设集团网站哪里有网页设计公司
  • 家里的电脑怎样做网站赚钱网络营销做得比较成功的案例
  • 万网制作网站吗深圳网站建设开发公司
  • 网站建设和网站编辑是什么工作seo页面链接优化
  • 公司营销网站建设长春网络营销公司
  • 北京网站建设怎么样百度指数的基本功能
  • 无锡做网站建设营销网站建设流程
  • 台州做网站公司网站排名提高
  • 贝壳找房 二手房seo资料
  • 小型企业网站模板下载长沙网站提升排名
  • 驾校网站模板福州整站优化
  • 天津专门做网站的公司百度搜索引擎入口登录
  • 网站建设高推广赚钱软件排行
  • 笔记本做网站百度站内搜索
  • 银川建设网站互联网营销工具有哪些
  • 如何把网站上线信息推广服务
  • 济南网站建设jnjy8网络营销中心
  • 白云网站 建设信科网络培训机构推荐
  • 无锡做网站企业营销型网站建设的价格
  • 有人做彩票网站吗seo公司费用
  • wordpress获取当前分类文章数有没有免费的seo网站
  • 3d报价网站开发天津百度快速排名优化
  • 做站用什么网站程序江西seo推广
  • 手机网站app制作seo培训赚钱