- 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]