URAL 2072 Kirill the Gardener 3】的更多相关文章

URAL 2072 思路: dp+离散化 由于湿度的范围很大,所以将湿度离散化 可以证明,先到一种湿度的最左端或者最右端,然后结束于最右端或最左端最优,因为如果结束于中间,肯定有重复走的路 状态:dp[i][0]表示湿度为i结束于左端最优的步数 dp[i][1]表示湿度为i结束于右端最优的步数 初始状态:dp[0][0]=dp[0][1]=0 状态转移: dp[i][0]=min(dp[i][0],dp[i-1][0]+abs(prel-nowr)+abs(nowl-nowr));       …
[题目链接] http://acm.timus.ru/problem.aspx?space=1&num=2072 [题目大意] 一个园丁要给一排花浇水,每个花都有一个标号,必须要先浇标号小的, 移动一格需要一单位时间,浇花需要一单位时间,园丁一开始在最左边的花处, 问浇完所有花的最短时间 [题解] 同一标号的花从开始浇水到结束,最优的一定是从最左边走到最右边 或者从最右边到最左边,所以我们将每种标号的花的最左和最右作为状态做单调dp, 就能得到答案. [代码] #include <cstdi…
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 = ;…
http://acm.timus.ru/problem.aspx?space=1&num=2072 题意:有n朵花,每朵花有一个饥渴值.现在浇花,优先浇饥渴值小的(即从小到大浇),浇花需要耗费1个单位时间,从第i个位置走到第j个位置需要耗费abs(j-i)个单位时间,问浇完所有的花需要耗费的最少时间是多少. 思路:考虑到有饥渴值一样的花,那么只要考虑怎么在饥渴值相同的情况下取最优,那问题便可以迎刃而解了. 首先想,要让时间耗费的少,那么就尽量不要走重复的路程,所以想到这里,可以确定:对于某一个饥…
2064. Caterpillars Time limit: 3.0 secondMemory limit: 64 MB Young gardener didn’t visit his garden for a long time, and now it’s not very pleasant there: ncaterpillars have appeared on the ground. Kirill decided to use this opportunity to have some…
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best programmer in the world! Now he regularly takes part in various programming contests, attentively listens to problems analysis and upsolves problems. But…
2066. Simple Expression Time limit: 1.0 secondMemory limit: 64 MB You probably know that Alex is a very serious mathematician and he likes to solve serious problems. This is another problem from Alex. You are given three nonnegative integers a, b, c.…
Palindromes and Super Abilities 2 Time Limit: 1MS   Memory Limit: 102400KB   64bit IO Format: %I64d & %I64u Status Description Dima adds letters s1, -, sn one by one to the end of a word. After each letter, he asks Misha to tell him how many new pali…
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串中心位置,RMQ询问LCP = min (height[rank[l]+1] to height[rank[r]]),注意的是RMQ传入参数最好是后缀的位置,因为它们在树上的顺序未知,且左边还要+1. #include <cstdio> #include <algorithm> #in…
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and each orders a juice cocktail. It could be from 1 to 3 different juices in each cocktail. There are three juices in the bar: apple, banana and pineappl…