原题链接: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 ;
}

Codeforces 583 DIV2 Robot's Task 贪心的更多相关文章

  1. Codeforces 583 DIV2 GCD Table 贪心

    原题链接:http://codeforces.com/problemset/problem/583/C 题意: 大概就是给你个gcd表,让你还原整个序列. 题解: 由$GCD(a,a)=a$,我们知道 ...

  2. Codeforces 583 DIV2 Asphalting Roads 模拟

    原题链接:http://codeforces.com/problemset/problem/583/A 题意: 很迷很迷,表示没看懂..但是你看样例就秒懂了 题解: 照着样例模拟就好 代码: #inc ...

  3. Codeforces 922 C - Robot Vacuum Cleaner (贪心、数据结构、sort中的cmp)

    题目链接:点击打开链接 Pushok the dog has been chasing Imp for a few hours already. Fortunately, Imp knows that ...

  4. Codeforces Round #323 (Div. 2) B 贪心,暴力

    B. Robot's Task time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  5. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

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

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

  7. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  8. codeforces #321 DIV2

    A题: 链接:http://codeforces.com/contest/580/problem/A dp,最长连续不上升子序列 #include<iostream> #include&l ...

  9. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

随机推荐

  1. MySQL和PostgreSQL比较

    1.MySQL相对来说比较年轻,首度出现在1994年.它声称自己是最流行的开源数据库.MySQL就是LAMP(用于Web开发的软件包,包括 Linux.Apache及Perl/PHP/Python)中 ...

  2. Python 代码优化技巧(一)

    Table of Contents 1. 代码优化Part1 1.1. if 判断的短路特性 1.2. join 合并字符串 1.3. while 1 和 while True 1.4. cProfi ...

  3. Windows Server 2012之活动目录域服务的卸载

    Windows Server 2012之活动目录域服务的卸载 2012-07-11 06:27:35 标签:Windows Server 2012 活动目录域服务 卸载 原创作品,允许转载,转载时请务 ...

  4. 数据库脚本开发日志模板 —— 项目需求 A

    前言: 在经历的几家公司的多个项目开发管理中,用 git 或者 svn来管理项目代码,都着重项目代码的管理,却疏于相应脚本的管理.本文可以参考,作为项目需求对应脚本开发记录文件(也建议用单个文件夹下放 ...

  5. maven学习(十一)——maven中的聚合与继承

    一.聚合 如果我们想一次构建多个项目模块,那我们就需要对多个项目模块进行聚合 1.1.聚合配置代码 <modules> <module>模块一</module> & ...

  6. UVALive 5033 I'm Telling the Truth 二分图最大匹配(略有修改)

    I - I'm Telling the Truth Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu ...

  7. php获取客户端mac地址

    exec('/sbin/arp -a 2>&1', $array, $return_val);dump($array);$mac = '';foreach($array as $valu ...

  8. Nginx & Reverse Proxy

    Nginx & Reverse Proxy https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/ https:/ ...

  9. mvcs项目搭建

    项目结构 下载链接:http://pan.baidu.com/s/1hsGtShA

  10. 刷题总结——Genghis Khan the Conqueror (hdu4126)

    题目: Genghis Khan(成吉思汗)(1162-1227), also known by his birth name Temujin(铁木真) and temple name Taizu(元 ...