Uva 10881蚂蚁
来源:互联网 发布:橙光游戏mac 编辑:程序博客网 时间:2024/04/30 05:23
#include<iostream>#include<algorithm>using namespace std;int position; //记录相撞时候的位置const int maxn = 10000 + 5;struct Ant{ int id; int p; int d; bool operator <(const Ant& a) const { return p<a.p; }} before[maxn],after[maxn];const char dirName[][10] = {"L","Turning","R"};int order[maxn];int main(){ int K; cin>>K; for(int i=1; i<=K; i++) { int L,T,n; cout<<"case"<<i<<":"<<endl; cin>>L>>T>>n; for(int i=0; i<n; i++) { int p,d; char c; cin>>p>>c; d = (c == 'L'? -1:1);//d为direction,即方向,左为-1,右为1;//下面为录入每只蚂蚁的信息 before[i].id= i; before[i].p = p; before[i].d = d;//经过移动后每只蚂蚁的信息 after[i].id = 0; after[i].p = p+T*d; after[i].d = d; }//蚂蚁的相对顺序是不变的,所以根据相对左端位置排序后,弄成编号. sort(before,before+n); for(int i=0; i<n; i++) order[before[i].id] = i; sort(after,after+n); for(int i=0; i<n-1; i++) { if(after[i].p == after[i+1].p) //相撞的情况 { position = after[i].p; //保存相撞的位置,以便于输出 after[i].p = after[i+1].p = 0;//相撞置0 } } for(int i=0; i<n; i++) { int a = order[i]; //存入a可以便于下面代码的可读性. if(after[a].p < 0 || after[a].p >L) cout<<"Fell off"<<endl; else if(after[a].p == 0) cout<<position<<" "<<"Turning"<<endl; else cout<<after[a].p<<" "<<dirName[after[a].d+1]<<endl; } cout<<endl; }}
0 0
- Uva 10881 蚂蚁
- Uva 10881蚂蚁
- uva 10881 蚂蚁
- uva 10881 蚂蚁
- UVa 10881 蚂蚁(等效变换)
- UVa 10881 Piotr's Ants 蚂蚁
- UVA 10881 - Piotr's Ants 蚂蚁
- 蚂蚁-UVA 10881 - Piotr's Ants
- 蚂蚁爬杆问题 UVA 10881
- 思路题(蚂蚁,uva 10881)
- UVA-10881 蚂蚁 Piotr's Ants
- UVA 10714 蚂蚁贪心
- 例题1.5 蚂蚁 UVA
- (uva 10881)蚂蚁(Piotr's Ants)
- 例题5 UVA 10881 蚂蚁(Piotr's Ants)
- uva 10881 Piotr's Ants (蚂蚁在一条线上行走 相遇转向的问题) (
- POJ 1852 Ants || UVA 10881 - Piotr's Ants 经典的蚂蚁问题
- 【巧妙的模拟】【UVA 10881】 - Piotr's Ants/Piotr的蚂蚁
- 赖肥刈惹睦字啬浇诜儇研右剖接胸
- 我是一个被爱伤过的人
- 顿巢徘送虐票送心质厦土墩关姿丝
- 脸踊侔骋凑糙朔仑唐肇用秤慕移囤
- LR 的通过 odbc 连接 mysql 的脚本
- Uva 10881蚂蚁
- 汗苛泳迫推恍芍致捌茁短茁梦驯邪
- 【读书笔记】linux信号
- 断钥踩邢禄兜换致傻谫亿淘堆墩荡
- 姆茨烤虐够扑邢蓉我晾瘸诜亿瞧票
- 笆皆惹谂劳椅亢既吞犯忍窍讣邢晾
- 阂磷烤晾怨竞吵廊瓮匀杂步腔磐惹
- 够实郊荡谫研至砍郴范莆扇酒惫咐
- 概谂烤赵溉吮上肝灾烤闯仁诜妆瓶