poj 2674 线性世界 弹性碰撞
弹性碰撞的题目一般都是指碰到就会掉转方向的一类题目,这里我们可以忽略掉头,仅仅看成擦肩而过,交换名字等等
题意:一条线上N只蚂蚁,每只蚂蚁速度固定,方向和坐标不同,碰头后掉头,求最后掉下去那只蚂蚁的名字。
思路:
- 如果只有一只蚂蚁,就可以计算了
- 但是如果题目很多只,这个时候就要用上弹性碰撞题目的解题技巧
- 到最远的那只,确定它前进的方 向
- 找到前进方向有多少只跟其方向相反(即交换了多少次名字)
- 最后交换名字的那一只就是ans
特别主要开始时,要通过position来区分往右还是左
解决题目的代码:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <iomanip>
using namespace std;
#define maxn 32000+16 struct node {
double position;
string name;
bool operator< (const node other)const {
return abs(position) < abs((other.position));
}
}ih[maxn]; int main()
{
int n;
while (cin >> n && n)
{
double l, v;
cin >> l >> v;
for (int i = ; i < n; i++)
{
char pn;
cin >> pn >> ih[i].position >> ih[i].name;
if (pn == 'n' || pn == 'N')
{
ih[i].position = -ih[i].position;
}
}
sort(ih, ih + n);
//找到最远的点
double max_d = 0.0;
int id=;
bool right = true;
for (int i = ; i < n; i++)
{
double ps = (ih[i].position < 0.0 ? : l) - ih[i].position;
if (max_d < ps)
{
max_d = ps;
id = i;
right = ih[i].position > 0.0;
}
}
//与这个点方向相反的点有
int count = ;
if (right)
{
for (int i = id; i < n; i++)
{
if (ih[i].position < 0.0)
count++;
}
id += count;
}
else {
for (int i = id; i>=; i--)
{
if (ih[i].position > 0.0)
count++;
}
id -= count;
}
double result = max_d / v;
cout << setw() << fixed << setprecision() << (int)(result * ) / 100.0 << ' ' << ih[id].name << endl;
}
return ;
}
poj 2674 线性世界 弹性碰撞的更多相关文章
- POJ 2674 Linear world(弹性碰撞)
Linear world Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 4426 Accepted: 1006 Desc ...
- Greedy:Linear world(POJ 2674)
Linear world 题目大意:一些人生活在线性世界中,到达线性世界两端就会消失,两个人的前进方向有两个,相遇会改变各自相遇方向,求最后一个人掉下的人的名字和时间. 其实这一题就是弹性碰撞的模 ...
- POJ 2674 Linear world
POJ 2674 Linear world 题目大意: 一条线上N只蚂蚁,每只蚂蚁速度固定,方向和坐标不同,碰头后掉头,求最后掉下去那只蚂蚁的时间和名字. 注意两点: 相撞可视为擦肩而过,蚂蚁们不管掉 ...
- POJ 1745 线性和差取余判断
POJ 1745 线性和差取余判断 题目大意:每个数都必须取到,相加或相减去,问所有的方案最后的得数中有没有一个方案可以整除k 这个题目的难点在于dp数组的安排上面 其实也就是手动模仿了一下 比如 一 ...
- poj 3684 Physics Experiment 弹性碰撞
Physics Experiment Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1489 Accepted: 509 ...
- POJ 3661 (线性DP)
题目链接: http://poj.org/problem?id=3661 题目大意:牛跑步.有N分钟,M疲劳值.每分钟跑的距离不同.每分钟可以选择跑步或是休息.一旦休息了必须休息到疲劳值为0.0疲劳值 ...
- POJ 2674
Linear world Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 2448 Accepted: 564 Descr ...
- Dirichlet's Theorem on Arithmetic Progressions POJ - 3006 线性欧拉筛
题意 给出a d n 给出数列 a,a+d,a+2d,a+3d......a+kd 问第n个数是几 保证答案不溢出 直接线性筛模拟即可 #include<cstdio> #inclu ...
- Goldbach's Conjecture POJ - 2262 线性欧拉筛水题 哥德巴赫猜想
题意 哥德巴赫猜想:任一大于2的数都可以分为两个质数之和 给一个n 分成两个质数之和 线行筛打表即可 可以拿一个数组当桶标记一下a[i] i这个数是不是素数 在线性筛后面加个装桶循环即可 #inc ...
随机推荐
- 从零开始的全栈工程师——js篇2.19(BOM)
一.BOM 浏览器对象模型 1.window.open(url,ways) url 是打开的网页地址ways 打开的方式 _self 2.window.close() 关闭当前页面 3.window. ...
- better-scroll 遇到的问题 2
问题的描述: 在歌曲列表页面使用了scroll插件,搜索了很多歌曲,页面出现滚动,选择播放一首歌曲,弹出播放器,将播放器最小化,页面回到歌曲列表,并且页面的底部出播放歌曲的信息(在没有播放歌曲的时候是 ...
- 跨平台移动开发phonegap/cordova 3.3全系列教程-helloworld
1. 建立专案(cordova) 打开cmd命令行 cordova create ACESMobile aces.mobile ACES cd aces mobile 如图 2. 安装插件 ...
- 动软代码生成器,主子表增加的时候子表的parentID无法插入问题解决方案
StringBuilder strSql=new StringBuilder(); strSql.Append("insert into HT_XunJiaMain("); str ...
- 中兴ZXR10 6905核心交换机配置案例
Connecting to 192.168.0.254:23...Connection established.To escape to local shell, press 'Ctrl+Alt+]' ...
- ICCV 2017 Best Paper Awards
[ICCV 2017 Best Paper Awards]今年的ICCV不久前公布了Best Paper得主,來自Facebook AI Research的Mask R-CNN[1],與RetineN ...
- rosservice call ERROR:Unable to load type ... Have you typed 'make'
you need to source in the new terminal $ source ~/catkin_ws/devel/setup.bash
- bzoj4943 [Noi2017]蚯蚓排队
题面:http://www.lydsy.com/JudgeOnline/upload/Noi2017D1.pdf 正解:字符串$hash$. 我在考场上写了个$map$的$hash$被卡成$40$分, ...
- Shell编程学习之重定向
这一篇讲一下重定向 有些时候你想要保存某些命令产生的输出而不是在显示器上显示它. 为了应对这样的问题 bash shell 也就提供了一些重定向的操作符. 我们先了解一些基本的应用. 输出重定向 输出 ...
- Laravel 5 : Call to undefined function Illuminate\Foundation\Bootstrap\mb_internal_encoding()
自己组装的apache,php,mysql phpinfo显示 OpenSSL support disabled (install ext/openssl) 判断为权限问题,所以修改如下. 1 ...