Link: click here~~
Test instructions
There are N soldiers everyone has a level value, the level of high people can teach low people, meaning is to find the most suitable combination to make the least cost
"Problem-solving ideas"
Just see this question, unexpectedly have no train of thought. Think for a while, actually find the maximum number of repeated elements can be, because the same person must not share one, so the minimum is the maximum number of repetitions, the same as the previous question, finished looking at other people's ideas, found that the map container to do is very convenient:the inside of the map container is a red black tree, We are working on its leaf node, there are two numbers, and the second number is used as a count.
Code:
#include <stdio.h> #include <map> #include <string.h> #include <iostream> #include < algorithm>using namespace Std;const int maxn=3005;int magic[maxn];int main () { int t,a,b,n,m,i,j; while (~SCANF ("%d", &t)) { int maxx=0; map<int, int >aa; for (i=0; i<t; i++) { scanf ("%d", &a); aa[a]++; if (Aa[a]>maxx) maxx=aa[a]; } if (t==0) puts ("0"); else printf ("%d\n", Maxx); } return 0;}
Link: click here~~
Test instructions: Use wood to repair the wall, the minimum number of use, remember that the wood can also be broken. So only when the total size of all the wood and less than the wall is impossible, the others from the big to the small sum, until the len>= wall jumps out!
Very simple ~ ~ It's strange to use sort to WA?
Code:
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm>using namespace Std;int Blocks[10000];int Main () {int l,n; int sum; while (scanf ("%d%d", &l,&n)!=eof) {sum=0; for (int i=1; i<=n; i++) {scanf ("%d", &blocks[i]); if (sum<l) sum+=blocks[i]; } if (sum<l) {printf ("impossible\n"); Continue }//sort (Blocks,blocks+n); for (int x=1; x<n; x + +) for (int y=x+1; y<=n; y++) {if (blocks[y]>blocks[x]) Swap (blocks[y],blocks[x]); } sum=0; for (int j=1; j<=n; J + +) {Sum+=blocks[j]; if (sum>=l) {printf ("%d\n", j); Break }}} return 0;}
Greedy topic HDU 1800 Flying to the Mars (looking for the largest repetition element) && HDU 2124 Repair the Wall (greedy)