UVA10881:
来源:互联网 发布:屏蔽软件弹出广告 编辑:程序博客网 时间:2024/06/06 09:04
题目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1822
题意:给出每个蚂蚁的初始状态,求时间T之后每只蚂蚁的状态
解法:如果忽略编号的话,可以把每只蚂蚁的掉头看成对穿而过,而最终的状态下,最左边的绝对是1号蚂蚁了
#include <stdio.h>#include <algorithm>using namespace std;const int maxn = 10005;struct NODE{ int no; int s; int t;//朝向,-1为左,0中,1右}start[maxn],end[maxn];int cmp(NODE x,NODE y){ return x.s < y.s;}char turn[][10] = {"L","Turning","R"};int order[maxn];int main(){ int t,cas = 1; scanf("%d",&t); while(t--) { int L,T,N,i; scanf("%d%d%d",&L,&T,&N); for(i = 0;i<N;i++) { char c; start[i].no = i; scanf("%d %c",&start[i].s,&c); start[i].t = (c == 'L'?-1:1); end[i].no = 0; end[i].s = start[i].s + T*start[i].t; end[i].t = start[i].t; } sort(start,start+N,cmp); for(i = 0;i<N;i++) order[start[i].no] = i; sort(end,end+N,cmp); for(i = 0;i<N-1;i++) { if(end[i].s == end[i+1].s) end[i].t = end[i+1].t = 0; } printf("Case #%d:\n",cas++); for(i = 0;i<N;i++) { int a = order[i]; if(end[a].s < 0 || end[a].s>L) printf("Fell off\n"); else printf("%d %s\n",end[a].s,turn[end[a].t+1]); } printf("\n"); } return 0;}
- UVA10881:
- uva10881
- UVa10881
- uva10881
- Uva10881
- UVa10881
- uva10881
- UVa10881
- UVA10881
- uva10881-虫虫爬杆
- UVA10881蚂蚁
- uva10881 ants
- UVA10881蚂蚁
- UVA10881 Piotr's Ants
- UVA10881 Piotr's Ants
- 蚂蚁爬杆+uva10881
- Uva10881 Piotr's Ants
- uva10881 Piotr's Ants
- IBatis SqlMap解析及加载
- 分词常见算法-----小整理
- 12250 - Language Detection
- progress--状态交互元素
- fms系列之一 连接服务器
- UVA10881:
- 开源中国iOS客户端学习——(十三)使用UIWebView控件布局视图
- PeekMessage & GetMessage 区别
- UVA 10591 - Happy Number
- [WIKIOI1281] Xn数列
- 关于Cross-Dll问题(在不同的模块之间申请和释放内存)
- Copy .vdi file by changing UUID in VirtualBox
- hdu 2066 一个人的旅行
- C#事件与代理的简单运用