纪中10日 2313. 动态仙人掌

(File IO): input:dinosaur.in output:dinosaur.out

时间限制: 1500 ms  空间限制: 524288 KB  具体限制  

Goto ProblemSet

题目描述

沙雕游戏……反正我没玩过……

输入

输出

样例输入

数据范围限制

Solution

考试时想的是对的

为什么就是没有分呢?

首先看看仙人掌有几种情况

situation1

两个比较分开的仙人掌……

小恐龙按照这样走(跳),并没有什么特殊操作。这时的最高高度是两个仙人掌中最高的高度。

situation2

两个靠的比较近的仙人掌……

先看第一个,为了高度尽量小,当然选择擦边跳了

但是恐龙只有落地才能跳呀……要是它跳完第一个就落地,再起跳,一定会装上第二个仙人掌的!

所以它只能一次性的跳过两个仙人掌……

求最高点:

设第一个的高度为a,第二个的高度为b,两个之间的距离为c;

标点

解:

因为△ABC是直角等腰三角形

所以AD=DC=a

同理可得:

EG=FG=b

所以AF=AD+DG+GF=a+b+c

延长AB,EF,交于H点

△AHF亦为直角等腰三角形

所以AH=HF=AF/2=(a+b+c)/2

那么就可以把两个仙人掌合成一个更高的了

Code

  1. #include<iostream>//不想OI一场空,千万别用万能头
  2. #include<algorithm>//快排sort()
  3. #include<cstdio>//能不用cin就不用
  4. #include<cstring>
  5. #include<map>
  6. #include<vector>
  7. #define IL inline
  8. using namespace std;
  9. IL void fin(){freopen("dinosaur.in","r",stdin);}
  10. IL void fout(){freopen("dinosaur.out","w",stdout);}
  11. IL void fio()
  12. {
  13. fin();
  14. fout();
  15. }
  16.  
  17. struct node{
  18. double p;
  19. double h;
  20. }din[];
  21. bool cmp(node ta,node tb)
  22. {
  23. return ta.p<tb.p;
  24. }
  25. int n,tp,th,maxn;
  26. double ans=-;
  27. int main()
  28. {
  29. // fio();
  30. cin>>n;
  31. for(int i=;i<n;i++)
  32. {
  33. scanf("%d%d",&tp,&th);
  34. din[i].p=tp;
  35. din[i].h=th;
  36. ans=max(ans,(double)din[i].h);
  37. if(din[i].p-din[i].h<){
  38. cout<<"-1\n";
  39. return ;
  40. }
  41. }
  42. sort(din,din+n,cmp);
  43. int a,b,c;
  44. for(int i=;i<n-;i++)
  45. {
  46. c=din[i+].p+din[i].p;
  47. a=din[i].h;
  48. b=din[i+].h;
  49. if(c>=a+b)
  50. {
  51. ans=max(ans,(double)max(a,b));
  52. }
  53. else
  54. {
  55. ans=max(ans,(a+b+c)/2.0);
  56. din[i+].p=(a+din[i].p+din[i+].p-b)/2.0;
  57. din[i+].h=(a+b+c)/2.0;
  58. }
  59. }
  60. printf("%.1lf",ans);
  61. return ;
  62. }

Code std

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cmath>
  5. using namespace std;
  6. struct cly
  7. {
  8. int longn,left,right;
  9. }a[];
  10. double ans;
  11. int n,p[],h[],l,r,i;
  12. bool cmd(cly x,cly y)
  13. {
  14. return x.left<y.left;
  15. }
  16. int main()
  17. {
  18. // freopen("dinosaur.in","r",stdin);
  19. // freopen("dinosaur.out","w",stdout);
  20. cin>>n;
  21. for(i=;i<=n;i++)
  22. {
  23. scanf("%d%d",p+i,h+i);
  24. a[i]=(cly){h[i],p[i]-h[i],p[i]+h[i]};
  25. }
  26. sort(a+,a++n,cmd);
  27. if(a[].left<)
  28. {
  29. cout<<"-1";
  30. return ;
  31. }
  32. l=a[].left;
  33. r=a[].right;
  34. i=;
  35. while(i<n)
  36. {
  37. if(r<=a[i+].left)
  38. {
  39. ans=max(ans,1.0*(r-l)/);
  40. i++;
  41. l=a[i].left;
  42. r=a[i].right;
  43. }
  44. else if(r>=a[i+].right)
  45. {
  46. i++;
  47. }
  48. else
  49. {
  50. i++;
  51. r=a[i].right;
  52. }
  53. }
  54. ans=max(ans,1.0*(r-l)/);
  55. printf("%.1lf",ans);
  56. return ;
  57. }

