POJ 2674 Linear world
题目大意: 一条线上N只蚂蚁,每只蚂蚁速度固定,方向和坐标不同,碰头后掉头,求最后掉下去那只蚂蚁的时间和名字。
注意两点: 相撞可视为擦肩而过,蚂蚁们不管掉不掉头它们的相对位置保持不变
这个题是大白上原来的蚂蚁相撞问题(POJ 1852)的加强版
如果只考虑最后掉下去那只蚂蚁的时间(即蚂蚁全部掉下的最长时间),那么可以认为这些蚂蚁相撞时直接擦肩而过.
    但是该题还要求出最后掉下去那只蚂蚁的名字,这样看起来似乎要考虑每个蚂蚁相撞的情况,若记录获得最大值的蚂蚁为A,若A和B碰撞,之后B又和C碰撞,之后C又和D.... 的最后一个人,这样最后一个相撞的人的名字即为所求,但是这样就不好处理 
如果把相撞视为擦肩而过,让蚂蚁们按原方向一直走,每只蚂蚁走pos+maxn或者pos-maxn后,此时对这些距离从小到大排序,找到位置为0或者L的点,记起下标为temp,由于蚂蚁的相对位置保持不变,则ant[pos].name即为所求.
注意最后是要截取两位小数,不是四舍五入,所以要用floor(maxn/V*100)/100.0(因为这个wa了几次)
/*
* Created: 2016年04月06日 10时29分37秒 星期三
* Author: Akrusher
*
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define in(n) scanf("%d",&(n))
#define in2(x1,x2) scanf("%d%d",&(x1),&(x2))
#define in3(x1,x2,x3) scanf("%d%d%d",&(x1),&(x2),&(x3))
#define inll(n) scanf("%I64d",&(n))
#define inll2(x1,x2) scanf("%I64d%I64d",&(x1),&(x2))
#define inlld(n) scanf("%lld",&(n))
#define inlld2(x1,x2) scanf("%lld%lld",&(x1),&(x2))
#define inf(n) scanf("%f",&(n))
#define inf2(x1,x2) scanf("%f%f",&(x1),&(x2))
#define inlf(n) scanf("%lf",&(n))
#define inlf2(x1,x2) scanf("%lf%lf",&(x1),&(x2))
#define inc(str) scanf("%c",&(str))
#define ins(str) scanf("%s",(str))
#define out(x) printf("%d\n",(x))
#define out2(x1,x2) printf("%d %d\n",(x1),(x2))
#define outf(x) printf("%f\n",(x))
#define outlf(x) printf("%lf\n",(x))
#define outlf2(x1,x2) printf("%lf %lf\n",(x1),(x2));
#define outll(x) printf("%I64d\n",(x))
#define outlld(x) printf("%lld\n",(x))
#define outc(str) printf("%c\n",(str))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define mem(X,Y) memset(X,Y,sizeof(X));
typedef vector<int> vec;
typedef long long ll;
typedef pair<int,int> P;
const int dx[]={,,-,},dy[]={,,,-};
const int INF=0x3f3f3f3f;
const ll mod=1e9+;
ll powmod(ll a,ll b) {ll res=;a%=mod;for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
const bool AC=true; struct node{
char dir[]; //方向
double pos;//位置
char name[];
};
node ant[];
double p[];
int n;
double L,V;
bool cmp(node x,node y){
return x.pos<y.pos;
}
void solve(){
double maxn,dis;
maxn=;
rep(i,,n){
dis=(ant[i].dir[]=='P'||ant[i].dir[]=='p')?L:;
maxn=max(maxn,abs(dis-ant[i].pos));
}
rep(i,,n){
dis=(ant[i].dir[]=='P'||ant[i].dir[]=='p')?maxn:-maxn;
p[i]=dis+ant[i].pos;
}
sort(p,p+n);
int temp;
rep(i,,n){
if(p[i]==||p[i]==L){
temp=i;break;
}
}
printf("%13.2f %s\n",floor(maxn/V*)/100.0,ant[temp].name);
}
int main()
{
while(in(n)&&n){
inlf2(L,V);
rep(i,,n){
scanf("%s %lf %s",&ant[i].dir,&ant[i].pos,&ant[i].name);
}
solve();
}
return ;
}
POJ 2674 Linear world的更多相关文章
- 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 Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 2448 Accepted: 564 Descr ... 
- poj 2674 线性世界 弹性碰撞
		弹性碰撞的题目一般都是指碰到就会掉转方向的一类题目,这里我们可以忽略掉头,仅仅看成擦肩而过,交换名字等等 题意:一条线上N只蚂蚁,每只蚂蚁速度固定,方向和坐标不同,碰头后掉头,求最后掉下去那只蚂蚁的名 ... 
- ProgrammingContestChallengeBook
		POJ 1852 Ants POJ 2386 Lake Counting POJ 1979 Red and Black AOJ 0118 Property Distribution AOJ 0333 ... 
- [POJ 2420] A Star not a Tree?
		A Star not a Tree? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4058 Accepted: 200 ... 
- 萌新笔记——Cardinality Estimation算法学习(二)(Linear Counting算法、最大似然估计(MLE))
		在上篇,我了解了基数的基本概念,现在进入Linear Counting算法的学习. 理解颇浅,还请大神指点! http://blog.codinglabs.org/articles/algorithm ... 
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
		Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ... 
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
		Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ... 
随机推荐
- Unity 通过Animation实现控件位置的转换
			Unity版本:4.5.1 NGUI版本:3.6.5 参考链接:http://blog.csdn.net/unity3d_xyz/article/details/23035521,作者:CSDN in ... 
- JavaScript框架设计 第14章 动画引擎
			easing-js <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ... 
- C#代码实现隐藏任务栏、开始菜单和禁用任务管理
			一:截图,主要是调用系统接口和更改注册表实现功能 二:代码 using System; using System.Collections.Generic; using System.Linq; usi ... 
- HDOJ(HDU) 2107 Founding of HDU(找最大值)
			Problem Description 经过慎重的考虑,XHD,8600, LL,Linle以及RPG等ACM队员集体退役,甚至正在酝酿退学. 为什么?要考研?那也不用退学呀- 当然不是!真正的原因是 ... 
- HttpContext.Current.Cache 和 HttpRuntime.Cache 区别
			原文地址:http://blog.csdn.net/avon520/article/details/4872704 .NET中Cache有两种调用方式:HttpContext.Current.Cach ... 
- How To Create a New User and Grant Permissions in MySQL
			How to Create a New User Let’s start by making a new user within the MySQL shell: CREATE USER 'newus ... 
- angularjs简单实现$http.post(CORS)跨域及$http.post传参方式模拟jQuery.post
			1.开启angularjs的CORS支持 .config(function($httpProvider) { // CORS post跨域配置 $httpProvider.defaults.useXD ... 
- Unity3D NGUI制作进度条
			利用GUI可以制作进度条,但是NGUI更加方便 我是用的NGUI3.5.3, 先找到NGUI Slider的预制体,利用自带的UISlider来制作. 主要是利用UISlider的Value来控制进 ... 
- Json序列化、反序列化互换
			// 序列化 using (MemoryStream stream = new MemoryStream()) { serializer.WriteObject(stream, hdm); jsonT ... 
- 互联网TCP/IP五层模型(一)
			转载自:阮一峰 我们每天使用互联网.你是否想过,它是怎样实现的? 全世界几十亿台电脑,连接在一起,两两通信. 上海的某一块网卡送出信号,洛杉矶的还有一块网卡竟然就收到了.两者实际上根本不知道对方的物理 ... 
