POJ 2632【Crashing Robots】

【漆学军】MT4进阶到MT5速成之路(2)获取持仓 MT5在持仓获取上,要比MT4复杂些,分两部分,获取持仓和挂单采用了不同的方法。 一、获取持仓中的buy和sell单 int b=0;//获取buy单个数 int s=0;//获取sell单个数 double lot_total_buy=0;//获取持仓中buy单的总手数 double lot_total_sell=0;//获取持仓中sell单的总手数 for(int i=0; i<PositionsTotal(); i++) { ulong ticket=Positi 阅读详情

题目链接

思路:

  • 简单模拟。
  • 把方向换成数字,如下处理转向问题:
​int ans;
switch(ins)
{
	case 'L' :
		ans = (rob[t].dir + n%4) % 4 ;
		rob[t].dir = ans ? ans : 4 ;break;
	case 'R' :
		ans = (rob[t].dir + 4 - n%4) % 4;
		rob[t].dir = ans ? ans : 4 ;break;
	case 'F' :
		MoveForward(t,n);break;
}
​

完整代码:

  • 664K 0MS
​//664K		0MS


#include <iostream>
#include <cstring>

using namespace std;

const int maxn = 105;

bool mp[maxn][maxn];
bool ok;
int l,r;
int M,N;
int numr,numi;
struct ROBOT{
	int x;
	int y;
	int dir;
}rob[maxn];

void init(){
	l = r = 0;
	ok = true;
	memset(mp,0,sizeof(mp));
	return ;
}

bool check(int i){
	int x = rob[i].x;
	int y = rob[i].y;
	if(x<1 || y<1 || x>M || y>N){
		l = i; //crash into wall
		return ok = false;
	}
	return true;
}

void MoveForward(int i,int n){
	mp[rob[i].x][rob[i].y] = false;
	while(n--){
		switch(rob[i].dir)
		{
			case 1 : rob[i].x++ ;break;
			case 2 : rob[i].y++ ;break;
			case 3 : rob[i].x-- ;break;
			case 4 : rob[i].y-- ;break;
		}
		//如果没有 check,一旦越出 maxn 使用 mp 很容易 RE 
		if(check(i)) 
			if(mp[rob[i].x][rob[i].y]){
				l = i;
				for(int t=1;t<=numr;t++){
					if(t == i)
						continue;
					if(rob[t].x == rob[i].x && rob[t].y == rob[i].y){
						r = t;
						break;
					}
				}
				ok = false;
				break;
			}
			else
				;
		else
			break;
	}
	if(ok)
		mp[rob[i].x][rob[i].y] = true;
	return ;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int T;cin>>T;
	while(T--){
		init();
		cin>>M>>N;
		cin>>numr>>numi;
		for(int i=1;i<=numr;i++){
			char dir;
			cin>>rob[i].x>>rob[i].y>>dir ;
			mp[rob[i].x][rob[i].y] = true;
			switch(dir)
			{
				case 'E' : rob[i].dir = 1;break;
				case 'N' : rob[i].dir = 2;break;
				case 'W' : rob[i].dir = 3;break;
				case 'S' : rob[i].dir = 4;break;
			}
		}
		for(int i=1;i<=numi;i++){
			int t;//serial number
			char ins;//instruction
			int n;//repeat
			cin>>t>>ins>>n;
			int ans;
			if(ok)
				switch(ins)
				{
					case 'L' :
						ans = (rob[t].dir + n%4) % 4 ;
						rob[t].dir = ans ? ans : 4 ;break;
						//
					case 'R' :
						ans = (rob[t].dir + 4 - n%4) % 4;
						rob[t].dir = ans ? ans : 4 ;break;
					case 'F' :
						MoveForward(t,n);break;
				}
			else ;
		}
		if(ok)
			cout<<"OK"<<endl;
		else
			if(r)
				cout<<"Robot "<<l<<" crashes into robot "<<r<<endl;
			else
				cout<<"Robot "<<l<<" crashes into the wall"<<endl ;
	}
	return 0;
}​
VS2019 +osg3.6.5+ earth3.2+qt5.14.2+osgQt 编译教程 用vs新建工程,稍后会在写一篇博客上分享四、结语至此,所有的编译就均已完成。 阅读详情

