Codeforces Round #323 (Div. 2) B. Robot's Task(模拟)
来源:互联网 发布:淘宝怎么用话费支付 编辑:程序博客网 时间:2024/06/05 04:09
题目地址
题目大意:给出n个数,表示有n台电脑,每台电脑上自带一条信息,n个数表示机器人要黑掉该台电脑所需要的最少信息条数,题目说明一定存在某种路线能够黑掉所有的电脑,机器人一开始朝向右边,求机器人黑掉所有电脑所需要的最少的改变方向的次数
解题思路:不断记录黑掉的电脑的台数,即得到了该台电脑上的信息,黑掉一台电脑把其值标记为n+1,永远不能达到,先从左到右一次扫描要求的信息数比当前的信息数少的黑掉,再转向从右向左扫描要求的信息数比当前的信息数少的黑掉,若某次黑掉电脑的总数为n,即可输出转向的次数。
#include <bits/stdc++.h>using namespace std;const int maxn = 1e3+100;int a[maxn];int main(){ int n; while(scanf("%d",&n) != EOF) { for(int i = 0; i < n; i++) scanf("%d",&a[i]); int sum = 0,res = 0; while(true) { for(int i = 0; i < n; i++) if(a[i]<=sum) a[i]=n+1,sum++; if(sum==n) break; res++; for(int i = n-1; i >= 0; i--) if(a[i]<=sum) a[i]=n+1,sum++; if(sum==n) break; res++; } printf("%d\n",res); } return 0;}
0 0
- Codeforces Round #323 (Div. 2) B. Robot's Task(模拟)
- Codeforces Round #323 (Div. 2) B. Robot's Task
- Codeforces Round #323 (Div. 2) B. Robot's Task
- Codeforces Round #323 (Div. 2)B. Robot's Task
- Codeforces Round #323 B Robot's Task
- 【Codeforces Round 323 (Div 2)B】【贪心】Robot's Task 最少转弯次数拿走所有物品
- Codeforces Round #323(div2) 583B. Robot's Task
- Codeforces Round #323 (Div. 2) B 模拟
- cf#323-div2-B. Robot's Task-简单模拟
- ocderforce 583B Robot's Task(模拟)
- Codeforces Round #339 (Div. 2)-B. Gena's Code(字符串模拟)
- Codeforces Round #343 (Div. 2) -B. Far Relative’s Problem(模拟)
- Codeforces Round #387 (Div. 2)B. Mammoth's Genome Decoding(简单模拟)
- cf 583 B. Robot's Task(模拟)
- Robot's Task(模拟)
- Codeforces Round #362 (Div. 2) B 模拟
- Codeforces Round #315 (Div. 2) B 模拟
- Codeforces Round #105 (Div. 2) B 模拟
- SpriteBuilder中CCMotionStreak提示图片文件找不到
- location.href、parent.location.href、top.location.href、 window.open
- 网站统计中的数据收集原理及实现
- framebuffer开发有我想象的那么简单吗
- OPENWRT-4G-移植-ALT3800
- Codeforces Round #323 (Div. 2) B. Robot's Task(模拟)
- CentOS安装nvidia显卡驱动的正确方法
- 关于用mapreduce做kmeans聚类以及python的numpy和list做矩阵、向量乘法的速度对比
- [Java 程序员]成为优秀Java程序员的10个要点
- [MFC]CTreeView树形视图、CTreeCtrl树形控件
- CISCO学习笔记(八)AS内高级距离矢量路由协议EIGRP
- led子系统 及 内核中led触发器实例
- 查询各数据库数据表的磁盘占用情况
- Android 状态栏背景模糊透明效果实现