Codeforces Round #158 (Div. 2) C. Balls and Boxes(模拟)

原题地址: http://codeforces.com/problemset/problem/260/C

\题意:有 n 个盒子(1-n排好) 盒子里有若干球,任意选择一个盒子 i (这个盒子里保证有球),将球取出,一个一个放入 i + 1 i + 2 … 盒子中,直到取出的球都放完(如果放了第 n 个盒子, 接下来从 1 号盒子开始放 现在告诉你放完后各个盒子里球的数量 和 最后一个球放入的盒子的下标 x , 问你放之前每个盒子里分别有多少球.

思路:经过简单的手动模拟,我们可以知道,初始简单的位置可以一定是所有球中最小的那一个.然后模拟就行了.

#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#define eps 1e-8
#define INF 0x3f3f3f3f
#define MOD 1e9+7
#define PI acos(-1)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define CLR(x,y) memset((x),y,sizeof(x))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int seed = 131;
const int maxn = 1e5 + 5;
int n, x;
ll a[maxn];
int main() {
    scanf("%d%d", &n, &x);
    ll MIN = INF;
    for(int i = 1; i <= n; i++) {
        scanf("%I64d", &a[i]);
        MIN = min(MIN, a[i]);
    }
    ll sum = 0;
    while(a[x] != MIN) {
        a[x]--;
        sum++;
        x--;
        if(x == 0) x = n;
    }
    for(int i = 1; i <= n; i++) {
        if(i == x) printf("%I64d ", sum + n * MIN);
        else printf("%I64d ", a[i] - MIN);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/yiqzq/article/details/81508124