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 ...
随机推荐
- deno深入揭秘及未来展望
deno node.js之父Ryan Dahl在一个月前发起了名为deno的项目,项目的初衷是打造一个基于v8引擎的安全的TypeScript运行时,同时实现HTML5的基础API.所谓的安全运行时, ...
- VueScroller 使用
下载插件 npm install vue-scroller -D 引入插件: import Vue from 'vue'import VueScroller from 'vue-scroller' ...
- [c/c++] programming之路(28)、结构体存储和内存对齐+枚举类型+typedef+深拷贝和浅拷贝
一.结构体存储 #include<stdio.h> #include<stdlib.h> struct info{ char c; //1 2 4 8 double num; ...
- 使用pynlpir增强jieba分词的准确度
在使用jieba分词时,发现分词准确度不高.特别是一些专业词汇,比如堡垒机,只能分出堡垒,并不能分出堡垒机.这样导致的问题是很多时候检索并不准确. 经过对比测试,发现nlpir进行分词效果更好.但是n ...
- es6 class中责任链模式与AOP结合
责任链模式大家应该都清楚,比如JS中的冒泡,Java中的拦截器.过滤器,都运用到了责任链模式. 可以看我之前的文章介绍责任链的:https://www.cnblogs.com/wuguanglin/p ...
- EmberJS 为什么我偏爱 Ember.js 胜过 Angular 和 React.js
文章写的很老到,非常值得一看!评论也很精彩,值得一看 为什么我偏爱 Ember.js 胜过 Angular 和 React.js 前几天看到了这篇文章:Why I prefer Ember.js ov ...
- logstash 抓取IIS日志文件写入Elasticsearch
如果需要对IIS日志进行分析可以使用logstash从文件中抓取出来进行分析: 输入部分: input { file { type => "iis_log_monitor" ...
- BZOJ-3208|记忆化搜索-花神的秒题计划Ⅰ
背景[backboard]: Memphis等一群蒟蒻出题中,花神凑过来秒题-- 描述[discribe]: 花花山峰峦起伏,峰顶常年被雪,Memphis打算帮花花山风景区的人员开发一个滑雪项目. 我 ...
- scipy插值与拟合
原文链接:https://zhuanlan.zhihu.com/p/28149195 1.最小二乘拟合 实例1 import numpy as np import matplotlib.pyplot ...
- vue数据变动监测
原文链接:https://blog.csdn.net/man_tutu/article/details/72148362 对象: 不能监测到: var vm = new Vue({ data:{ a: ...