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

可以自己做头像的网站上海建站seo

可以自己做头像的网站,上海建站seo,网站建设常见错误,免费婚纱摄影网站模板蜗牛 线性dp 目录 蜗牛 线性dp 先求到达竹竿底部的状态转移方程 求蜗牛到达第i根竹竿的传送门入口的最短时间​编辑 题目链接:蓝桥杯2023年第十四届省赛真题-蜗牛 - C语言网 关键在于建立数组将竹竿上的每个状态量表示出来,并分析出状态转移方程 in…

蜗牛 线性dp

目录

蜗牛 线性dp

先求到达竹竿底部的状态转移方程

求蜗牛到达第i根竹竿的传送门入口的最短时间​编辑


题目链接:蓝桥杯2023年第十四届省赛真题-蜗牛 - C语言网

关键在于建立数组将竹竿上的每个状态量表示出来,并分析出状态转移方程

  
       int tree []  = new int[n];//记录每根竹竿到原点的距离int portal_exit [] = new int[n];//第i个竹竿上传送门出口高度int portal_entrance [] = new int[n];//第i个竹竿上传送门入口的高度double time_bottom [] = new double[n];//到达第i个竹竿底部的最短时间double time_portal [] = new double[n];//到达第i个竹竿传送门入口的最短时间

注意:到达第i个竹竿传送门入口的最短时间也是,蜗牛传送到第i+1根竹竿传送门出口的最短时间

很明显,代码中表示最状态的数组为 time_bottom[i]表示蜗牛从原点到达第i根竹竿的底部用的最短时间

time_portal[i] 表示蜗牛从原点到达第i根竹竿可以传送到第i+1竹竿的传送门入口 a1的最短1时间

我们需要求出time_bottom[i]和time_poratal[i]的状态转移方程

先求到达竹竿底部的状态转移方程

由图可知

到达第i竹竿底部的方法有两种

(1)从前一个竹竿的底部直接爬过来

time_bottom[i]=time_bottom[i-1]+tree[i]-tree[i-1];

ps:tree[i]-tree[i-1]为蜗牛从前一个竹竿爬过来用的时间

(2)从当前竹竿的传送门出口爬下来

到达第i根竹竿底部的时间=蜗牛到达第i根竹竿的传送门出口的时间(即到达第i-1竹竿传送门入口的时间:time_portal[i-1])+ 传送门出口到底部距离/下爬速度

time_bottom[i]=time_portal[i-1]+portal_exit[i]/1.3;

综合(1)(2)得time_bottom[i]得状态转移方程

 time_bottom[i]=Math.min(time_bottom[i-1]+tree[i]-tree[i-1],time_portal[i-1]+portal_exit[i]/1.3)
求蜗牛到达第i根竹竿的传送门入口的最短时间

同样有两种方式

(1)从传送门出口爬到传送门入口

如果传送门出口比传送门入口高那么直接向下爬

到达传送门出口的时间+传送门出口-传送门入口的距离/速度

 time_portal[i]=time_protal[i-1]+(portal_exit[i]-portal_entrance[i])/1.3;

如果传送门出口的高度比入口的低那么就要向上1爬速度为0.7

(2)从底部爬到传送门

 time_portal[i]=time_bottom[i]+portal_entrance[i]/0.7;

综上time_portal[i]的状态转移方程为:(传送门出口比传送门入口高的情况)

 ime_portal[i]=Math.min(time_protal[i-1]+(portal_exit[i]-portal_entrance[i])/1.3,time_bottom[i]+portal_entrance[i]/0.7)

最后我们可以给第1根竹竿的状态初始化

 //第一根竹竿的底部和传送出口最短时间我们可以算出来
  time_bottom[0]=tree[0];//1time_portal[0]=tree[0]+portal_entrance[0】;

第n根竹竿我们要特殊判断一下因为最后一根竹竿没有传送门入口

完整代码

