跳到正文

题解

AT2141 AtCoDeerくんと変なじゃんけん / AtCoDeer and Rock-Paper 题解

QwQ蒟蒻wjr约 2 分钟
原文
文章信息与版本

文章信息

发布
2019年8月2日
收录
2026年10月13日
更新
2026年11月12日
篇幅
约 2 分钟
获赞
4

版本

  1. v1当前

冒昧地问一句,这题是被而已评分的吗?

显然你能选帕子就选帕子。

假设第一个人全出石头。

考虑把一些石头修改成帕子。

这样贡献只增不减,加起来就是答案。

C++
#include<cstdio>
#include<cstring>
#define re register
using namespace std;
template<typename T>
inline void read(T&x)
{
	x=0;
	char s=getchar();
	bool f=false;
	while(!(s>='0'&&s<='9'))
	{
		if(s=='-')
			f=true;
		s=getchar();
	}
	while(s>='0'&&s<='9')
	{
		x=(x<<1)+(x<<3)+s-'0';
		s=getchar();
	}
	if(f)
		x=(~x)+1;
}
char s[1000010],len;
long long ans,sum_1,sum_2;
bool col[1000010];
int main()
{
	scanf("%s",s+1);
	len=strlen(s+1);
	for(int i=1; i<=len; ++i)
	{
		if(s[i]=='p')
		{
			if(sum_1<sum_2)
				sum_1++;
			else
			{
				sum_2++;
				ans--;
			}
		}
		else
		{
			if(sum_1<sum_2)
			{
				sum_1++;
				ans++;
			}
			else
				sum_2++;
		}
	}
	printf("%lld\n",ans);
}
原文