ZOJ 4092 Robot Cleaner I (模拟判重)

ZOJ题目分类(源自网络) 阅读详情

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4092

题意

给出n × m的方格,给出一串指令,机器人初始在一个位置,机器人会根据方格四周(包括自身)的值得出要执行的指令,问执行k次之后,机器人捡到了多少垃圾。

题解

k特别大,所以不能直接暴力模拟,考虑什么时候机器人会进入死循环。
因为机器人会根据四周的值计算该执行什么指令,而只有捡了垃圾才会改变方格的值,所以如果到当前点机器人捡的垃圾的个数和之前是一样的,那么就进入了死循环。(说明绕了一圈已经没有垃圾可捡了[方格的值没有改变],那只会一直对着这个绕圈)

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e3+1;
int t,n,m;
long long k;
char s[300];
char mat[maxn][maxn]; 
int vis[maxn*10];
int f_pow(int a,int b){
	int res = 1;
	while(b){
		if(b & 1) res *= a;
		a *= a;
		b >>= 1;
	}
	return res;
}
int solve(int x,int y){
	int ans = 0;
	ans += f_pow(3,4)*(mat[x][y] - '0');
	ans += f_pow(3,3)*(mat[x-1][y] - '0');
	ans += f_pow(3,2)*(mat[x+1][y] - '0');
	ans += f_pow(3,1)*(mat[x][y-1] - '0');
	ans += mat[x][y+1] - '0';
	return ans;
}
int f(char c){
	if(c == 'U') return 0;
	if(c == 'D') return 1;
	if(c == 'L') return 2;
	if(c == 'R') return 3;
	if(c == 'I') return 4;
	if(c == 'P') return 5;
	return 0;
}
int ff(int x,int y) {
	return (x-1)*m+y;
}
bool mov(char c,int &ans,int &x,int &y, int& pre){
	int tx = x,ty = y;
	if(vis[ff(x,y)] == pre) return false;
	vis[ff(x,y)] = pre;
	if(c == 'U'){
		if(mat[x-1][y] != '1' && x > 1 && mat[x-1][y] != '1')
			x--;
	}
	if(c == 'D'){
		if(mat[x+1][y]!='1' && x < n && mat[x+1][y] != '1')
			x++;
	}
	if(c == 'R'){
		if(mat[x][y+1] != '1' && y < m && mat[x][y+1] != '1')
			y++;
	}
	if(c == 'L'){
		if(mat[x][y-1]!='1' && y > 1 && mat[x][y-1] != '1')
			y--;
	}
	if(c == 'P'){
		if(mat[x][y] == '2'){
			mat[x][y] = '0';
			ans++;
			pre = ff(x,y);
		}
	}
	return true;
}
int main(){
	cin >> t;
	int x,y;
	while(t--){
		memset(vis,0,sizeof(vis));
		scanf("%d%d",&n,&m);
		scanf("%d%d%lld",&x,&y,&k);
		scanf("%s",s);
		int pre = -2;
		for(int i = 1; i <= n; i++)
				scanf("%s",mat[i] + 1);
		int ans = 0;
		while(k--){
			int p = solve(x,y);
			char c = s[p];
			if(!mov(c,ans,x,y,pre))
				break;
		}
		printf("%d\n",ans);
	}
	return 0;
}
ZOJ:浙江大学程序在线评测系统.docx ZOJ,全称“浙江大学程序在线评测系统”(Zhejiang University Online Judge),是一个提供信息学(算法竞赛)题库及程序评测的网站。以下是关于ZOJ的详细介绍: 一、基本信息 名称:浙江大学程序在线评测系统(ZOJ) 外文名:Zhejiang University Online Judge 始建时间:2002年 平台:构建于Linux平台 语言兼容性:兼容Pascal、C、C++等多种语言 二、系统特点 公益性:ZOJ是一个免费的公益性网上程序设计题库,是国内创办最早的程序在线评测系统之一。 题目来源:题目大部分来自ACM国际大学生程序设计竞赛,以及全球各赛区或著名大学的竞赛试题,总数超过3000道,且均为全英文题目。 竞赛支持:每年5月份左右的浙江省大学生程序设计竞赛在该系统上进行,ZOJ还每月举行月赛,吸引全球程序爱好者参与。 三、功能与服务 实时排名与公布:比赛结果实时排名,在线公布,确保比赛的公平公正。 自动评测:用户可以针对某个题目编写程序并提交,ZOJ会自动判定程序的对错,并在几秒内给出反馈。 教学支持:每个学生可以在ZOJ上建立自己的账号,教 立即下载

