Logo aaa 的博客

博客

CF381A

...
aaa
2025-12-01 12:54:08

本文章由 WyOJ Shojo 从洛谷专栏拉取,原发布时间为 2021-04-08 14:59:38

思路

deque是一个好东西。

输入数据用双向队列存储。用一个 while 循环。如果现在是 Sereja 的环节,如果队列的头比尾大,Sereja的牌就加上队列的头,否则加队列的尾。反之,一样。

代码

#include <iostream>
#include <cstdio>
#include <queue>
#include <deque>
using namespace std;

int main()
{
	bool q=0;
	int Sereja=0,Dima=0;
	int n;
	deque<int> a;
	cin>>n;
	for(int i=1;i<=n;++i){
		int t;
		cin>>t;
		a.push_back(t);
	}
	while(!a.empty()){
		if(q==0){
			if(a.front()>a.back()){
				Sereja+=a.front();
				a.pop_front();
				q=1;
				continue;
			}
			Sereja+=a.back();
			a.pop_back();
			q=1;
		}
		else{
			if(a.front()>a.back()){
				Dima+=a.front();
				a.pop_front();
				q=0;
				continue;
			}
			Dima+=a.back();
			a.pop_back();
			q=0;
		}
	}
	cout<<Sereja<<' '<<Dima;
	return 0;
} 

评论

暂无评论

发表评论

可以用@mike来提到mike这个用户,mike会被高亮显示。如果你真的想打“@”这个字符,请用“@@”。