蚂蚁爬杆+uva10881
来源:互联网 发布:温湿度软件 编辑:程序博客网 时间:2024/06/11 00:37
这题有两点可以简化:
1.两个蚂蚁相撞是,掉头走了就相当于后想穿过走接着走。
2.所有的蚂蚁相对顺序是不变的,因为碰头后掉头走。
下面是代码:
#include<iostream>#include<algorithm>#include<cstring>#include<cstdio>using namespace std;const int MAX=10010;class node{ public: int id,p,d; node(){} node(int id,int p,int d)//:id(i),p(ip),d(iid) { this->id=id; this->p=p; this->d=d; } bool operator <(const node &a) const { return p<a.p; }};node before[MAX],after[MAX];int order[MAX];const char dirName[][10]={"L","Turning","R"};int main(){ #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif int k; scanf("%d",&k); for(int cas=1;cas<=k;cas++) { int L,T,n; scanf("%d%d%d",&L,&T,&n); for(int i=0;i<n;i++) { int p,d; char c; scanf("%d %c",&p,&c); d=(c=='L'?-1:1); before[i]=node(i,p,d); after[i]=node(0,p+T*d,d); } sort(before,before+n); for(int i=0;i<n;i++) order[before[i].id]=i; sort(after,after+n); printf("Case #%d:\n",cas); for(int i=0;i<n-1;i++) if(after[i].p==after[i+1].p) after[i].d=after[i+1].d=0; for(int i=0;i<n;i++) { int t=order[i]; if(after[t].p<0||after[t].p>L) printf("Fell off\n"); else printf("%d %s\n",after[t].p,dirName[after[t].d+1]); } puts(""); } return 0;}
0 0
- 蚂蚁爬杆+uva10881
- UVA10881蚂蚁
- UVA10881蚂蚁
- uva10881(蚂蚁模拟)
- 例题1.5 蚂蚁 UVa10881
- Uva10881 - Piotr's Ants(蚂蚁)
- UVA10881:
- uva10881
- UVa10881
- uva10881
- Uva10881
- UVa10881
- uva10881
- UVa10881
- UVA10881
- 蚂蚁爬杆问题
- 蚂蚁爬杆
- 蚂蚁爬杆
- 【Java】实现按中文首字母排序
- ArcGis10安装步骤
- Delphi 实现文件从Oralce数据库 Blob 字段的读写
- 使用Git和远程代码库
- FindWindow用法举例
- 蚂蚁爬杆+uva10881
- 采样点数与采样频率的区别
- think in java interview-高级开发人员面试宝典(一)
- jQuery EasyUI parser
- iOS中XML解析 (二) libxml2(实例:打印xml内容及存储到数组)
- Response.Redirect导致session丢失的解决办法
- 取消选中单选框radio的三种方式
- oracle 数据库实例优化
- think in java interview-高级开发人员面试宝典(二)