UVa10881
来源:互联网 发布:贝恩杯 知乎 编辑:程序博客网 时间:2024/06/05 20:07
/*
解题的关键在于两点:
1.理解相撞就是擦肩而过,但是两者头上的记号会交换。
2.关键是确定相对顺序,并且正确编号,而蚂蚁的相对顺序是不变的。
因此首先使用id数组记录蚂蚁的相对顺序,即按照蚂蚁的初始位置为蚂蚁编号排序
之后计算最终蚂蚁的位置,然后改变蚂蚁的状态
最后根据相对顺序确定蚂蚁编号。
*/
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<vector>
#include<utility>
using namespace std;
struct ele{
int id;
int pos;
char dir;
bool operator <(const ele& a)const{
return id<a.id;
}
};
const int nmax=10000+5;
ele ant[nmax];
int kase,n,L,T;
int main()
{
//auto fin=fopen("UVa.in","r");
auto cmp_id=[](pair<int,int>&a,pair<int,int>&b){return a.second<b.second;};
auto cmp_pos=[](ele &a,ele&b){return a.pos<b.pos;};
//fscanf(fin,"%d",&kase);
scanf("%d",&kase);
for(int num=1;num<=kase;++num){
printf("Case #%d:\n",num);
//fscanf(fin,"%d %d %d",&L,&T,&n);
scanf("%d %d %d",&L,&T,&n);
vector<pair<int,int>>id(n);
for(int i=0;i<n;++i){
id[i].first=i+1;
//fscanf(fin,"%d %c",&(id[i].second),&(ant[i].dir));
scanf("%d %c",&(id[i].second),&(ant[i].dir));
ant[i].pos=id[i].second;
}
sort(id.begin(),id.end(),cmp_id);
for(int i=0;i<n;++i)ant[i].pos+=ant[i].dir=='R'?T:-T;
sort(ant,ant+n,cmp_pos);
for(int i=0;i<n;++i)ant[i].id=id[i].first;
for(int i=0;i<n;++i){
if(ant[i].pos<0||ant[i].pos>L)ant[i].dir='F';
else if(i+1<n&&ant[i].pos==ant[i+1].pos){
ant[i].dir=ant[i+1].dir='T';
++i;
}
}
sort(ant,ant+n);
for(int i=0;i<n;++i){
if(ant[i].dir=='F')printf("Fell off\n");
else if(ant[i].dir=='T')printf("%d Turning\n",ant[i].pos);
else printf("%d %c\n",ant[i].pos,ant[i].dir);
}
printf("\n");
}
return 0;
}
阅读全文
0 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
- Android textview自适应宽度自动调整字体大小
- 对象转化为json串的出现循环引用$ref $.s1解决办法
- “-bash: /usr/local/bin/npm: No such file or directory” centos7 nodejs yum安装包损坏的修复
- 从 LeetCode 279 实践动态规划
- 个人FTP(FileZilla_Server) 使用
- UVa10881
- 浅谈m1卡
- leetcode182. Duplicate Emails
- 贫穷的VIM作者Bram Moolenaar
- win7 IIS7.5配置伪静态
- ip正则表达式验证
- 什么是Code Review
- idea 基于maven 的ssm 整合实现登录功能(第一篇)
- 基于百度地图Web API的物联设备调试工具(一)