Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

请求指点,pku---2005

Posted by lzk at 2005-03-16 20:25:24 on Problem 2005
需求高人的帮助啊,想了一天还是未想出错误的地方,附上源代码,请求指点

#include<iostream.h>
#include<iomanip.h>

int card[12];//储存剩余card的张数(未显示的),如:n=1,已知 2,3,4,则card[2]=card[3]=card[4]=3
int n;

void main()
{
	char read[10];
	int three[3];//three[0]储存对方card,three[1],three[2]储存我方cards;
	int sum;
	int remain;
	int i;
	double proba;
	cin>>n;
	cout<<endl;
	while(n>0)
	{
		
		for(i=0;i<3;i++)//读入数据
		{
			cin>>read;
			if(read[0]=='A') three[i]=11;
			else if(read[0]=='J'||read[0]=='Q'||read[0]=='K'||read[0]=='T') three[i]=10;
			else
			{
				three[i]=read[0]-'0';
			}
		}
		if( (three[2]==2 && three[1]==2) || three[1]+three[2]<=three[0]+2 ) //当我方全为2时,或我方之和+2<对方牌时,我方必不能胜
		{
			cout<<"0.000%"<<endl;
			//cout<<0<<endl;
			cout<<endl;
			cin>>n;
			continue;
		}
		for(i=2;i<10;i++)//初始化已有的牌的张数,如n=1时,2有card[2]=4张,10(即10,J,Q,K)有card[10]=4*4=16张
		{
			card[i]=4*n;
		}
		card[10]=16*n;
		card[11]=4*n;
		card[three[0]]--;//减去已知的card ,即得剩余的card
		card[three[1]]--;
		card[three[2]]--;
		remain=three[1]+three[2]-three[0];//我方之和减去对方的牌面值,得到我方不能取胜的最低值
		sum=0;
		for(i=2;i<remain;i++)//我方能取胜的情况
		{
			sum+=card[i];//sum储存我方能取胜时,对方不能
		}
		proba=double(sum)/(n*52-3)*100;//计算概率,并化为百分数
		cout<<setiosflags(ios::fixed)<<setprecision(3)<<proba<<'%'<<endl;
		cout<<endl;
		cin>>n;
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator