poj2674
来源:互联网 发布:录音剪辑软件 编辑:程序博客网 时间:2024/05/17 02:10
#include <iostream>#include <string>#include <algorithm>#include <iomanip>#include<cstdio>#include<math.h>using namespace std;int n;double l,v;struct Inhsbit{ double pos; char dir; string name; bool operator < (const Inhsbit& t ) const { return pos<t.pos; }}in[33000];int main(){ while(cin>>n&&n) { cin>>l>>v; for(int i=0;i<n;i++) { cin>>in[i].dir>>in[i].pos>>in[i].name; } sort(in,in+n); double dis=0.0; int loc=0; for(int i=0;i<n;i++) { double d; if(in[i].dir=='p'||in[i].dir=='P') d=l-in[i].pos; else d=in[i].pos; if(d>dis+1e-6) { dis=d; loc=i; } } int cnt=0; if(in[loc].dir=='p'||in[loc].dir=='P') { for(int i=loc;i<n;i++) { if(in[i].dir=='n'||in[i].dir=='N') cnt++; } } else { for(int i=0;i<=loc;i++) { if(in[i].dir=='p'||in[i].dir=='P') cnt--; } } cout << setw(13) << fixed << setprecision(2) << (int)(dis/v * 100) / 100.0 << ' ' << in[loc+cnt].name <<endl; } return 0;}
这一题比较坑,首先它第二次定位时不能使用sort,否则会超时,另外出题者32000的数据别有用心,时间卡的狠死,sort完全无法通过。
其次两位小数之后不是四舍五入,而是直接截掉。
另外据说N大小写不分。
最后个人参考了码农场的代码,但是个人觉得它的代码在处理position==0的时候不太好,所以我还是自己另外加了dir,虽然繁琐了些,却也没什么不好
0 0
- poj2674
- poj2674浅谈
- poj2674 弹性碰撞
- POJ2674运动碰撞模拟
- POJ2674-Linear world
- poj2674 弹性碰撞
- POJ2674 Linear world 弹性碰撞
- POJ2674-Linear world【弹性碰撞】
- poj2674 弹性碰撞 Linear world
- java写飞机大战四
- 一个初始驱动化函数
- 禅师与青年
- ROS 教程之 vision: 摄像头标定camera calibration
- 非软网络www.2ubu.com
- poj2674
- Redis常用命令总结
- scsi和光驱,硬盘,u盘都有关啊
- HDU 1689 Just a Hook 线段树区间更新求和
- linux性能问题(CPU,内存,磁盘I/O,网络)
- 集合框架
- 实现Comparable接口对树形结构数据进行排序
- 类与对象
- [ACM Steps] Hat's Fibonacci 大数加法 另一种节约空间的方法