描述:

  Suppose there are M people, including you, playing a special card game. At the beginning, each player receives N cards. The pip of a card is a positive integer which is at most N*M. And there are no two cards with the same pip. During a round, each player chooses one card to compare with others. The player whose card with the biggest pip wins the round, and then the next round begins. After N rounds, when all the cards of each player have been chosen, the player who has won the most rounds is the winner of the game.

  Given your cards received at the beginning, write a program to tell the maximal number of rounds that you may at least win during the whole game. 

  The input consists of several test cases. The first line of each case contains two integers m (2?20) and n (1?50), representing the number of players and the number of cards each player receives at the beginning of the game, respectively. This followed by a line with n positive integers, representing the pips of cards you received at the beginning. Then a blank line follows to separate the cases.

  The input is terminated by a line with two zeros.

  For each test case, output a line consisting of the test case number followed by the number of rounds you will at least win during the game.

代码:

  题中说最少能赢的最大次数,意味着我们要求的是必胜的次数,可以脑补,当场上有人拿比你这次出的牌更大的牌的时候,你是必输的。

  所以只需要知道场上有没有比你牌大的牌,就可以确定这次是不是必胜。可以用o(n2)的算法,设置一个数组,标记每张牌是否出过(没有一张牌点数相同),然后每出一个去找。

  这里是o(n)的算法,记录了点数大于你这张牌的牌还没出的数目left,和上一次出牌较小的的点数-1(以便计算这次能有多少张牌没出)。

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include <math.h>
using namespace std;
#define N 105
int cmp( const void *a,const void *b ){
return *(int *)b-*(int *)a;
} int main(){
int m,n,a[N],count,ts=,left,max_left;
while( scanf("%d%d",&m,&n)!=EOF ){
if( m== && n== ) break;
for( int i=;i<n;i++ )
cin>>a[i];
qsort(a,n,sizeof(int),cmp);//递减 left=;max_left=m*n;count=;
for( int i=;i<n;i++ ){
if( left== ){//场上没有剩下的牌
if( max_left==a[i] ){
max_left--;
count++;//必胜
}
else{
left+=(max_left-a[i]-);//这次剩余多少没出
max_left=a[i]-;//记录
}
}
else{
left--;//对方用掉一张赢
left+=(max_left-a[i]);//这次剩余多少没出
max_left=a[i]-;//记录
}
}
printf("Case %d: %d\n",ts++,count);
}
system("pause");
return ;
}

