2072. Kirill the Gardener 3
http://acm.timus.ru/problem.aspx?space=1&num=2072
回忆一下
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <queue>
#include <map> using namespace std; struct Tmp
{
Tmp()
{
l = ;
r = ;
}
int l;
int r;
}; int main()
{
//freopen("data.in","r",stdin);
int n;
cin>>n;
map<int,Tmp> mt;
for(int i = ; i <= n; ++i)
{
int k;
cin>>k;
mt[k].l = min(mt[k].l, i);
mt[k].r = max(mt[k].r, i);
}
long long ans = n; int lastl = ;
int lastr = ;
long long LANS = ;
long long RANS = ;
for(map<int,Tmp>::iterator it = mt.begin(); it != mt.end(); ++it)
{
Tmp tmp = (it->second); long long TLN = (tmp.r - tmp.l) + min(abs(tmp.r - lastl) + LANS, abs(tmp.r - lastr) + RANS);
long long TRN = (tmp.r - tmp.l) + min(abs(tmp.l - lastl) + LANS, abs(tmp.l - lastr) + RANS);
LANS = TLN;
RANS = TRN;
lastl = tmp.l;
lastr = tmp.r;
} ans += min(LANS, RANS); cout<<ans<<endl;
return ;
}
2072. Kirill the Gardener 3的更多相关文章
- URAL 2072 Kirill the Gardener 3
URAL 2072 思路: dp+离散化 由于湿度的范围很大,所以将湿度离散化 可以证明,先到一种湿度的最左端或者最右端,然后结束于最右端或最左端最优,因为如果结束于中间,肯定有重复走的路 状态:dp ...
- URAL 2072 Kirill the Gardener 3 (单调DP)
[题目链接] http://acm.timus.ru/problem.aspx?space=1&num=2072 [题目大意] 一个园丁要给一排花浇水,每个花都有一个标号,必须要先浇标号小的, ...
- Ural 2072:Kirill the Gardener 3(DP)
http://acm.timus.ru/problem.aspx?space=1&num=2072 题意:有n朵花,每朵花有一个饥渴值.现在浇花,优先浇饥渴值小的(即从小到大浇),浇花需要耗费 ...
- HDU 2072 单词数
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2072 普通解法: /* HDU 2072 单词数 --- 字符串处理 */ #include < ...
- HDU 2072(单词数)题解
以防万一,题目原文和链接均附在文末.那么先是题目分析: [一句话题意] “就是统计一篇文章里不同单词的总数”(已经是一句话了..) [题目分析] 明显需要去重,上set,因为按行分析,又没有EOLN用 ...
- Codeforces 842A Kirill And The Game【暴力,水】
A. Kirill And The Game time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
- Codeforces Round #430 A. Kirill And The Game
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each poti ...
- HDU 2072 - 单词数 - [(有点小坑的)字典树模板题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2072 Problem Descriptionlily的好朋友xiaoou333最近很空,他想了一件没有 ...
- ACM 删数问题 SDUT 2072
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/2072.html 删数问题 Time Limit ...
随机推荐
- Linux 内存泄漏检查工具 valgrind
抄自<从零开始的JSON库教程>,先mark一下,以后再慢慢研究. ======== 引用分割线 ======== 在 Linux.OS X 下,我们可以使用 valgrind 工具(用 ...
- android开发_ViewGroup(组视图)-- 五大布局
view组--ViewGroup(组视图) ViewGroup的作用:在view中添加子控件.ViewGroup的5个子类,就是五大布局: (1) LinearLayout 线性布局(常用) (2) ...
- Android系统应用Mms之短信会话列表加载流程一
1. ConversationList短息会话列表界面 1. 开始进行加载 ConversationList: protected void onStart(){ ... // 进行异步查询 star ...
- 对Activity的DecorView的包装(二)
看了下公司的系统代码对于根布局decor_layout.xml的修改, 有所获. 前些时候才开始做系统开发的时候, 总想改改系统的源码, 至于原因: 人总是想装装, 在踩过几个别人修改的坑后, 还是觉 ...
- HackerRank-Python攻城歷程-1.Tuples
Solution: if __name__ == '__main__': n = int(input()) integer_list = map(int, input().split()) t=tup ...
- 一键快速部署CodeBlocks的EGE图形库工具
大一下学期,学完了c语言的基本内容, 也就开始开发项目了,此时一个图形界面就比较重要了,c语言中不提供图形界面,一般这些是用的其它开发的图形库,如 Easyx .ege等. 本文就提供 Codeblo ...
- Clover 安装 Mac 系统更新 (原版黑苹果)
关于使用原版镜像(即 .dmg )安装黑苹果的升级,笔者写写自身经验吧. 在Clover启动的界面中与Mac OS有关的启动菜单有以下这些: Boot FileVault Prebooter from ...
- python自动化测试常用断言的使用方法
自动化测试中寻找元素并进行操作,如果在元素好找的情况下,大家就可以较熟练地编写用例脚本了,但光进行操作可能还不够,有时候也需要对预期结果进行判断. 下面介绍几个常用断言的使用方法,可以一定程度上帮助大 ...
- http压测工具wrk使用
安装 wrk支持大多数类UNIX系统,不支持windows.需要操作系统支持LuaJIT和OpenSSL,不过不用担心,大多数类Unix系统都支持.安装wrk非常简单,只要从github上下载wrk源 ...
- Android 简单记事本
写在前面 课程作业需要,于是忙活好几天抄了一个简单的记事本,使用已学内容包括Android UI布局,Activity的跳转,SQLite数据库. 开发环境:Android Studio 参考:htt ...