原题链接:http://codeforces.com/problemset/problem/583/B

题意:

就。。要打开一个电脑,必须至少先打开其他若干电脑,每次转向有个花费,让你设计一个序列,使得总花费最小。

题解:

就傻傻的走就好。。从左走到右,再走回来,更新序列和答案就好。

代码:

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#define MAX_N 1003
using namespace std; int a[MAX_N];
int n; int cnt=;
int ans=;
int d=; bool used[MAX_N]; int main() {
cin.sync_with_stdio(false);
cin >> n;
for (int i = ; i < n; i++)cin >> a[i];
int x = ;
while (cnt != n) {
if (cnt >= a[x] && used[x] == ) {
cnt++;
used[x] = ;
}
if (cnt == n)break;
x += d;
if (x == n) {
x = n - ;
d = -;
ans++;
}
if (x == -) {
x = ;
d = ;
ans++;
}
}
cout << ans << endl;
return ;
}

最新文章

  1. 【转】前端工程师必须了解的 谷歌 HTML/CSS 规范
  2. .NET跨平台之旅:corehost 是如何加载 coreclr 的
  3. linux常用命令积累
  4. Roslyn 学习笔记(一)
  5. 在linux上通过yum安装JDK
  6. Mysql 排名查询
  7. ruby(html)
  8. 工厂模式 - 程序实现(java)
  9. java和javascript获取word文档的书签位置对比
  10. [ES6] Module export
  11. Android自定义ListView的Item无法响应OnItemClick的解决办法
  12. PAT (Advanced Level) 1063. Set Similarity (25)
  13. c++(hash表)
  14. python中字符串编码转换
  15. python摸爬滚打之day29----socketserver实现服务端和多个客户端通信
  16. Codeforces Round #487 (Div. 2) C - A Mist of Florescence
  17. linux命令总结之echo命令
  18. 第9月第9天 CTFramesetterCreateWithAttributedString
  19. POJ 1548 Robots(最小路径覆盖)
  20. Graph-BFS-图的广度优先遍历

热门文章

  1. vim编辑器最简单使用方法
  2. mysql-update时where条件无索引锁全表
  3. Windows下如何用CMD命令跳转到指定的目录下
  4. 【bzoj3339】Rmq Problem
  5. JS一个非常经典的问题:在遍历数组时对DOM监听事件,索引值将始终等于遍历结束后的值
  6. 申请社交平台appkey详细教程
  7. leetcode 【 Reorder List 】python 实现
  8. Python+Selenium练习篇之8-利用css定位元素
  9. web访问流程
  10. js验证密码强弱