# UVa11292 Dragon of Loowater

Source: Internet
Author: User
Tags chop

Problem-solving ideas: This is a simple greedy problem, the ability of the knight high Price, if the ability to chop a very weak

's head is a waste of talent. So the hired Knights were able to sort from small to large, with all head diameters

According to the order from small to large, one by one to cut it. You can't cut off your current head without hiring.

`1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 Const intMAXN =20005;6 intA[MAXN], B[MAXN];7 intMain ()8 {9     intN, M, Sum, Cnt1, Cnt2;Ten      while(~SCANF ("%d%d", &n, &m) && (n | |m)) One     { A          for(inti =0; I < n; i++) scanf ("%d", &a[i]); -          for(inti =0; I < m; i++) scanf ("%d", &b[i]); -         if(M < n)//because a knight can only chop one head, if the number of knights is less than the                     //The number of headers, the direct output can be.  -         { -printf"Loowater is doomed!\n"); -             Continue; +         } -Sort (A, a + N);//Direct sort sort, default from small to large +Sort (b, B +m); Acnt1 = Cnt2 = SUM =0; at          while(1) -         { -             if(B[cnt2] >= a[cnt1])//If you can cut off the current header, the pointer -                                   //move back one bit.  -             { -Sum + =B[cnt2]; inCnt2 + +, Cnt1 + +;  -             } to             ElseCnt2 + +;//if not, the knight to the big pointer moves back one +  -             if(Cnt1 = = N | | cnt2 = = m) Break;//if any of the pointers have been scanned, jump out.  the         } *         if(Cnt1 = = N) printf ("%d\n", sum);//If all the heads are cut, the output will be the least cost. \$         Elseprintf"Loowater is doomed!\n");Panax Notoginseng     } -     return 0; the}`
View Code

UVa11292 Dragon of Loowater

Related Keywords:

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.