ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

【ACM】2022.7.31训练赛

2022-07-31 20:03:01  阅读:125  来源: 互联网

标签:le hour int 31 spot 训练赛 2022.7 include first


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 = 0;y <= 190;y ++)
		{
			for( z = 0;z <= 249;z ++)
			{
				int sum1 = 11*x+13*y+17*z;
				int sum2 = 13*x+17*y+11*z;
				
				if(sum1 == 2471 && sum2 == 2739)
				{
					cout << x+y+z << endl;
					return 0;
				}
			}
		}
	}
	
	return 0;
}

C.Cat Cycle

题目描述

Suppose you are living with two cats: A and B. There are $ n $ napping spots where both cats usually sleep.

Your cats like to sleep and also like all these spots, so they change napping spot each hour cyclically:

  • Cat A changes its napping place in order: $ n, n - 1, n - 2, \dots, 3, 2, 1, n, n - 1, \dots $ In other words, at the first hour it's on the spot $ n $ and then goes in decreasing order cyclically;
  • Cat B changes its napping place in order: $ 1, 2, 3, \dots, n - 1, n, 1, 2, \dots $ In other words, at the first hour it's on the spot $ 1 $ and then goes in increasing order cyclically.

The cat B is much younger, so they have a strict hierarchy: A and B don't lie together. In other words, if both cats'd like to go in spot $ x $ then the A takes this place and B moves to the next place in its order (if $ x < n $ then to $ x + 1 $ , but if $ x = n $ then to $ 1 $ ). Cat B follows his order, so it won't return to the skipped spot $ x $ after A frees it, but will move to the spot $ x + 2 $ and so on.

Calculate, where cat B will be at hour $ k $ ?

输入格式

The first line contains a single integer $ t $ ( $ 1 \le t \le 10^4 $ ) — the number of test cases.

The first and only line of each test case contains two integers $ n $ and $ k $ ( $ 2 \le n \le 10^9 $ ; $ 1 \le k \le 10^9 $ ) — the number of spots and hour $ k $ .

输出格式

For each test case, print one integer — the index of the spot where cat B will sleep at hour $ k $ .

样例 #1

样例输入 #1

7
2 1
2 2
3 1
3 2
3 3
5 5
69 1337

样例输出 #1

1
2
1
3
2
2
65

提示

In the first and second test cases $ n = 2 $ , so:

  • at the $ 1 $ -st hour, A is on spot $ 2 $ and B is on $ 1 $ ;
  • at the $ 2 $ -nd hour, A moves to spot $ 1 $ and B — to $ 2 $ .

If $ n = 3 $ then: - at the $ 1 $ -st hour, A is on spot $ 3 $ and B is on $ 1 $ ;

  • at the $ 2 $ -nd hour, A moves to spot $ 2 $ ; B'd like to move from $ 1 $ to $ 2 $ , but this spot is occupied, so it moves to $ 3 $ ;
  • at the $ 3 $ -rd hour, A moves to spot $ 1 $ ; B also would like to move from $ 3 $ to $ 1 $ , but this spot is occupied, so it moves to $ 2 $ .

In the sixth test case:

  • A's spots at each hour are $ [5, 4, 3, 2, 1] $ ;
  • B's spots at each hour are $ [1, 2, 4, 5, 2] $ .

题面翻译【转自洛谷】

假设有两只猫:猫 A 和猫 B ,共同拥有 \(n\) 个休息地点排成一个环,位置顺时针编号为 \(1\) 至 \(n\),他们要选择休息位置。

对于选择休息位置,两只猫有不同的策略:

猫 A 在第 \(1\) 小时会选择休息位置 \(n\),接下来每过一小时它就会逆时针移一个位置,也就是说它选择的位置的序列为 \(n,n-1,n-2,...,3,2,1,n,n-1,...\)。

猫 B 在第 \(1\) 小时会选择休息位置 \(1\),接下来每过一小时它就会顺时针移一个位置,也就是说它选择的位置的序列为 \(1,2,3,...,n-1,n,1,2,...\)。

特别的,因为猫 A 比猫 B 老,所以猫 A 比猫 B 地位高一些,因此当两只猫相中了同一个位置时,由猫 A 占领这个位置,猫 B 会再顺时针移一个位置到下一个位置。

给定 \(n,k\),求出第 \(k\) 小时猫 B 在哪个位置。

\(T\) 组询问。

\(1\leq T\leq10^4;2\leq n\leq10^9;1\leq k\leq10^9;\)

思路

按照提示或者题意可以知道

  • 当n为偶数时,A和B两只猫,总不会相遇
  • 当n为奇数时,A和B两只猫,每隔n/2就会相遇,因此,我们需要将少走的步数加上

代码

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define PI 3.1415926536

using namespace std;

void solve()
{
	int n , k;
	cin >> n >> k;
	
	if(k == 0)
	{
		cout << 1 << endl;
		return ;
	}
	if(n % 2 == 0)
	{
		if(k % n == 0)
			cout << n << endl;
		else
			cout << k%n << endl;
	}
	else
	{
		int q = n/2;//每隔q次相遇一次 
		int z = (k-1) / q;//少走的步数 
		int m = (z+k) % n;//总共的步数 
		
		if(m == 0)
			cout << n << endl;
		else
			cout << m << endl;
		
	}
}

int main()
{
	int T;
	cin >> T;

	while(T --)
		solve();

	return 0;
}

未完

标签:le,hour,int,31,spot,训练赛,2022.7,include,first
来源: https://www.cnblogs.com/heystar/p/16537909.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有