相关推荐

zoj 源码700题

包含了zoj700多道题目的源代码,在做题时可以参考

UVALive 3983 (单调队列优化dp)

题意:有一个机器人要捡n个垃圾到垃圾桶(0, 0)里,给出了机器人最多可以捡多重的垃圾c,然后给出了n个垃圾的位置和重量,机器人只能按给出的顺序捡垃圾,然后一起扔到垃圾桶里,问把所有垃圾清理完机器人行走的最短距离。 分析:《训练指南》P73。 代码: #include<bits/stdc++.h> using namespace std; const int maxn = 1...

常胜将军的博客 231

浙江大学ZOJ题目分类

浙大ZOJ题目分类,可以让你更方便快速锁定那你想要联系的题目,是自己快速提高·

存档/Lev OJ P1490 机器人捡垃圾

动态规划

m0_63916671的博客 803

小程序捡垃圾机器人

捡垃圾的机器人程序,机器人部分,欢迎下载

保姆级教程:在通达信V7.611上配置欧奈尔RPS曲线(附完整公式与每日更新流程)

本文提供通达信V7.611配置欧奈尔RPS曲线的保姆级教程,涵盖从环境准备、基础设置到核心公式配置的全流程。详细讲解如何创建股票池、编写EXTRS基础公式及RPS显示公式,并附每日更新流程与实战应用技巧,帮助投资者精准捕捉强势股。

weixin_30000735的博客 460

ZOJ贪心算法_题目

ZOJ贪心算法_题目(转) #1117 经典贪心,哈夫曼编码。 #1184 硬币称重,经典,1.若被判平,左右所有球必正常;2.若判轻或判重,对应球被判轻、重记数+1;3.只有球只被判轻或判重,且次数跟天平不平衡次数相等,该球才能是坏的,否则必然是好的。 #1409 求最佳带宽价格比,其中带宽为所有组件的带宽最小值,价格为各个组件价格总和,用贪心即可:记录所有可能的带宽,然后枚举带宽求最优价

稻草人 1992

Ubuntu22.04 apt 安装 ROS1 ROS Noetic Ninjemys

ubuntu 22.04 apt-get 安装 ros1 ros Noetic 最新版

autolabor的博客 5万+

ZOJ刷题指南

题单

Demilly123的博客 2416

LAMMPS ReaxFF模拟后处理:如何用Python精准追踪C-N键的断裂与形成?

本文详细介绍了如何利用Python对LAMMPS ReaxFF模拟结果进行后处理,精准追踪C-N键的断裂与形成过程。通过解析键级输出文件、构建原子类型映射字典,并实现C-N键的统计与可视化,为材料科学和催化反应研究提供了高效的数据分析解决方案。文章特别强调了ReaxFF力场在断键分析中的关键作用,并提供了完整的Python代码实现。

weixin_28706923的博客 355

Marvell 88E6390x交换芯片:从零构建No-CPU模式网络交换系统

本文详细介绍了如何为Marvell 88E6390x以太网交换芯片构建No-CPU模式网络交换系统。通过解析其核心价值与硬件准备,并手把手指导使用CodeBlocks、IMPGUI和SwitchGUI等软件工具进行配置代码编写、镜像生成与烧录,最终实现交换芯片脱离外部CPU独立工作,适用于成本敏感、空间受限的嵌入式网络设备设计。

plant的博客 482

zoj4092.Robot Cleaner I(模拟水)

Robot Cleaner I Time Limit:1 Second Memory Limit:65536 KB Tired of tidying up his room, BaoBao decides to invent a robot cleaner to help him do...

Amove 726

Android一个APP里面最少有几个线程

Android应用启动时,默认会创建一个进程,该进程中最少包含负责处理用户交互、UI更新等核心操作,所有与界面相关的逻辑必须在此线程执行。若在此线程执行耗时操作(如网络请求),会导致界面卡顿甚至触发ANR(应用无响应)。当对象重写了finalize()方法时,该线程负责将这些对象放入队列并调用其finalize()方法,完成资源释放后再由GC回收。监控的执行效率。如果finalize()方法执行超时(默认10秒),此线程会触发虚拟机退出以防止应用长时间阻塞。

编程进化论 613

【ZOJ浙大校赛19】【模拟】Robot Cleaner I

题目链接:传送门 【题意】: 一个打扫机器人(说到机器人,恭喜LDU在2019-04-21 Robocup中获得全国冠军,为自己的学校及飞哥感到骄傲)。 然后执行指令,在一个指令条中根据当前格子的4联通即当前格子,用3进制来运算,得到的数字进行执行指令。 所以这个题目就是一个大模拟,上下左右的走(U,D,L,R),同时有一个不工作偷懒(I),还有捡起垃圾(P)。 但是捡起垃圾后会清空当...

