博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVA-10881 Piotr's Ants
阅读量:7222 次
发布时间:2019-06-29

本文共 1529 字,大约阅读时间需要 5 分钟。

     

这道题以前在那见过,但是当时没做出来,今天有看到这道题感觉真的听巧妙的,嘿嘿嘿,如果不看是哪只蚂蚁,忽略碰撞之后转身这个条件,其实在这两种情况下最后蚂蚁的位置都是相同的,而要解决的问题就是确定在哪一个位置上究竟是哪只蚂蚁,每只蚂蚁的相对顺序是不变的(因为相撞之后转身,不能穿过),所以顺序的问题就解决了,啊,ACM真的是有趣!!!

 

#include
#include
#include
#include
using namespace std;const int N = 10000 + 5;struct ant{ int id, p, d; bool operator < (const ant & x) const { return p < x.p; }}before[N],after[N];int L, n, t, order[N];const char* dir[3] = {
"L", "Turning", "R"}; //这也不得不说很巧妙!void Solve_question(){ static int Case = 0; 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) after[i].d = after[i + 1].d = 0; printf("Case #%d:\n",++Case); for(int i = 0; i < n; i++){ int a = order[i]; if(after[a].p < 0 || after[a].p > L) printf("Fell off\n"); else printf("%d %s\n", after[a].p, dir[after[a].d+1]); } printf("\n");}void Input_data(){ int p, d; char c; scanf("%d %d %d", &L, &t, &n); for(int i = 0; i < n; i++){ scanf("%d %c", &p, &c); d = (c == 'L'? -1 : 1); // -1表示向左运动, 0表示正在转身, 1表示向右运动 before[i] = (ant){i, p, d}; after[i] = (ant){
0, p + t * d, d}; }}int main(){ int T; scanf("%d", &T); while(T--){ Input_data(); Solve_question(); }}

 

 

转载于:https://www.cnblogs.com/Pretty9/p/7384035.html

你可能感兴趣的文章
忙里偷闲( ˇˍˇ )闲里偷学【C语言篇】——(9)链表
查看>>
struts2 type="redirectAction"重定向 与动态调用方法
查看>>
实时搜索的优化
查看>>
Oracle 好书 07 ( undo 表空间管理 )
查看>>
使用MapReduce实现温度排序
查看>>
技术网站
查看>>
HDU计算机学院大学生程序设计竞赛(2015’12)1008 Study Words
查看>>
python面试
查看>>
oracle中去掉回车换行空格的方法详解
查看>>
eval(gzinflate(base64_decode N层,自动解密
查看>>
Apache CXF 2.7.0 的 wsdl2java 生成客户端java类中required 未定义的问题
查看>>
中国大学排名定向爬虫
查看>>
657. Insert Delete GetRandom O(1)
查看>>
Java编程资料
查看>>
duilib 设计界面 初体验(附超链接开发)
查看>>
jvm内存区域
查看>>
IOS--常用控件--UIScrollView
查看>>
能够使开发和调试更为方便的java日志框架
查看>>
冷门Javascript API——element.insertAdjacentHTML
查看>>
绘制希尔伯特曲线
查看>>