Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴个WA答案,讲讲过程

Posted by 120405217 at 2013-05-28 13:30:44 on Problem 2433
#include<iostream>
#include<vector>
#include<string>
#include<iterator>
#include<algorithm>
#include<sstream>
#include<set>
#include<map>
#include<cstdio>
#include<list>
#include<utility>
using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    
    vector<int> list(1,0);
    for (int i=0; i<n; ++i)
        list.push_back(*istream_iterator<int>(cin));
    list.push_back(0);
    
    map<int, int> higher;
    int lower_than_l(0),lower_than_r(0),lg=0;
    for (int i = 1; i <= n+1; ++i)
    {
        if (list[i]<list[i-1])
        {
            lower_than_l = i;
            lg = 1;
        }else if (lg && list[i]>list[i-1])
        {
            higher[lower_than_r] = lower_than_l;
            lower_than_r = i-1;
            lg = 0;
        }
    }
    higher[lower_than_r] = lower_than_l;
    
    vector<int> solving;
    int level,sum;
    for (map<int, int>::iterator it = higher.begin();
         it != higher.end();
         ++it)
    {
        sum = 0;
        level = max(list[it->first], list[it->second]);
        for (int i = it->first+1; i < it->second; ++i) {
            if (list[i] > level) {
                sum += list[i] - level;
            };
        }
        solving.push_back(sum);
    }
    
    sort(solving.begin(), solving.end());
    sum = 0;
    for (int i = 0; i < solving.size()-k; ++i)
    {
        sum += solving[i];
    }
    cout << sum << endl;
    return 0;
}
in
6 1
4 1 3 2 3 1
out
4
但是此代码:
out
2
原因
to
4 1 2 2 2 1
3个2  依然是峰
才知道这题这么难
流汗不止

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator