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的更多相关文章

  1. URAL 2072 Kirill the Gardener 3

    URAL 2072 思路: dp+离散化 由于湿度的范围很大,所以将湿度离散化 可以证明,先到一种湿度的最左端或者最右端,然后结束于最右端或最左端最优,因为如果结束于中间,肯定有重复走的路 状态:dp ...

  2. URAL 2072 Kirill the Gardener 3 (单调DP)

    [题目链接] http://acm.timus.ru/problem.aspx?space=1&num=2072 [题目大意] 一个园丁要给一排花浇水,每个花都有一个标号,必须要先浇标号小的, ...

  3. Ural 2072:Kirill the Gardener 3(DP)

    http://acm.timus.ru/problem.aspx?space=1&num=2072 题意:有n朵花,每朵花有一个饥渴值.现在浇花,优先浇饥渴值小的(即从小到大浇),浇花需要耗费 ...

  4. HDU 2072 单词数

    题目链接  http://acm.hdu.edu.cn/showproblem.php?pid=2072 普通解法: /* HDU 2072 单词数 --- 字符串处理 */ #include < ...

  5. HDU 2072(单词数)题解

    以防万一,题目原文和链接均附在文末.那么先是题目分析: [一句话题意] “就是统计一篇文章里不同单词的总数”(已经是一句话了..) [题目分析] 明显需要去重,上set,因为按行分析,又没有EOLN用 ...

  6. 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 ...

  7. 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 ...

  8. HDU 2072 - 单词数 - [(有点小坑的)字典树模板题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2072 Problem Descriptionlily的好朋友xiaoou333最近很空,他想了一件没有 ...

  9. ACM 删数问题 SDUT 2072

    http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/2072.html 删数问题 Time Limit ...

随机推荐

  1. VMware install MikroTik RouterOS

    1 download the vmdk from Mikro Tik official website 2 create a new vmware host with use an exited vm ...

  2. Oracle 12c 单实例安装

    准备工作 实验环境:Redhat 6.6   Oracle 12c 12.2.0.1 1.官网下载 https://www.oracle.com/technetwork/database/enterp ...

  3. 基于OpenCV做“三维重建”(4)--相机姿态还原和实现三维重建

    v当我们构建成功了viz,就可以使用3维效果给我们提供的便利,进一步进行一些3维的操作. 在这个动画中,注意图片后面的那个黑线,对应的是相机的位置. /*----------------------- ...

  4. 对于SQL注入的理解

    从网上搜索的资料,结合自己的理解整理了一下,网友们在查看时若有发现问题,还请不吝指正,谢谢! 1.什么是SQL注入? ——官方说法:把SQL命令插入到web表单验证的输入框中,提交到服务器,以达到越过 ...

  5. android TextView描边

    前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要重写了onDraw方法. 这一边讲一个进阶功能,实现textView的描边效果. 上效果图. 上代码: public class St ...

  6. 论文笔记:Auto-ReID: Searching for a Part-aware ConvNet for Person Re-Identification

    Auto-ReID: Searching for a Part-aware ConvNet for Person Re-Identification 2019-03-26 15:27:10 Paper ...

  7. go 笔记

    Go 语言的变量声明格式为: var 变量名 变量类型 返回类型. 匿名变量不占用命名空间,不会分配内存.匿名变量与匿名变量之间也不会因为多次声明而无法使用. func GetData() (int, ...

  8. SpringIOC的概念理解、构造器注入、setter注入、p命名空间注入、IOC容器介绍与比较

    1.IOC概念理解 IOC(Inversion of Control)即“控制反转”,不是什么技术,而是一种设计思想.在Java开发中,Ioc意味着将你设计好的对象交给容器控制,而不是传统的在你的对象 ...

  9. Struts2---动态action以及应用

    为了处理各种逻辑业务,根据execute方法来判断请求哪种业务,然后将请求转发到对应的业务处理上, 通过动态请求action对象中的方法,实现某个单一的业务逻辑处理. 动态action的应用 //创建 ...

  10. Predict Referendum by sklearn package

    Background Last day we talk about Python Basics in Chinese. Today, we will do data analysis with pyt ...