[Poj1323] Game prediction game, or greedy (this blog uses stack processing)

Source: Internet
Author: User

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)

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.