纪中10日T1 2313. 动态仙人掌
纪中10日 2313. 动态仙人掌
(File IO): input:dinosaur.in output:dinosaur.out
题目描述

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

输出

样例输入

数据范围限制

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
#include<iostream>//不想OI一场空,千万别用万能头
#include<algorithm>//快排sort()
#include<cstdio>//能不用cin就不用
#include<cstring>
#include<map>
#include<vector>
#define IL inline
using namespace std;
IL void fin(){freopen("dinosaur.in","r",stdin);}
IL void fout(){freopen("dinosaur.out","w",stdout);}
IL void fio()
{
fin();
fout();
} struct node{
double p;
double h;
}din[];
bool cmp(node ta,node tb)
{
return ta.p<tb.p;
}
int n,tp,th,maxn;
double ans=-;
int main()
{
// fio();
cin>>n;
for(int i=;i<n;i++)
{
scanf("%d%d",&tp,&th);
din[i].p=tp;
din[i].h=th;
ans=max(ans,(double)din[i].h);
if(din[i].p-din[i].h<){
cout<<"-1\n";
return ;
}
}
sort(din,din+n,cmp);
int a,b,c;
for(int i=;i<n-;i++)
{
c=din[i+].p+din[i].p;
a=din[i].h;
b=din[i+].h;
if(c>=a+b)
{
ans=max(ans,(double)max(a,b));
}
else
{
ans=max(ans,(a+b+c)/2.0);
din[i+].p=(a+din[i].p+din[i+].p-b)/2.0;
din[i+].h=(a+b+c)/2.0;
}
}
printf("%.1lf",ans);
return ;
}
Code std
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
struct cly
{
int longn,left,right;
}a[];
double ans;
int n,p[],h[],l,r,i;
bool cmd(cly x,cly y)
{
return x.left<y.left;
}
int main()
{
// freopen("dinosaur.in","r",stdin);
// freopen("dinosaur.out","w",stdout);
cin>>n;
for(i=;i<=n;i++)
{
scanf("%d%d",p+i,h+i);
a[i]=(cly){h[i],p[i]-h[i],p[i]+h[i]};
}
sort(a+,a++n,cmd);
if(a[].left<)
{
cout<<"-1";
return ;
}
l=a[].left;
r=a[].right;
i=;
while(i<n)
{
if(r<=a[i+].left)
{
ans=max(ans,1.0*(r-l)/);
i++;
l=a[i].left;
r=a[i].right;
}
else if(r>=a[i+].right)
{
i++;
}
else
{
i++;
r=a[i].right;
}
}
ans=max(ans,1.0*(r-l)/);
printf("%.1lf",ans);
return ;
}
纪中10日T1 2313. 动态仙人掌的更多相关文章
- 纪中10日T1 2300. 【noip普及组第一题】模板题
2300. [noip普及组第一题]模板题 (File IO): input:template.in output:template.out 时间限制: 1000 ms 空间限制: 262144 K ...
- 纪中17日T1 2321. 方程
纪中17日T1 2321. 方程 (File IO): input:cti.in output:cti.out 时间限制: 1000 ms 空间限制: 262144 KB 具体限制 Goto ...
- 纪中5日T1 1564. 旅游
1564. 旅游 题目描述 输入N个数,从中选择一些出来计算出总和,问有多少种选法使得和为质数. 输入 第一行一个整数N. 第二行N个整数,表示这N个数的值. 输出 一个整数,表示方案数. 样例输入 ...
- 纪中12日T1 2307. 选择
2307. 选择 (File IO): input:choose.in output:choose.out 时间限制: 1000 ms 空间限制: 262144 KB 具体限制 Goto Pr ...
- 纪中10日T3 2296. 神殿 bfs
2296. 神殿 (File IO): input:temple.in output:temple.out 时间限制: 1500 ms 空间限制: 524288 KB 具体限制 Goto Prob ...
- 纪中21日T3 2118. 【2016-12-30普及组模拟】最大公约数
纪中21日T3 2118. 最大公约数 (File IO): input:gcd.in output:gcd.out 时间限制: 1000 ms 空间限制: 262144 KB 具体限制 Goto ...
- 纪中23日c组T2 2159. 【2017.7.11普及】max 洛谷P1249 最大乘积
纪中2159. max 洛谷P1249 最大乘积 说明:这两题基本完全相同,故放在一起写题解 纪中2159. max (File IO): input:max.in output:max.out 时间 ...
- 纪中23日c组T3 2161. 【2017.7.11普及】围攻 斐波那契数列
2161. 围攻 (File IO): input:siege.in output:siege.out 时间限制: 1000 ms 空间限制: 262144 KB 具体限制 Goto Prob ...
- 洛谷P1880 [NOI1995]石子合并 纪中21日c组T4 2119. 【2016-12-30普及组模拟】环状石子归并
洛谷P1880 石子合并 纪中2119. 环状石子归并 洛谷传送门 题目描述1 在一个圆形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石 ...
随机推荐
- qt creator源码全方面分析(2-1-1)
目录 C++的策略/二进制兼容性问题 定义 ABI注意事项 可做与不可做 库程序员的技巧 位标志 使用d指针 故障排除 在没有d指针的情况下将新数据成员添加到类中 添加已重新实现的虚函数 使用新类 向 ...
- 拖延症?贪玩?来试试"百万金币时间管理法"
中午吃完饭就想休息? 一到假期就起不来? 总是想玩游戏? 究其原因是因为我们没有深刻意识到时间的价值. 这点在大气爱智慧的视频:懂这个道理,保证让你快速自律起来!拯救拖延症,更好的戒掉不良习惯中有讲到 ...
- Andriod you must restart adb and eclipse
今天看着视频 学习着 andriod ,启动 的时候 竟然报错 我试了N种google来的方法,都失效,现在把我的解决方法告诉大家,希望能帮到大家. 首先,我先罗列下我搜到的方法,大家也可以尝试. 1 ...
- golang 运算符
/* 算术运算符 : + - * / % ++ -- 关系运算符 : == != > < >= <= 逻辑运算符 : && || ! 赋值运算符 : = += ...
- pytorch之 optimizer comparison
import torch import torch.utils.data as Data import torch.nn.functional as F import matplotlib.pyplo ...
- cdh集群hive升级,数据不丢失
1.下载hive-1.2.1安装包 http://archive.apache.org/dist/hive/hive-1.2.1/apache-hive-1.2.1-bin.tar.gz 2.将安装包 ...
- 【重新整理】log4j 2的使用
一 概述 1.1 日志框架 日志接口(slf4j) slf4j是对所有日志框架制定的一种规范.标准.接口,并不是一个框架的具体的实现,因为接口并不能独立使用,需要和具体的日志框架实现配合使用(如log ...
- 【转载】IPSec-Tools配置
来源:https://blog.csdn.net/zt698/article/details/4811604 1 介绍从Linux 2.6内核开始,内核就自身带有IPSec模块,配合IPS ...
- Leetcode:面试题 04.03. 特定深度节点链表
Leetcode:面试题 04.03. 特定深度节点链表 Leetcode:面试题 04.03. 特定深度节点链表 先贴一下自己写过一个模板,按层数遍历: https://www.cnblogs.co ...
- TFT液晶显示屏之绘图板应用
应用范例: 使用 TOPWAY Smart LCD (HMT043FC-1C) 绘图板应用 第一步建立工程 ① 开TOPWAY TML Graphic Editor 2017 V1.04软件, 点击菜 ...