zjnu 1739 PŠENICA()

Description

Our heroes, Mirko and Slavko, plant Christmas wheat every year on Saint Lucy’s Day. It is well known
that stalks of wheat grow at different speeds so, after a certain time, the wheat becomes quite messy.
The guys are determined to solve this problem by playing the following game:
When it’s Mirko’s turn, he chooses a stalk of wheat with the minimal height and prolongs its
height so it’s of the same height as the first stalk longer than it.
When it’s Slavko’s turn, he chooses a stalk of wheat with the maximal height and cuts it to be
of the same height as the first stalk shorter than it.
The game lasts while there are at least three stalks of different heights and the loser is the player
who can’t make his move.
For given heights of all stalks of wheat and the assumption that Mirko is the one starting the game,
determine the winner of the game and the height of the shortest and longest stalk when the game is
finished.

Input

The first line of input contains the integer N (1 <= N <= 100000), the number of wheat stalks.
The second line of input contains N space separated integers that denote the heights of individual
wheat stalks. The height of each stalk will be less than or equal to 100000.

Output

The first line of output must contain the word “Mirko” if Mirko is the winner of the game, or “Slavko”
if Slavko is the winner of the game.
The second line of output must contain the height of the shortest and longest stalk when the game is
finished.

Sample Input

  
  
3 3 3 3

Sample Output

  
  
Slavko 3 3
题意就是给你一个序列,两个人玩游戏,第一个人要把最小的数变成倒数第二小的数,第二个人要把最大的数变成倒数第二大的数,直达这个序列还剩两个数,谁先不能走谁输,输出赢得人。


这是一道很好的模拟题,如果你直接暴力是超时的,所以直接求前缀和成段更新。思路很棒!

AC代码:

#include <stack>
using namespace std;
typedef __int64 ll;
const int maxn=100010;
ll s[maxn],dig[maxn],a[maxn];
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
   ll i,n,tot;
	scanf("%I64d",&n);
	for(i=1;i<=n;i++)
		scanf("%I64d",&a[i]);
	sort(a+1,a+n+1);
	memset(s,0,sizeof(s));
	tot=1;
	for(i=1;i<=n;)
	{
		dig[tot]=a[i];
		for(;i<=n;i++)
		{
			if(dig[tot]==a[i]) s[tot]++;
			else break;
		}
		tot++;
	}
	for(i=2;i<tot;i++)
		s[i]+=s[i-1];
	ll w=tot-1,tsum=0,wsum=0,t=1;
	int last=1;
	while(w-t>1)
	{
		if(tsum+s[t]<=wsum+s[tot-1]-s[w-1])
		{
			last=0;
			tsum+=s[t];
			t++;
		}
		else
		{
			last=1;
			wsum+=s[tot-1]-s[w-1];
			w--;
		}
	}
	if(!last) cout<<"Mirko"<<endl;
	else cout<<"Slavko"<<endl;
	cout<<dig[t]<<" "<<dig[w]<<endl;
    return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值