HDU 5112 A Curious Matt(水~)
来源:互联网 发布:蓝博软件 编辑:程序博客网 时间:2024/06/05 00:54
Description
一个人在跑步,给出其在n个位置的时刻,每两个相邻位置之间这个人速度恒定,忽略加速的时间,问这个人最大速度
Input
第一行为一整数T表示用例组数,每组用例第一行为一整数n,之后n行每行两个整数xi和ti表示这个人在xi时的时刻(2<=n<=10000,0<=xi,ti<=10^6)
Output
对于每组用例,输出这个人的最大速度
Sample Input
2
3
2 2
1 1
3 4
3
0 3
1 5
2 0
Sample Output
Case #1: 2.00
Case #2: 5.00
Solution
简单题,对xi升序排,更新(x[i]-x[i-1])/(t[i]-t[i-1])的最大值即可
Code
#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>using namespace std;#define maxn 11111#define INF 0x3f3f3f3ftypedef long long ll;struct node{ int t,x;}p[maxn];int T,n;int cmp(node a,node b){ if(a.t!=b.t)return a.t<b.t; return a.x<b.x;}int main(){ scanf("%d",&T); int res=1; while(T--) { scanf("%d",&n); for(int i=0;i<n;i++)scanf("%d%d",&p[i].t,&p[i].x); sort(p,p+n,cmp); double ans=0; for(int i=1;i<n;i++)ans=max(ans,abs(1.0*(p[i].x-p[i-1].x)/(p[i].t-p[i-1].t))); printf("Case #%d: ",res++,ans); printf("%.2lf\n",ans); } return 0;}
0 0
- HDU 5112 A Curious Matt(水~)
- 【瞎搞】 HDU 5112 A Curious Matt 水
- hdu 5112 A Curious Matt(排序)
- HDU 5112 A Curious Matt
- hdu 5112 A Curious Matt
- hdu 5112 A Curious Matt
- HDU 5112 A Curious Matt
- hdu 5112 A Curious Matt
- hdu 5112 A Curious Matt (java,快速输入)
- 文章标题 HDU 5112- A Curious Matt
- HDU 5112 A Curious Matt (水题)
- A Curious Matt 5112
- hdoj 5112 A Curious Matt(水题)
- hdoj-5112-A Curious Matt
- HDU 5112 A Curious Matt (14北京 排序 水题)
- HDU 5112 2014ICPC北京站现场赛 A Curious Matt
- hdu 5112 A Curious Matt (结构体+cmp函数)
- HDU-5112-A Curious Matt (2014ACM/ICPC北京赛区现场赛A题!)
- Go语言学习九:接口、错误处理
- 虚函数有个十分重要的作用,之动态绑定
- odoo8登录时,同帐号在其它客户端的连接自动退出
- Titanic: Machine Learning from Disaster——Logistic regression
- java Io reader writer 笔记3
- HDU 5112 A Curious Matt(水~)
- BZOJ 1486: [HNOI2009]最小圈
- 解决 gradlew 构建错误: 编码 GBK的不可映射字符
- 6.2.4 随机游走(Random Walk)
- Openstack 源码修改,实现nova boot 创建的虚拟机支持USB 重定向
- 大数相乘 大数类
- Http协议入门
- 网络编程中的指令号命名技巧
- 一个Android学习的地方