[2016-03-14] [UVA] [11292] [Dragon of Loowater]

Source: Internet
Author: User
Tags chop cmath

  • Time: 2016-03-14-19:50:12
  • Title Number: [2016-03-14][uva][11292][dragon of Loowater]
  • Main topic:
      • There are m knights to cut N Dragons, each knight can see the head of the dragon when and only if the ability value is greater than the diameter of the dragon's head, each in fact, cut off one dragon needs to pay a value equal to the cost of capacity, ask M a knight can chop all dragons, can output the minimum cost, otherwise output "Loowater is doomed!"
  • Input:
      • Multiple sets of data
      • Each set of data
      • Nm
      • diameter of n row faucet
      • M-line Knight's ability value
  • Output:
      • If you can cut all the Dragons, the minimum cost of output
      • Otherwise output "Loowater is doomed!"
  • Analysis:
      • Greedy, knight from the ability low to high start, each actually chooses the first oneself can deal with the Dragon (Dragon by head size sort), can cut down the dragon head the count, cannot directly ignore the judgment next, knows all Dragon chop finish or the knight enumerates over



#include <vector> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> using namespace std; typedef Long long LL; #define The CLR(x, y) memset ((×), (y),sizeof((x))) #define for (x, Y, z) for ( int.) = (y);(x) < (*); + + (x)) #define FORD( x, Y, z) for(int.) = (y);(x) >= (z);--(x))


const int maxn = 20000 +; int A[MAXN],B[MAXN]; int Main () { //freopen ("In.txt", "R", stdin); //freopen ("OUT.txt", "w", stdout); int n,m; while (~scanf ("%d%d", &n,&m) && n + m) { for (i,0,n) scanf ("%d", A + i); for (i,0,m) scanf ("%d", B + i);sort (a,a+n); sort (b,b+m); int j = 0,ans = 0;For (i,0,m) { if(B[i] >= a[j]) {ans + = b[i]; if(++j = = n ) break;                        }                } If(j = = N)printf ("%d\n", ans); Else puts ("Loowater is doomed!");         } return 0;}


From for notes (Wiz)

[2016-03-14] [UVA] [11292] [Dragon of Loowater]

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.