列表

详情


NC221651. Meetinanotherworld,enjoytastyfood!

描述

One evening, Mr.X passed by Luojia Gate as usual and found a long line of KFC at the gate. People waited in line the night before for a limited number of 50 pairs of Genshin badges to be handed out at 10 a.m. However, unfortunately, the number of people in the queue is well over 50. That means there will be people waiting in line all night but not getting the badge they are looking forward to. And the people themselves know it. So they are hoping that a few more people will leave the queue before their patience runs out.
Assuming there are  person waiting in the queue, and the initial patience value of the  person is . In each round, each person will lose the patience value equivalent to his/her current ranking in order from front to back successively for one time. With each additional round, everyone’s patience diminishes once. If a person's patience value is less than or equal to zero, he or she will immediately abandon the queue and leave the queue. Note that when someone leaves the queue, the rank of the person behind him immediately changes.
Mr.X wants to know the order in which everyone will leave if the queue goes on forever.

输入描述

The first line contains an integer , representing the number of people in the queue.
The second line contains  integers , representing the current patience value of the  preson.

输出描述

Output  integers in one line, denoting the order in which  people leave.

示例1

输入:

5
2 2 6 4 5

输出:

2 1 4 5 3

说明:

In the first round, the patience value of people who's still in the queue is . Their patience value and the queue is changed as the way follows:

;

, and since  is reduced to , the  person leaves the queue;

, after  person left, the rank of  person has changed to , so his patience value is reduced by  in this round;

;

.

In the second round, their patience value is reduced as the way follows:

, the  person leaves the queue;

;

, the  person leaves the queue;

, the  person leaves the queue.

And finally, in the fifth round, the patience value of  person is reduced to , and he leaves the queue. So the order in which  people leave in the example is .


原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C 解法, 执行用时: 12ms, 内存消耗: 368K, 提交时间: 2021-05-19 21:29:04

#include<stdio.h>
#define ll long long 
const int maxn=1003;
int n;
const ll inf_ll=0x7FFFFFFFFFFFFFFF; 
ll a[maxn];
int b[maxn];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%lld",&a[i]);
	int sum=0;
	while(sum<n){
		ll minn=1e18+10;
		ll cnt=1;
		for(int i=1;i<=n;++i){
			if(b[i])
                continue;
			if(minn>(a[i]+cnt-1)/(cnt)){
				minn=(a[i]+cnt-1)/(cnt);
			}
			cnt++;
		}
		cnt=1;
		for(int i=1;i<=n;++i){
			if(b[i])continue;
			a[i]-=(minn-1)*(cnt);
			cnt++;
		}
		cnt=1;
		for(int i=1;i<=n;++i){
			if(b[i])continue;
			a[i]-=(cnt);
			if(a[i]<=0){
				printf("%d ",i);
				sum++;cnt--;
				b[i]=1;
			}
			cnt++;
		}
	}
}

C++(clang++11) 解法, 执行用时: 11ms, 内存消耗: 416K, 提交时间: 2021-05-11 14:36:25

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll T[1001];
ll M[1001];
int main(){
  int n;
  int tot=0;
  scanf("%d",&n);
  for(int i=1;i<=n;i++)scanf("%lld",&T[i]);
  while(1){
  	if(tot==n)break;
    ll ma=1e18+1;
    for(int i=1;i<=n;i++){
      if(T[i]==-1)continue;
      ll s=ceil(T[i]*1.0/(i-M[i]));
	  ma=min(ma,s);
	}
	int k=0;
	for(int i=1;i<=n;i++){
        if(T[i]==-1)continue;
	  T[i]-=ma*(i-M[i]);
	  T[i]+=k;
	  M[i]+=k;
	  if(T[i]<=0){
	  	printf("%d ",i);
	  	T[i]=-1;
	  	k++;
	  	tot++;
	  }
	}
  }
    return 0;
}

上一题