Monsters Battle Royale AtCoder - 4297

Problem Statement
There are N monsters, numbered 1,2,…,N.

Initially, the health of Monster i is Ai.

Below, a monster with at least 1 health is called alive.

Until there is only one alive monster, the following is repeated:

A random alive monster attacks another random alive monster.
As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking.
Find the minimum possible final health of the last monster alive.

Constraints
All values in input are integers.
2≤N≤105
1≤Ai≤109
Input
Input is given from Standard Input in the following format:

N
A1 A2 … AN
Output
Print the minimum possible final health of the last monster alive.

Sample Input 1
4
2 10 8 40
Sample Output 1
2
When only the first monster keeps on attacking, the final health of the last monster will be 2, which is minimum.

Sample Input 2
4
5 13 8 1000000000
Sample Output 2
1
Sample Input 3
3
1000000000 1000000000 1000000000
Sample Output 3
1000000000

思路:这道题就是找最后可以剩下的最小的生命值,由于攻击者在攻击时并不减少血量,所以所剩下最小的一定小于等于初始生命值最小的怪兽,当一个怪兽生命值是另一个怪兽生命值的倍数的时候,那么另一个怪兽就可以完全被生命值小的那个怪兽消灭掉,如果不是整数倍,也可以辗转相减(???)最后得出生下的生命值最小的怪兽。

就是求所有数的最大公约数。。。

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int mod=998244353;
int a[1000010];
int main()
{
	int n;
	cin >>n;
	int x;
	cin >>x;
	int sum=x;
	for(int i=1;i<n;i++)
	{
		cin >>x;
		sum=__gcd(sum,x);
	}
	cout <<sum<<endl;
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值