设为首页 加入收藏

TOP

HDU 1338 Game Prediction
2015-07-20 17:21:01 来源: 作者: 【 】 浏览:3
Tags:HDU 1338 Game Prediction

这题我用的是贪心算法,我的理解是这样的:

要求我最少能赢的次数,就是求别人最多能赢的次数。首先把我的牌先升序排序,然后我从小开始出,对于我出的牌,别人应该尽可能的压,而且用他们比我大的最小的那张牌;如果他们不压,那么他们后面这张牌就很有可能用不上,就少赢一次。

#include
  
   
#include
   
     #include
    
      #include
     
       #include
      
        #include
       
         using namespace std; int card[52]; bool used[1002]; int n,m,t; int _find(int x) { for(int i=x+1;i<=t;i++) if(!used[i]) return i; return 0; } int main() { int k=1; while(scanf("%d%d",&m,&n)) { if(n==0&&m==0) break; memset(used,false,sizeof(used)); for(int i=1;i<=n;i++) { scanf("%d",&card[i]); used[card[i]]=true; } sort(card+1,card+n+1); t=n*m; int ans=0; for(int i=1;i<=n;i++) { int a=_find(card[i]); //printf("card=%d,a=%d\n",card[i],a); if(a!=0) used[a]=true; else { ans+=n-i+1; break; } } printf("Case %d: %d\n",k++,ans); } return 0; } 
       
      
     
    
   
  


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇LeetCode-Binary Tree Postorder .. 下一篇poj 3264 Balanced Lineup RMQ线..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Redis on AWS:Elast (2025-12-27 04:19:30)
·在 Spring Boot 项目 (2025-12-27 04:19:27)
·使用华为开发者空间 (2025-12-27 04:19:24)
·Getting Started wit (2025-12-27 03:49:24)
·Ubuntu 上最好用的中 (2025-12-27 03:49:20)