原题链接: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=0;
int ans=0;
int d=1;bool used[MAX_N];int main() {cin.sync_with_stdio(false);cin >> n;for (int i = 0; i < n; i++)cin >> a[i];int x = 0;while (cnt != n) {if (cnt >= a[x] && used[x] == 0) {cnt++;used[x] = 1;}if (cnt == n)break;x += d;if (x == n) {x = n - 2;d = -1;ans++;}if (x == -1) {x = 1;d = 1;ans++;}}cout << ans << endl;return 0;
}

转载于:https://www.cnblogs.com/HarryGuo2012/p/4854890.html

Codeforces 583 DIV2 Robot's Task 贪心相关推荐

  1. codeforces#320(div2) D Or Game 贪心

    codeforces#320(div2) D  "Or" Game  贪心 D. "Or" Game time limit per test 2 seconds ...

  2. codeforces#324(div2) E. Anton and Ira 贪心

    codeforces#324(div2) E. Anton and Ira  贪心 E. Anton and Ira time limit per test 1 second memory limit ...

  3. codeforces 628.div2

    # Codeforces 628.div2 A. EhAb AnD gCd B. CopyCopyCopyCopyCopy C. Ehab and Path-etic MEXs D. Ehab the ...

  4. Codeforces 437C The Child and Toy(贪心)

    题目连接:Codeforces 437C  The Child and Toy 贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子. #include <iostream> ...

  5. CodeForces - 1395D - Boboniu Chats with Du 贪心

    CodeForces - 1395D - Boboniu Chats with Du 贪心 题意:如果ai>ma_i>mai​>m,并且当天可以说话,则接下来ddd天不能说话.其余所 ...

  6. codeforces 712 div2 ABC

    codeforces 712 div2 ABC A. Déjà Vu A palindrome is a string that reads the same backward as forward. ...

  7. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  8. Educational Codeforces Round 12 C. Simple Strings 贪心

    C. Simple Strings 题目连接: http://www.codeforces.com/contest/665/problem/C Description zscoder loves si ...

  9. Codeforces 846 B Math Show DFS + 贪心

    题目链接: http://codeforces.com/contest/846/problem/B 题目描述: 有N个节点, 每个节点有相同的K个子节点, 每个子节点有时间花费,完成一个子节点获得1分 ...

最新文章

  1. 揭秘:人工智能迅猛发展的本质是什么?
  2. MySQL大数据量分页查询方法及其优化
  3. 烧水壶起水沟了怎么办?
  4. redis on windows
  5. Android中使用Handler(消息机制)造成内存泄露的分析和解决
  6. poj 1654 Area 多边形面积
  7. python实现快速创建订单_从销售订单和Od中的产品订单创建新记录
  8. 2021“MINIEYE杯”中国大学生算法设计超级联赛(2)I love exam(背包)
  9. [Maven问题总结]Maven+Tomcat7
  10. 去年五一的大理丽江之行,今年的得在加班中度过了
  11. 搭建个人云盘保姆级教程
  12. Matlab图像的二维傅里叶变换频谱图特点研究
  13. C++中begin()函数的含参数的使用
  14. 使用Windows Powershell卸载和安装Win10 原生应用的方法
  15. OpwnWrt 路由器MWAN3多线多拨实现方法
  16. xftp(windows系统与linux系统之间文件传输)
  17. 黑盒测试技术(概念等价类划分法详细)——软件质量保证与测试
  18. 【数据结构功法】第2话 · 一篇文章带你彻底吃透·算法复杂度
  19. Java将Excel文件、Word文件转为PDF
  20. 陈安之、王顺杰、翟鸿燊这些成功学讲师有些语句确实很发人深省为什么说他们是大忽悠呢?

热门文章

  1. 2013蓝桥杯C++B:高斯日记;马虎的算式(2种解法)
  2. bzoj 1602: [Usaco2008 Oct]牧场行走(暴力LCA)
  3. C++ STL vector容器的插入和删除
  4. python调试利器pysnooper
  5. hadoop+hive+hbase+spark补充内容
  6. c#压缩解压缩bzip2、tar、zip、gzip、deflate、ntdll
  7. jquery系列教程6-ajax的应用全解
  8. java数组实现队列
  9. VMWare workstation Pro 14 For Linux key
  10. Python2.7.3 Tkinter Entry(文本框) 说明