Codeforces Round #323 B Robot's Task
来源:互联网 发布:纺织服装行业协会数据 编辑:程序博客网 时间:2024/05/29 14:27
题意:给你n个数,每选定一个数之后要找大于等于他的最小的,也就是从最小的开始找,然后找第一个大于等于他的,问将所有的数都找完最少需要换几次方向、
思路:直接模拟+贪心,一直到找完所有的数、从最小开始找,一直到找完,左边找完找又边,依次从左边的头或者右边的头开始找,一直到找完、
AC代码:
#include<cstdio>#include<cstring>const int maxn = 1100;int n;int a[maxn];int cnt,now;int vis[maxn];int main(){ while(scanf("%d",&n)!=EOF){ memset(vis,0,sizeof(vis)); cnt=0,now=0; for(int i=1;i<=n;i++) scanf("%d",&a[i]); while(1){ if(cnt%2==0){ for(int i=1;i<=n;i++){ if(vis[i]) continue; if(a[i]<=now){ vis[i]=1; now++; } } } else{ for(int i=n;i>=1;i--){ if(vis[i]) continue; if(a[i]<=now){ vis[i]=1; now++; } } } if(now==n)break; cnt++; } printf("%d\n",cnt); } return 0;}
0 0
- Codeforces Round #323 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(div2) 583B. Robot's Task
- Codeforces Round #323 (Div. 2) B. Robot's Task(模拟)
- 【Codeforces Round 323 (Div 2)B】【贪心】Robot's Task 最少转弯次数拿走所有物品
- B. Robot's Task
- cf#323-div2-B. Robot's Task-简单模拟
- cf 583 B. Robot's Task(模拟)
- Code Forces 583 B. Robot's Task(贪心)
- ocderforce 583B Robot's Task(模拟)
- Educational Codeforces Round 32 B. Buggy Robot(模拟)
- Educational Codeforces Round 6 A. Professor GukiZ's Robot
- Robot's Task(模拟)
- Codeforces - Educational Codeforces Round 14B - s-palindrome(模拟)
- CodeForces 888B Buggy Robot
- codeforces 893B. Buggy Robot
- 6.Python深入_内存管理
- [汇编语言]在CPU内部,两个寄存器之间通过什么方式进行读写?
- [汇编语言]sub命令得到的结果,在送入内存之前,是否保存在某个寄存器中
- 如何SPM配置
- Codeforces Round #323 A Asphalting Roads
- Codeforces Round #323 B Robot's Task
- C程序调用matlab (Win8 64 bit + VS 2013 + Matlab R2014a)
- Codeforces #323 D. Once Again... (LIS)
- 大家早安,唠叨的兔几出现了,继续话痨python
- 八大排序算法的Python实现
- android自定义view Paint的setMaskFilter(MaskFilter maskfilter)
- SQL多表连接查询
- java定时器
- 识别为DynamicWeb