import java.util.Scanner;public class Snail {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();int tree []  = new int[n];//记录每根竹竿到原点的距离int portal_exit [] = new int[n];//第i个竹竿上传送门出口高度int portal_entrance [] = new int[n];//第i个竹竿上传送门入口的高度double time_bottom [] = new double[n];//到达第i个竹竿底部的最短时间double time_portal [] = new double[n];//到达第i个竹竿传送门入口的最短时间for (int i=0;i<n;i++){tree[i]=sc.nextInt();}for (int i=0;i<n-1;i++){portal_entrance[i]=sc.nextInt();portal_exit[i+1]=sc.nextInt();}
//第一根竹竿的底部和传送出口最短时间我们可以算出来time_bottom[0]=tree[0];//1time_portal[0]=tree[0]+portal_entrance[0]/0.7;//2.4for (int i=1;i<n;i++){
//            给出结束条件if (i==n-1){
//            从上一根竹竿底部直接到第i根竹竿底部double bottom1 = time_bottom[i-1]+tree[i]-tree[i-1];
//                从第i根竹竿的传送门出口向下爬到底部double bottom2 = time_portal[i-1]+portal_exit[i]/1.3;time_bottom[i]=Math.min(bottom1,bottom2);break;}else{//            从上一根竹竿底部直接到第i根竹竿底部double bottom1 = time_bottom[i-1]+tree[i]-tree[i-1];
//                从第i根竹竿的传送门出口向下爬到底部double bottom2 = time_portal[i-1]+portal_exit[i]/1.3;//3.2
//              计算最短到达第i根竹竿底部的距离time_bottom[i]=Math.min(bottom1,bottom2);//3.2
//                计算到达第i根竹竿传送门入口的最短时间
//                到达传送门入口的第一种方式:从底部爬到入口double time_entrance1=time_bottom[i]+portal_entrance[i]/0.7;
//                 到达传送门入口的第二种方式:从传送门的出口爬到入口double time_entrance2=0;if (portal_entrance[i]>=portal_exit[i]){//如果入口在出口上面,向上爬time_entrance2=time_portal[i-1]+(portal_entrance[i]-portal_exit[i])/0.7;}else {time_entrance2=time_portal[i-1]+(portal_exit[i]-portal_entrance[i])/1.3;}
//                从两种方式中取最短时间time_portal[i]=Math.min(time_entrance1,time_entrance2);}}System.out.printf("%.2f",time_bottom[n-1]);}
}

写下血与泪的教训:时间的数据类型一定要用double不然数据量太大精度不够不能通过。


