[Restart] sdut 2074 -- range coverage Problem

Source: Internet
Author: User

Question: Click to open the link

Not written for more than a monthCodeNow, for Shousheng's 1B and KMP, we can't understand how to avoid being crushed in the tat multi-School Exercise competition .......

Do some greedy questions to find the feeling. This is a typical problem, with a range coverage.

The number of covered line segments should be intercepted as much as possible, and the difference value must be large first, so as to ensure the shortest length of Line Segment coverage.

Do not forget the line segment deviation-1 ..

# Include <iostream> # include <cstring> # include <algorithm> using namespace STD; int qujian [400]; int Cha [400]; bool CMP1 (int A, int B) {return a <B;} bool cmp2 (int A, int B) {return A> B;} int main () {int n, m; while (CIN> N> m) {memset (qujian, 0, sizeof (qujian); memset (CHA, 0, sizeof (CHA )); for (INT I = 0; I <n; I ++) CIN> qujian [I]; sort (qujian, qujian + N, CMP1 ); for (Int J = 0; j <n-1; j ++) {Cha [J] = qujian [J + 1]-qujian [J]-1;} Sort (CHA, CHA + n-1, cmp2); int sum = qujian [n-1]-qujian [0] + 1; for (int K = 0; k <m-1; k ++) {sum-= CHA [k] ;}cout <sum <Endl ;}return 0 ;}

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.