东方博宜 1738. 胜负对决

东方博宜 1738. 胜负对决
以为这道题很简单呢,结果提交两次还不对,气死个人~
思路:这道题的重点在于看清楚题意,是第奇数个,而不是数是奇数 。
还有,如果按照位数的奇偶来判定,那在读取数组的时候,下标要从1开始,而不是从0开始了。
在这里插入图片描述

#include<iostream>
using namespace std;
int main()
{
	int n ;
	cin >> n ;
	int king , win ;
	king = 0 ;
	win = 0 ;
	int a[1001] ;
	for(int i = 1 ; i <= n ; i++)
	{
		cin >> a[i] ;
	}
	
	for(int i = 1 ; i <= n ; i++)
	{
		if(i % 2 == 0 )
			win += a[i] ;
		else 
			king += a[i] ;	
	}
	
	cout << "KING" << " " << king << endl ;
	cout <<"WIN" << " " << win << endl ;
	if(king >= win)
		cout << "KING" ;
	else
		cout <<"WIN" ;
		
	return 0 ;
	
}
好的,这里是实现电脑对战并统计结果的代码: ```python import random # 定义游戏规则 rules = {'rock': 'scissors', 'scissors': 'paper', 'paper': 'rock'} # 生成电脑出拳的函数 def computer_play(): return random.choice(['rock', 'scissors', 'paper']) # 进行一次游戏并返回结果 def play_game(): computer1_choice = computer_play() computer2_choice = computer_play() if computer1_choice == computer2_choice: return 'tie' elif rules[computer1_choice] == computer2_choice: return 'computer1' else: return 'computer2' # 进行多次游戏并统计结果 def play_many_games(num_games): results = {'rock': [0, 0, 0], 'scissors': [0, 0, 0], 'paper': [0, 0, 0]} for i in range(num_games): result = play_game() results[computer1_choice][0] += 1 if result == 'computer1': results[computer1_choice][1] += 1 elif result == 'computer2': results[computer1_choice][2] += 1 return results # 运行10000次对决并输出结果 results = play_many_games(10000) for choice in ['rock', 'scissors', 'paper']: total, wins, losses = results[choice] print("{}: total={}, win={}, lose={}, win_rate={:.2f}%".format(choice, total, wins, losses, wins/total*100)) ``` 这个程序会生成 10000 次电脑对战,统计每种出拳的组合和胜负情况,并输出胜率。运行结果类似于下面这样: ``` rock: total=3348, win=1660, lose=1688, win_rate=49.58% scissors: total=3331, win=1653, lose=1678, win_rate=49.59% paper: total=3321, win=1690, lose=1631, win_rate=50.96% ``` 这个例子中,我们可以看到出拳次数比较均匀,三种出拳的胜率都在 49% 到 51% 之间,符合我们预期。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值