纪中10日T1 2313. 动态仙人掌的更多相关文章

  1. 纪中10日T1 2300. 【noip普及组第一题】模板题

    2300. [noip普及组第一题]模板题 (File IO): input:template.in output:template.out 时间限制: 1000 ms  空间限制: 262144 K ...

  2. 纪中17日T1 2321. 方程

    纪中17日T1 2321. 方程 (File IO): input:cti.in output:cti.out 时间限制: 1000 ms  空间限制: 262144 KB  具体限制   Goto ...

  3. 纪中5日T1 1564. 旅游

    1564. 旅游 题目描述 输入N个数,从中选择一些出来计算出总和,问有多少种选法使得和为质数. 输入 第一行一个整数N. 第二行N个整数,表示这N个数的值. 输出 一个整数,表示方案数. 样例输入 ...

  4. 纪中12日T1 2307. 选择

    2307. 选择 (File IO): input:choose.in output:choose.out 时间限制: 1000 ms  空间限制: 262144 KB  具体限制   Goto Pr ...

  5. 纪中10日T3 2296. 神殿 bfs

    2296. 神殿 (File IO): input:temple.in output:temple.out 时间限制: 1500 ms  空间限制: 524288 KB  具体限制 Goto Prob ...

  6. 纪中21日T3 2118. 【2016-12-30普及组模拟】最大公约数

    纪中21日T3 2118. 最大公约数 (File IO): input:gcd.in output:gcd.out 时间限制: 1000 ms  空间限制: 262144 KB  具体限制 Goto ...

  7. 纪中23日c组T2 2159. 【2017.7.11普及】max 洛谷P1249 最大乘积

    纪中2159. max 洛谷P1249 最大乘积 说明:这两题基本完全相同,故放在一起写题解 纪中2159. max (File IO): input:max.in output:max.out 时间 ...

  8. 纪中23日c组T3 2161. 【2017.7.11普及】围攻 斐波那契数列

    2161. 围攻 (File IO): input:siege.in output:siege.out 时间限制: 1000 ms  空间限制: 262144 KB  具体限制   Goto Prob ...

  9. 洛谷P1880 [NOI1995]石子合并 纪中21日c组T4 2119. 【2016-12-30普及组模拟】环状石子归并

    洛谷P1880 石子合并 纪中2119. 环状石子归并 洛谷传送门 题目描述1 在一个圆形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石 ...

随机推荐

  1. Ceph 存储集群1-配置:硬盘和文件系统、配置 Ceph、网络选项、认证选项和监控器选项

    所有 Ceph 部署都始于 Ceph 存储集群.基于 RADOS 的 Ceph 对象存储集群包括两类守护进程: 1.对象存储守护进程( OSD )把存储节点上的数据存储为对象: 2.Ceph 监视器( ...

  2. 9. Palindrome Number QuestionEditorial Solution

    Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...

  3. 基于TensorFlow的MNIST手写数字识别-深入

    构建多层卷积神经网络时需要多组W和偏移项b,我们封装2个方法来产生W和b 初级MNIST中用0初始化W和b,这里用噪声初始化进行对称打破,防止产生梯度0,同时用一个小的正值来初始化b避免dead ne ...

  4. [python之路]简单介绍

    python介绍 #python是一个什么样的语言?编译型和解释型静态语言和动态语言强类型定义语言和弱类型定义语言python是一门动态解释性的强类型定义语言. #Python的优缺点##优点Pyth ...

  5. CCF_201612-3_炉石传说

    http://115.28.138.223/view.page?gpid=T45 模拟. #include<iostream> #include<cstring> #inclu ...

  6. HDU_5057_分块

    http://acm.hdu.edu.cn/showproblem.php?pid=5057 分块,保存每个块中每位对应数字的和,复杂的是getmum,左右下标所在的块不能直接读取block数组,要重 ...

  7. 题解 USACO12DEC【逃跑的BarnRunning Away From…】

    期末考前写题解,\(rp++! \ rp++! \ rp++!\) \[ description \] 给出一个以 \(1\) 为根的边带权有根树,给定一个参数 \(L\) ,问每个点的子树中与它距离 ...

  8. mongodb 配置文件解释(转)

    Mongodb 3.x配置说明,本文内容忽略了Enterprise版和一些不常用的配置. 一.配置说明 在Mongod安装包中,包含2个进程启动文件:mongod和mongos:其中mongd是核心基 ...

  9. C# 把带有父子关系的数据转化为------树形结构的数据 ,以及 找出父子级关系的数据中里面的根数据Id

    紧接上一篇,将List<Menu>的扁平结构数据, 转换成树形结构的数据 返回给前端   ,   废话不多说,开撸! --------------------- 步骤: 1. 建 Menu ...

  10. Bound Method and Unbound Method - 绑定方法 与 非绑定方法

    Bound Method and Unbound Method 通常有两种方法对类的方法(instance.method)/属性(class.attribute)进行引用, 一种称做 Bound Me ...