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. JS版剑指offer

    介绍 用JavaScript刷完了剑指offer,故总结下每道题的难度.解决关键点,详细题解代码可以点链接进去细看. 关于JS刷题的技巧可以看我之前的这篇:JS刷题总结. 剑指offer的题目在牛客网 ...

  2. 爬虫中xpath的特殊用法

    Xpath之starts-with(@属性名称,属性字符串相同部分) 以相同的字符开头的用法 在做爬虫时解析html的源码时候可能会遇见以下这种标签, <div id="test-1& ...

  3. 理解bootstrap的列偏移offset 和 推拉push/pull的区别?

    参考: http://www.cnblogs.com/jnslove/p/5430481.html & https://blog.csdn.net/hly_coder/article/deta ...

  4. html2canvas文字重叠(手机端)

    发现情况: 1.设置文字居中,文字自动换行后文字有重叠   text-align: center; 解决办法: text-align: left; text-align: justify;等 2.使用 ...

  5. Axios Token验证拦截器

    import axios from 'axios'; // req拦截 axios.interceptors.request.use( //设置头部的token config.headers['tok ...

  6. 【ASP.NET】 HttpContext.Current.User.Identity.Name 返回值为空

    问题起因 在做项目的时候,我使用HttpContext.Current.User.Identity.Name来获取Web应用程序正在使用时的用户名. 在开发过程中,我使用了我的本地iis,启用了集成的 ...

  7. 深度学习环境搭建(ubuntu16.04+Titan Xp安装显卡驱动+Cuda9.0+cudnn+其他软件)

    一.硬件环境 ubuntu 16.04LTS + windows10 双系统 NVIDIA TiTan XP 显卡(12G) 二.软件环境 搜狗输入法 下载地址 显卡驱动:LINUX X64 (AMD ...

  8. Chrom Firefox 非安全端口访问

    使用Chrom Firefox 访问非安全端口 问题描述 Firefox 此网址已被限制 此网址使用了一个通常用于网络浏览以外目的的端口.出于安全原因,Firefox 取消了该请求. Chrome 无 ...

  9. 从Scratch到Python——Python生成二维码

    # Python利用pyqrcode模块生成二维码 import pyqrcode import sys number = pyqrcode.create('从Scratch到Python--Pyth ...

  10. kafka知识点

    一.为什么需要消息系统 1.解耦: 允许你独立的扩展或修改两边的处理过程,只要确保它们遵守同样的接口约束. 2.冗余: 消息队列把数据进行持久化直到它们已经被完全处理,通过这一方式规避了数据丢失风险. ...