2072. Kirill the Gardener 3
2017-02-07 21:39
1036 查看
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 = 1000000001; r = 0; } int l; int r; }; int main() { //freopen("data.in","r",stdin); int n; cin>>n; map<int,Tmp> mt; for(int i = 1; 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 = 1; int lastr = 1; long long LANS = 0; long long RANS = 0; 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 0; }
相关文章推荐
- ural 2072 - Kirill the Gardener 3 - dp
- Ural 2072 Kirill the Gardener 3
- URAL 2072 Kirill the Gardener 3
- URAL 2072 Kirill the Gardener 3 (单调DP)
- ural 2072 - Kirill the Gardener 3 详细题解 (思维+dp)
- Kirill the Gardener 3 URAL 2072
- codeforces 842 A. Kirill And The Game(阅读题)
- 【 Codeforces Round #430 (Div. 2) A 】 Kirill And The Game
- Codeforces 842A. Kirill And The Game (暴力)
- A - Kirill And The Game
- Codeforces Round #430 A. Kirill And The Game
- Codeforces Round #430 (Div. 2) A. Kirill And The Game
- Codeforces 842 A Kirill And The Game
- (数学水题)Codeforces A. Kirill And The Game
- Kirill And The Game
- CF 842A - Kirill And The Game
- A. Kirill And The Game
- 培训经历:Awakening the Dragon Within
- 书讯 -- SQL Server 2005 Practical Troubleshooting The Database Engine
- The NetBeans team is pleased to announce the availability of NetBeans IDE 6.7 Beta.