相关推荐

一文读懂客户健康度

什么是客户健康度?客户健康度为什么重要?怎么计算客户健康度?这篇文章,我们来聊聊。

m0_62700043的博客 1425

POJ 刷题系列:2632. Crashing Robots

POJ 刷题系列:2632. Crashing Robots传送门:2632. Crashing Robots题意: 在一张地图(A x B)中给出N个robot的位置和初始移动方向,以及M条指令,任意两个robot不能同时移动,问是否存在非法的crash状态(撞墙,撞其他robot)。 思路: 思路比较简单的模拟题,新建一个grid地图信息,每个位置初始化为0,有机器人的位置则初始化

Demon-初来驾到 415

TMS320F280049C 学习笔记21 交叉开关 Crossbar (X-BAR)

简单介绍了X-BAR。

whyorwhnt的专栏 2万+

poj 2632 Crashing Robots

恶心的模拟题,敲错了字符,错了…… /* * Author: stormdpzh * POJ: 2632 Crashing Robots * Time: 2012/5/12 12:02:49 */ #include #include #include #include #include #include #include #include #include #inclu

stormdpzh的专栏 449

TCN(Temporal Convolutional Networks)时序卷积网络详解及代码

TCN(Temporal Convolutional Networks)时序卷积网络详解及代码

zhulewen的博客 7886

UVM环境复位--stop_sequences()

在UVM验证环境中, stop_sequences是一个用于强制终止所有正在运行的 Sequence 的方法,通常用于动态控制激励生成流程。1.通过uvm_config_db传递事件和严格的同步机制,此方案符适用于复杂复位场景和动态测试控制。组件耦合:Driver 和 Sequence 不再直接依赖env,通过标准接口通信。竞争条件:确保 Driver 完成清理后再终止 Sequence。代码健壮性:使用非阻塞操作和事件监听,避免死锁。

qq_42779035的博客 3021

【POJ2632】Crashing Robots

题目传送门 本题知识点:模拟 模拟机器人的运作过程,分别有三种功能,L 则是左转90°,R 则是右转90°,L 则是前进1格。让我们去模拟并判断它们的状态。 输入: 第一行是测试样例 第二行分别是矩形的长、宽(比如,5 4) // 题目是讲得很清楚的 // 4 // 3 // 2 // 1 // 1 2 3 4 5 第三行分别是机器人的个数以及指令条数 接下来是先输入每个机器人的初...

LT4585的博客 340

SolidWorks2020详细步骤安装教程

1、在安装软件前请断开网络连接,需要安装.NETFramework3.5和4.0,最后还要确保把之前安装的旧版本完全卸载,以管理员身份运行SolidWorks_Flexnet_Server\server_remove.bat,然后等到服务“SolidWorksFlexnet服务器”将被删除。12、先不要运行软件,找到_SolidSQUAD_文件夹,将文件夹“ProgramFiles\SOLIDWORKSCorp”中的所有破解文件复制替到“ProgramFiles\SOLIDWORKSCorp”目录下;

qq_53545309的博客 1万+

poj2632Crashing Robots

http://poj.org/problem?id=2632 模拟算法:将整个过程完完整整的走一遍。题目怎么叙述的,程序就怎么运行。所以模拟题对算法设计的要求不高,但是需要大家选择最适当的数据结构来进行模拟,模拟题一般都很繁琐,所以信心和精心是必不可少的。 本题注意点挺多的,变量也很多,稍不注意就会错~~也算是一道比较让人头疼的模拟题了。 #include #include int ar

ViolentLittleAngel的博客 620

计算分子相似度(摩根分子指纹计算)

