NC221651. Meetinanotherworld,enjoytastyfood!
描述
输入描述
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; }