Question:
Input m, n, indicating that there are several cards. The weights are different from each other, and the maximum value is M * n.
Each round has a card for everyone, and the weight wins!
Now the protagonist has n cards in his hand and asks him at least how many games he can win.
Question:
Greedy. Every time you come out, you can see if someone can suppress you.
Or, in other words, it means that everyone will join you and know in advance what cards you are playing! So we don't think about how many players we can win, but how many players we can lose! Another conversion is to see how many cards will win, and it is useless!
Implementation: A stack that does not store things. If you don't understand it, you can check the code... Watermarked ~
#include <cstdio>#include <cstring>#include <algorithm>#define N 10000using namespace std;int n,m,top,ans;bool visit[N];int main(){//freopen("test.in","r",stdin);int i,j,k,t=0;while(scanf("%d%d",&m,&n),m&&n){printf("Case %d: ",++t);m*=n;ans=top=0;memset(visit,0,sizeof(visit));for(i=1;i<=n;i++){scanf("%d",&k);visit[k]=1;}for(i=m;i;i--){if(visit[i]){if(top)top--;else ans++;}else top++;}printf("%d\n",ans);}return 0;}
[Poj1323] Game prediction game, or greedy (this blog uses stack processing)