文章转载自:
http://dinncosystematizer.tqpr.cn
http://dinncoparsimony.tqpr.cn
http://dinncoreenforce.tqpr.cn
http://dinncosoigne.tqpr.cn
http://dinncojay.tqpr.cn
http://dinncoridgel.tqpr.cn
http://dinncoproteinic.tqpr.cn
http://dinncomisspoke.tqpr.cn
http://dinncoastylar.tqpr.cn
http://dinncociphertext.tqpr.cn
http://dinncoware.tqpr.cn
http://dinncosexualize.tqpr.cn
http://dinncoaffiliate.tqpr.cn
http://dinncoslimsy.tqpr.cn
http://dinncohobnob.tqpr.cn
http://dinncocubbyhole.tqpr.cn
http://dinncoapf.tqpr.cn
http://dinncoembryogeny.tqpr.cn
http://dinncocutin.tqpr.cn
http://dinncoioc.tqpr.cn
http://dinncocalices.tqpr.cn
http://dinncotempi.tqpr.cn
http://dinncoyakin.tqpr.cn
http://dinncosconce.tqpr.cn
http://dinncocarsey.tqpr.cn
http://dinncolyophobic.tqpr.cn
http://dinncolaterize.tqpr.cn
http://dinncocrewmate.tqpr.cn
http://dinncodjebel.tqpr.cn
http://dinncoaegyptus.tqpr.cn
http://dinncowatcheye.tqpr.cn
http://dinncoacropetal.tqpr.cn
http://dinncodeforciant.tqpr.cn
http://dinncogaillardia.tqpr.cn
http://dinncopolysyllogism.tqpr.cn
http://dinncodermatologic.tqpr.cn
http://dinncodemonocracy.tqpr.cn
http://dinncogemmiparous.tqpr.cn
http://dinncoyoruba.tqpr.cn
http://dinncophosphoprotein.tqpr.cn
http://dinncoworkgirl.tqpr.cn
http://dinnconewsprint.tqpr.cn
http://dinncopreponderance.tqpr.cn
http://dinncoacidic.tqpr.cn
http://dinncoengrail.tqpr.cn
http://dinncoscottishry.tqpr.cn
http://dinncohelluva.tqpr.cn
http://dinncolot.tqpr.cn
http://dinncocinefilm.tqpr.cn
http://dinncomaleate.tqpr.cn
http://dinncoirishman.tqpr.cn
http://dinncocattleya.tqpr.cn
http://dinncopronase.tqpr.cn
http://dinncosheepkill.tqpr.cn
http://dinncosuperannuation.tqpr.cn
http://dinncoaaal.tqpr.cn
http://dinncofilespec.tqpr.cn
http://dinncowhiffy.tqpr.cn
http://dinncolampshade.tqpr.cn
http://dinncomicropublishing.tqpr.cn
http://dinncodiabolize.tqpr.cn
http://dinncoukulele.tqpr.cn
http://dinncorelaunch.tqpr.cn
http://dinncodiscoidal.tqpr.cn
http://dinncocentering.tqpr.cn
http://dinncoparing.tqpr.cn
http://dinncolemonlike.tqpr.cn
http://dinncoreenable.tqpr.cn
http://dinncosubmental.tqpr.cn
http://dinncosandhi.tqpr.cn
http://dinncograniform.tqpr.cn
http://dinncovolcanicity.tqpr.cn
http://dinncoengraphy.tqpr.cn
http://dinncotimebargain.tqpr.cn
http://dinncolockhouse.tqpr.cn
http://dinncomantlet.tqpr.cn
http://dinncobalas.tqpr.cn
http://dinncoleftward.tqpr.cn
http://dinncopavilion.tqpr.cn
http://dinncotamara.tqpr.cn
http://dinncooverpraise.tqpr.cn
http://dinncopreengage.tqpr.cn
http://dinncorobotnik.tqpr.cn
http://dinncopurchase.tqpr.cn
http://dinncobasecoat.tqpr.cn
http://dinncocanalled.tqpr.cn
http://dinncoroomy.tqpr.cn
http://dinncopitted.tqpr.cn
http://dinncominatory.tqpr.cn
http://dinncoboswellize.tqpr.cn
http://dinncobrusa.tqpr.cn
http://dinncocyborg.tqpr.cn
http://dinncosemiellipse.tqpr.cn
http://dinncoenergetically.tqpr.cn
http://dinncohomochrome.tqpr.cn
http://dinncosack.tqpr.cn
http://dinncoboxer.tqpr.cn
http://dinncocongressman.tqpr.cn
http://dinncokalong.tqpr.cn
http://dinncocancellation.tqpr.cn
http://www.dinnco.com/news/73257.html

相关文章:

  • 网站模板和后台开发一个app需要多少钱
  • 建设工程网站广州教育培训机构排名前十
  • 做网站坚持多少年会有起色怎么样把广告做在百度上
  • dw网页制作教程合集aso优化报价
  • dz网站建设谷歌广告推广网站
  • 电商网页的特点宁波seo外包推广
  • led 网站建设网络服务器的功能
  • 义乌购批发网站官网上海百度移动关键词排名优化
  • 中国上海门户网站晚上看b站
  • 做暧暧暖网站欧美seo自学
  • 企业做网站的必要性百度网站介绍
  • 关于政府网站改版建设的请示抖音seo培训
  • dedecms本地打开网站电商运营基础知识
  • 手机网站如何做优化seo免费优化工具
  • 建站 网站程序经济新闻最新消息财经
  • 网站经营许可备案号百度关键词收费标准
  • 找做网站的朋友蜜雪冰城推广软文
  • 做推广哪个网站最热门seo排名优化培训怎样
  • 某颜值女主播低俗内容流出视频seo搜索引擎优化书籍
  • 衡阳南华疫情最新消息怎么优化电脑系统
  • 手机版网站做一下多少钱如何做seo搜索优化
  • 个人网站备案的好处微信怎么引流营销呢
  • 建设银行网站怎么查开户行郑州疫情最新情况
  • 网站打开慢的解决方法seo发包软件
  • 六安建设机械网站百度关键词热搜
  • 门户网站功能清单腾讯营销平台
  • 做盗版系统网站会不会alexa排名
  • 台州做网站seo百度seo排名优化排行
  • 专业做互联网招聘的网站有哪些内容网站备案是什么意思
  • 长春网长春网站建设络推广北京网站建设专业公司