poj1323
来源:互联网 发布:糯米胶品牌 知乎 编辑:程序博客网 时间:2024/04/30 12:55
【题意】
总共n*m张面值为1..n*m的扑克,n个人,每个人m张扑克,一共m轮,每轮每人出一张扑克,最大的人获胜,给出你的扑克,问你起码能赢多少局
【输入】
多组数据
第一行为n、m,若为两个0表示数据结束
接下来一行m个数字,表示自己的手牌
【输出】
对于每组数据,输出一个数字表示起码能赢多少局
贪心
首先把自己的牌从大到小排序,再把不是自己的牌从小到大排序
因为问的是起码能赢多少局,所以考虑最坏状况
m轮,每次看自己当前最大的是不是全场最大的,
是的话答案加一,自己的队列首指针加一,非自己的队列尾指针减n-1
不是的话,自己的队列首指针加一,非自己的队列首指针加一,尾指针减n-2
错误原因,把m打成了n,最近经常犯一些低级错误,需要重视
program poj1323;type arr=array [0..1001] of longint;var ans,t,m,n,i,j,k,s1,s2,e1,e2:longint; yes:array [0..1001] of boolean; dl,xl:arr;procedure swap (var a,b:longint);var i:longint;begin i:=a; a:=b; b:=i;end;begin t:=0; repeat read(n,m); if (n=0)and(m=0) then break; inc(t); fillchar(yes,sizeof(yes),false); for i:=1 to m do begin read(k); yes[k]:=true; end; e1:=0; e2:=0; for i:=n*m downto 1 do if yes[i] then begin inc(e1); dl[e1]:=i; end else begin inc(e2); xl[e2]:=i; end; s1:=1; s2:=1; ans:=0; for i:=1 to m do if dl[s1]>xl[s2] then begin inc(ans); inc(s1); e2:=e2-n+1; end else begin inc(s1); inc(s2); e2:=e2-n+2; end; writeln('Case ',t,': ',ans); until false;end.
- poj1323
- poj1323
- poj1323
- poj1323
- poj1323(贪心)
- poj1323 贪心
- poj1323(Game Prediction)
- poj1323 Game Prediction 贪心
- poj1323解题报告
- POJ1323 Game Prediction
- POJ1323------Game Prediction
- poj1323解题报告
- poj1323 Game Prediction
- POJ1323 Game Prediction(贪心)
- poj1323,poj2586贪心容易题
- POJ1323 Game Prediction(贪心)
- POJ1323 Game Prediction(贪心)
- POJ1323 Game Prediction(贪心算法训练)
- Oracle时间函数
- php 中常用三种加密函数
- UBUNTU11.10(32bit)下iNodeClient客户端安装
- C++程序设计实验报告(十一)
- 写在前面——关于错误锦集
- poj1323
- android 混淆Conversion to Dalvik format failed with error 1错误
- 小波变换网文精粹:小波变换教程(八)
- UITableView 详细讲解
- oracle里面写脚本把一个表里的数据做处理导入另一个表
- 错误500-内部服务器错误害死人
- 详解linux下wget的用法
- 错误锦集一:循环退出条件(递归退出条件)
- oracle中的 resetlogs+scn恢复