Z_sea的博客 370

【ATC/DTC方法第四期】GOT09-dT-tao 昼夜温度周期模型方法介绍(含Python代码实现)

GOT09-dT-tao 模型是一种经过简化和参数固定的 昼夜温度周期模型(Diurnal Temperature Cycle, DTC)。它从 GOT09 模型(Göttsche and Olesen, 2009)衍生而来,但更加轻量化,更适合在数据不足或参数估计困难的情境下使用。

WW、forever的博客 145

RTOS与Linux功能差异与应用场景全面对比

在嵌入式系统的开发中,操作系统的选择至关重要。和是两种广泛应用的操作系统,它们在功能、设计目标以及应用领域中各具优势。随着嵌入式系统的不断发展,已成为嵌入式行业的大趋势。那么,这两者到底有什么不同呢?

硬核科技 400

【ZOJ题目分类】备忘

ZOJ题目分类 初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 1334 1337 1338 1350 1365 1382 1383 1394 1402 1405 1414 1494 1514 1622 1715 1730 1755 1760 1763 17

「谁定义我是我」 1289

中国土地市场网爬取

实习期间老板需要对土地数据进行爬取,想来想去就Google到了.应该算是种类最齐全的土地数据了。Github地址:https://github.com/AnTi-anti/china_land/tree/master。

猫敷雪 5462

zoj并查集系列

zoj系列学习——并查集 题型: 并查集 三步走 查找 合并 压缩 问题描述 zoj2833Friendship 题目简析: 已知N个人 M条指令,有两种操作M(朋友关系)Q(查询) 比较典型的并查集问题。 该问题已经提示要用scanf 和 printf了 没有ac的代码,说是超时问题 #include <iostream> #include<stdio.h> #include<cmath> #include <string.h> using name

BUTTY_LUO的博客 574

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

蓝牙模块HM-10手册

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

poj完整分类

DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  1024   Calendar Game       简单题  1027   Human Gene Functions   简单题  1037   Gridland            简单题  1052   Algernon s Noxious

zhongkeli的专栏 7874

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

ZOJ问题(找规律,字符串处理)

                                               ZOJ问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4909    Accepted Submission(s): 1510   P...

chengsilin666的博客 720

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

分类

 10月20日Zoj Problem Classfication & Brief Report(Updating...)简单题#1001 -____-b  A+B。#1110 Dick and Jane 胡乱枚举收缩一下情况就可以了。#1115 a[i+1] = a[i] 的全部数位上的加起来,直到剩下一个,直接模拟。#1414 太弱太弱,按照模 4 分类讨论一下即可。#1713

Solidfish的专栏 3297

杭电、POJ、ZOJ ACM刷题顺序和题目分类详解

首先推荐一个各大ACM网站的一键直达网站。 链接地址:https://vjudge.net 杭电OJ刷题顺序推荐 第一阶段:开始入门!(15天,53题) 一.输入输出练习(2天,10题) 1000、1089—1096、1001二.简单操作(2—4天,12题) 2000—2011、2039三.英文题试水(3—4天,8题) 1720、1062、2104、1064、2734、1170、1197、2629四.回归水题(4-6天,24题) 2012—2030、2032、2040、2042、...

Lycodeboy的博客 1万+

ZOJ 分类

ZOJ题目分类 初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 1334 1337 1338 1350 1365 1382 1383 1394 1402 1405 1414 1494 1514 1622 1715 1730 1755 1760 1763 1796

Lemon_Chen 1万+

ZOJ 开源项目使用教程

ZOJ 开源项目使用教程 1. 项目的目录结构及介绍 ZOJ 项目的目录结构如下: zoj/ ├── app/ │ ├── controllers/ │ ├── models/ │ ├── views/ ├── config/ ├── public/ │ ├── css/ │ ├── js/ ├── tests/ ├── vendor/ ├── .env ├── .gitign...

gitblog_00500的博客 407

杂文 ZOJ问题 hdoj 3788

/* ZOJ问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2669    Accepted Submission(s): 812 Problem Description 对给定的字符串(只包含'z','o','j'三

亿念之茶的专栏 2764
上一篇: zoj 4097 Rescue the Princess (缩点+LCA)
下一篇: codeforces 1153D Serval and Rooted Tree(树形dp+贪心)
Link_Ray
博客等级 码龄9年 44粉丝 156原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值