CF450A 【Jzzhu and Children】

普通的模拟题
这题用一个队列容器来模拟队列元素是pair类型的,first用来存每个小朋友想要的糖数,second用来存小朋友的序号,然后开始模拟,模拟出口是当队列迟到等于1时就输出当前队列里小朋友的序号。
具体代码:

#include<bits/stdc++.h>
using namespace std;
int n,m,x,tot,sum;
queue<pair<int,int> >a;
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>x;
		a.push(make_pair(x,i));
	}
	while(a.size()!=1){
		tot=a.front().first;
		sum=a.front().second;
		a.pop();
		tot-=m;
		if(tot>0)a.push(make_pair(tot,sum));
	}
	cout<<a.front().second<<endl;
	return 0;
}

  

猜你喜欢

转载自www.cnblogs.com/20020219-liu/p/11609798.html
今日推荐