import numpy as np import pandas as pd import seaborn as sns import matplotlib as plt from rdkit.Chem import Draw from rdkit.Chem import AllChem as Chem from rdkit.Chem import PandasTools from rdkit import DataStructs data = pd.read_csv(r'47_covidLead.csv'

weixin_39417324的博客 1390

项目篇 | 图书管理系统 | 管理员模块 | 概述

图书管理系统管理员模块概述

百栗.的博客 408

POJ2632 Crashing Robots

Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8576   Accepted: 3703 Description In a modernized warehouse, robots are used to fetch the goo

乱齐八糟 388

使用Qt编译Qt WebEngine

这就是使用Qt编译Qt WebEngine模块的基本步骤。通过按照上述步骤,您应该能够成功编译和使用Qt WebEngine来嵌入Web内容到您的Qt应用程序中。Qt WebEngine是Qt框架的一个模块,它提供了一个现代的Web浏览器引擎,可以在Qt应用程序中嵌入Web内容。首先,需要获取Qt的源代码。如果尚未安装,可以从Qt官方网站下载并安装Qt。完成Qt的安装后,您可以构建并运行Qt WebEngine示例来验证编译是否成功。这将把编译好的Qt库文件和头文件安装到之前指定的安装目录中。

DevForge的博客 3023

POJ 2632.Crashing Robots

题目:http://poj.org/problem?id=2632 AC代码(C++): #include #include #include #include #include #include #include #include #include using namespace std; int main(void) { int n;

njyexiong的博客 275

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

Crashing Robots POJ2632

Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4556   Accepted: 1991 Description

天堂人间 3120

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

poj2632 Crashing Robots 模拟

Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10341   Accepted: 4380 Description In a modernized warehouse, robots are used to fetch the go

kyoma的博客 429

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

POJ 2632-Crashing Robots

POJ 2632-Crashing Robots

Yuric的专栏 379

POJ 2632 Crashing Robots

Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7374   Accepted: 3232 Description In a modernized warehouse, robots are used to fetch the goo

u013082590的专栏 812

poj2632 Crashing Robots

第一次WA了,因为还没给题目的数据输入完就输出答案了,没输进去的数据自然会不高兴 ̄へ ̄ 第二次runtime error,因为数组越界,醉了(ಥ _ ಥ) 学到了新的输入输出数据的方法(解放手指头!): 在main开头的地方添加以下两行 freopen("D:\input.txt","r",stdin); freopen("D:\output.txt","w",stdout);输出的数据在

franklin_lei的博客 308

Crashing Robots POJ 2632

Description In a modernized warehouse, robots are used to fetch the goods. Careful planning is needed to ensure that the robots reach their destinations without crashing into each other. Of cours

luckyrass的专栏 518

POJ 2632, Crashing Robots

模拟类 DescriptionIn a modernized warehouse, robots are used to fetch the goods. Careful planning is needed to ensure that the robots reach their destinations without crashing into each other. Of cour...

weixin_33788244的博客 180

POJ2632-Crashing Robots

全解题报告索引目录 -> 【北大ACM – POJ试题分类】 转载请注明出处:http://exp-blog.com ------------------------------------------------------------------------- 提示:简单的模拟而已。。。程序很长不是因为算法(根本就没算法= =)而是因为很多情况要考虑,要有耐心 需要小...

ζёСяêτ - 小優YoU 5010

(模拟)poj2632 Crashing Robots

题目:http://poj.org/problem?id=2632 大模拟题,值得敲敲,虽然很痛苦,需要注意的是模拟要一步一步进行,否则就WA得多少次啊。。。 下面是AC代码,很长,凑合看吧,以后会精简。。。 #include int main() { int _k,num,order,x,y,x_cur[110],y_cur[110]; int robot[110],repeat

那些你很冒险的梦 848
上一篇: POJ 1068【Parencodings】
下一篇: POJ 1573【Robot Motion】
Masker_43
博客等级 码龄8年 5粉丝 143原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值