Rokua P1209 Repair Bullpen = = Codevs 2079 Repair Barn

Source: Internet
Author: User

time limit: 1 s space limit: 128000 KB title level: Golden Gold Title Description Description

In a dark night, under a stormy night, farmer John's barn roof, the door was blown away. Fortunately, many cows are on holiday, so the barn is not full. The bullpen was lined up next to the other, and the cows stayed overnight. There are some cows in the barn, some not. All the barns have the same width. After the door was lost, farmer John had to erect a new plank in front of the barn as soon as possible. His new lumber supplier will supply him with any length he wants, but stingy suppliers can only offer a limited number of planks. Farmer John wants to minimize the total length of wood he buys.

Given: The maximum number of planks possible to buy M (1<= m<=50); The total number of cattle sheds S (1<= s<=200); The total number of cows in the Barn is C (1 <= C <=s), and the cow's Barn number stall_number (1 <= stall_number <= S), calculates the minimum total length of the planks required to stop all cattle sheds. Output the minimum total length of the required planks as an answer.

Enter a description input Description
    • Line 1th: The maximum number of planks m, the total number of cattle sheds s and the total number of cows C (separated by a space)
    • Line 2nd to c+1: Each line contains an integer that represents the number of the cow's barn.
outputs description output Description

A single line contains an integer representing the minimum total length of the required planks.

sample input to sample
4 50 183 4 6 8 1415 16 17 2125 26 27 30 31 40 41 42 43
Sample output Sample outputs -
Sample explanation:

[An optimal arrangement is to use a plate to block the barn 3-8,14-21,25-31,40-43.]

data size & Hint

See description

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 #defineMAXN 10017 intA[maxn],m,k,n,s[maxn],ans;8 BOOLcmpintTaintTB)9 {Ten     returnTa>TB; One } A intMain () - { -scanf"%d%d%d",&n,&k,&m); the     if(n>m) -     { -printf"%d\n", m); -         return 0; +     } -      for(intI=1; i<=m;i++) +scanf"%d",&a[i]); ASort (A +1, a+m+1); at      for(intI=1; i<=m-1; i++) -s[i]=a[i+1]-A[i]; -Sort (s+1, s+m,cmp); -      -      for(inti=n;i<=m-1; i++) -ans+=S[i]; in        -ans+=N; toprintf"%d\n", ans); +      -     return 0; the}

Idea: greedy, input data is not guaranteed ordered, after sorting, discard the maximum distance of n-1, and then sum

Rokua P1209 Repair Bullpen = = Codevs 2079 Repair Barn

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.