POJ1323-Game Prediction的更多相关文章

  1. 论文阅读(Xiang Bai——【arXiv2016】Scene Text Detection via Holistic, Multi-Channel Prediction)

    Xiang Bai--[arXiv2016]Scene Text Detection via Holistic, Multi-Channel Prediction 目录 作者和相关链接 方法概括 创新 ...

  2. scikit-learn使用笔记与sign prediction简单小结

    经Edwin Chen的推荐,认识了scikit-learn这个非常强大的python机器学习工具包.这个帖子作为笔记.(其实都没有笔记的意义,因为他家文档做的太好了,不过还是为自己记记吧,为以后节省 ...

  3. 【转载】Chaotic Time-Series Prediction

    原文地址:https://cn.mathworks.com/help/fuzzy/examples/chaotic-time-series-prediction.html?requestedDomai ...

  4. (转)LSTM NEURAL NETWORK FOR TIME SERIES PREDICTION

    LSTM NEURAL NETWORK FOR TIME SERIES PREDICTION Wed 21st Dec 2016   Neural Networks these days are th ...

  5. 【软件分析与挖掘】Multiple kernel ensemble learning for software defect prediction

    摘要: 利用软件中的历史缺陷数据来建立分类器,进行软件缺陷的检测. 多核学习(Multiple kernel learning):把历史缺陷数据映射到高维特征空间,使得数据能够更好地表达: 集成学习( ...

  6. FJNU 1155 Fat Brother’s prediction(胖哥的预言)

    FJNU 1155 Fat Brother’s prediction(胖哥的预言) Time Limit: 1000MS   Memory Limit: 257792K [Description] [ ...

  7. MATLAB时间序列预测Prediction of time series with NAR neural network

    具体请参考:http://lab.fs.uni-lj.si/lasin/wp/IMIT_files/neural/nn05_narnet/ 神经网络预测时间序列数据,有三种模型, 这里是给出的是第二种 ...

  8. Kaggle Bike Sharing Demand Prediction – How I got in top 5 percentile of participants?

    Kaggle Bike Sharing Demand Prediction – How I got in top 5 percentile of participants? Introduction ...

  9. Intra Luma Prediction

    在宏块的帧内预测过程中,有四种宏块类型:I_4x4,I_8x8,I16x16,I_PCM.他们都需要在相邻块做去块滤波之前进行帧内预测. 亮度帧内预测的总体流程 1-4获取当前block的帧内预测模式 ...

  10. Intra Chroma Prediction

    帧内预测依赖于当前宏块的相邻宏块,如果任何一个相邻宏块不可用,那么会直接影响到当前宏块的预测方式. 那么宏块怎么才谓之可用? 满足以下几个条件的相邻宏块为不可用: 相邻宏块超出边界,即(x<0 ...

随机推荐

  1. sctf pwn200

    题目给出了pwn200和libc.so.使用IDA查看程序,发现逻辑很简单. 使用checksec查看pwn200的安全属性,如下图: 发现NX enabled,No PIE. 在第一次读(0x080 ...

  2. SecureCRT 绝佳配色方案, 保护你的眼睛(转发)

    SecureCRT 绝佳配色方案, 保护你的眼睛 关键词:SecureCRT配色, SecureCRT设置颜色, Linux终端配色,Linux终端颜色设置. 终端有一个好的配色,不仅能保护自己的眼睛 ...

  3. Cannot create JDBC driver of class '' for connect URL 'jdbc:mysql://127.0.0.1:3306/test'

    原来的配置如下: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http ...

  4. 应用程序无法启动,因为应用程序的并行配置不正确,有关详细信息,请参阅应用程序事件日志,或使用命令行SxsTrace.exe工具

    今天做项目,需要用C#引用C++的链接库文件,但是在调试的时候会报错这个错误. 运行SxsTrace.exe 以管理员用户登陆,启动cmd; 执行命令:SxsTrace Trace -logfile: ...

  5. js 和 jsp关系

    http://stackoverflow.com/questions/11718063/use-javascript-or-jquery-inside-a-cif-statement 纠结了半天的问题

  6. ASP.Net连接WebServer使用Https协议(证书)

    ASP.Net使用Https(证书)协议连接WebService 最近使用ASP.Net连接WebService,不过走的协议是Https的,我一般用的使用都是普通的http协议.所以刚开始有点不值从 ...

  7. Linux系统管理员不可不知的命令:sudo

    对Linux系统管理员或高级用户而言,sudo是必不可少的最重要的命令之一.当我们想要运行重要任务时,sudo提供了安全的提升权限.请耐心读本文,看看sudo能为你做些什么. sudo是个统管一切的命 ...

  8. Opencv 完美配置攻略 2014 (Win8.1 + Opencv 2.4.8 + VS 2013)上

    下载安装软件 下载 Opencv for Windows 最新版本,本文是 Opencv 2.4.8.双击后会出现解压提示,实际上就是“安装”了,路径填写为 D:/Program Files,然后确定 ...

  9. QF——关于iOS的强引用,弱引用及strong,retain,copy,weak,assignd的关系

    强引用和弱引用: 我们已经知道OC中的内存管理是通过“引用计数器”来实现的.一个对象的生命周期取决于它是否还被其他对象引用(是否retainCount=0).但在有些情况下,我们并不希望对象的销毁时间 ...

  10. QF——UI之UIImageView及UIView的形变属性transform

    UIImageView: 专门用来放置图片的视图.它里面放置的图片是[UIImage imageNamed: (NSString) imgName]生成的,注意千万别只写成图片NSString类型的名 ...