2019小学组——stone

题目

在这里插入图片描述

思路

first

题目要求是有序有序整数对
在这里插入图片描述
所以可以用队列进行运算。为判断是否是从大到小进入队列,我们用
这段代码来判断 ——附c++ operator的用法汇总

bool operator<(const node&a) const {
return x>a.x||x==a.x&&y>a.y;
}

second

题目说明小明只踢第奇数个
在这里插入图片描述
判断石子的个数则用if语句来实现

if(i%2) {

	} else{
	
	}

third

题目最终要求的是最远踢出的距离
在这里插入图片描述
所以 ans=q.top().x+q.top().y;

代码

#define LOCAL
#include
#include
using namespace std;

struct node {
int x,y;
bool operator<(const node&a) const {
return x>a.x||x==a.x&&y>a.y;
}
};
priority_queue q;
priority_queue p;
int main() {
#ifdef LOCAL
freopen(“c:\BJZHC0\stone\stone1.in”, “r”, stdin);
freopen(“c:\BJZHC0\stone\stone1.out”, “w”, stdout);
#endif
int n,k=0,temp=0;
node t;

cin>>n;
for(int i=0; i<n; i++) {
	cin>>t.x>>t.y;
	q.push(t);
	//	p.push(t);
}
/*
while(!p.empty()) {
	node n1;
	n1.x=p.top().x;
	n1.y=p.top().y;
	cout<<n1.x<<" "<<n1.y<<endl;
	p.pop();
}
*/
int i=1,ans=0;
node now;
while(!q.empty()) {
	now.x=q.top().x+q.top().y;
	now.y=q.top().y;
	if(i%2) {
		q.push(now);
		ans=q.top().x+q.top().y;
		q.pop();
	} else
		q.pop();
	i++;
}

cout<<ans;

#ifdef LOCAL
fclose(stdin);//关闭重定向输入
fclose(stdout);//关闭重定向输出
#endif
return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值