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