【ACM】2022.7.31训练赛

博客:https://www.cnblogs.com/heystar/

A.Arena

CodeForces - 1487A

题目描述

$ n $ heroes fight against each other in the Arena. Initially, the $ i $ -th hero has level $ a_i $ .

Each minute, a fight between two different heroes occurs. These heroes can be chosen arbitrarily (it’s even possible that it is the same two heroes that were fighting during the last minute).

When two heroes of equal levels fight, nobody wins the fight. When two heroes of different levels fight, the one with the higher level wins, and his level increases by $ 1 $ .

The winner of the tournament is the first hero that wins in at least $ 100^{500} $ fights (note that it’s possible that the tournament lasts forever if no hero wins this number of fights, then there is no winner). A possible winner is a hero such that there exists a sequence of fights that this hero becomes the winner of the tournament.

Calculate the number of possible winners among $ n $ heroes.

输入格式

The first line contains one integer $ t $ ( $ 1 \le t \le 500 $ ) — the number of test cases.

Each test case consists of two lines. The first line contains one integer $ n $ ( $ 2 \le n \le 100 $ ) — the number of heroes. The second line contains $ n $ integers $ a_1, a_2, \dots, a_n $ ( $ 1 \le a_i \le 100 $ ), where $ a_i $ is the initial level of the $ i $ -th hero.

输出格式

For each test case, print one integer — the number of possible winners among the given $ n $ heroes.

样例 #1
样例输入 #1
3
3
3 2 2
2
5 5
4
1 3 3 7
样例输出 #1
1
0
3
提示

In the first test case of the example, the only possible winner is the first hero.

In the second test case of the example, each fight between the heroes results in nobody winning it, so the tournament lasts forever and there is no winner.

翻译【转自洛谷】

n 个英雄在竞技场战斗,初始时第 i 位英雄有能力值 a_i

现在竞技场将进行对决,每分钟都会出现随机的两位(不同的)英雄战斗,最终能力值高的获胜(能力值一样时平局),并且获胜者能力值上升 11(平局时没有英雄的能力值会上升)。

当一位英雄的获胜次数超过 100^500 时,对决结束,该英雄成为赢家。现在请你统计多少英雄可能成为赢家。

T 组数据。

$ 1≤T≤500 $ ;
$ 1≤n,ai ≤ 100 $;

思路

模拟,按照题目给的Notes,可以知道,找出数组a中最小的数的个数,答案就是总个数-最小值的个数

代码
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

const int N = 110;
int a[N];

void solve()
{
   
   
	int n;
	cin >> n;
	
	int mina = 0x3f3f3f3f;
	for(int i = 1;i <= n;i ++)
	{
   
   
		cin >> a[i];
		mina = min(mina , a[i]);	
	}
	
	sort(a+1,a+n+1);
	int ans = 0;
	for(int i = 1;i <= n;i ++)
	{
   
   
		if(a[i] != mina)
		{
   
   
			ans = i-1;
			break;
		}
	}
	
	if(ans == 0)
	{
   
   
		cout << 0 << endl;
		return ;
	}
	
	else
		cout << n-ans << endl;
	
	return ;
}

int main()
{
   
   
	int T;
	cin >> T;
	
	while(T --)
		solve();
	
	return 0;
}

B.方程的解

计蒜客 A1142

题目描述

给出方程组:
image
已知 x,y,z 均为正整数,请你计算 x,y,z 相加和最小为多少。

思路

模拟,三重循环,解出答案

代码
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
   
   
	int x , y , z;
	
	for( x = 0;x <= 224;x ++)
	{
   
   
		for( y = 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值