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


    C. Balls and Boxes
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right.

    Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting balls (one at a time) to the boxes with numbers i + 1, i + 2, i + 3 and so on. If Vasya puts a ball into the box number n, then the next ball goes to box 1, the next one goes to box 2 and so on. He did it until he had no balls left in his hands. It is possible that Vasya puts multiple balls to the same box, and it is also possible that one or more balls will go to the box number i. If i = n, Vasya puts the first ball into the box number 1, then the next ball goes to box 2 and so on.

    For example, let's suppose that initially Vasya had four boxes, and the first box had 3 balls, the second one had 2, the third one had 5and the fourth one had 4 balls. Then, if i = 3, then Vasya will take all five balls out of the third box and put them in the boxes with numbers: 4, 1, 2, 3, 4. After all Vasya's actions the balls will lie in the boxes as follows: in the first box there are 4 balls, 3 in the second one, 1 in the third one and 6 in the fourth one.

    At this point Vasya has completely forgotten the original arrangement of the balls in the boxes, but he knows how they are arranged now, and the number x — the number of the box, where he put the last of the taken out balls.

    He asks you to help to find the initial arrangement of the balls in the boxes.

    Input

    The first line of the input contains two integers n and x (2 ≤ n ≤ 105, 1 ≤ x ≤ n), that represent the number of the boxes and the index of the box that got the last ball from Vasya, correspondingly. The second line contains n space-separated integers a1, a2, ..., an, where integer ai (0 ≤ ai ≤ 109, ax ≠ 0) represents the number of balls in the box with index i after Vasya completes all the actions.

    Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64dspecifier.

    Output

    Print n integers, where the i-th one represents the number of balls in the box number i before Vasya starts acting. Separate the numbers in the output by spaces. If there are multiple correct solutions, you are allowed to print any of them.

    Examples
    input
    4 4
    4 3 1 6
    output
    3 2 5 4 
    input
    5 2
    3 2 0 2 7
    output
    2 1 4 1 6 
    input
    3 3
    2 3 1
    output
    1 2 3 
    题意:n个盒子,取其中一个盒子i,把i的球全拿出来,从i+1开始循环给后面一个盒子一个球,直到给完为止;
       给你给完后的序列和最后一个球放的位置;
    思路:取最小值为i即可;
    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define pi (4*atan(1.0))
    #define eps 1e-14
    const int N=2e5+10,M=1e6+10,inf=1e9+10,MOD=2009;
    const ll INF=1e18+10;
    ll a[N];
    int main()
    {
        int n,x;
        scanf("%d%d",&n,&x);
        ll minn=inf;
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&a[i]);
            minn=min(minn,a[i]);
        }
        ll sum=0;
        while(a[x]!=minn)
        {
            sum++;
            a[x]--;
            x--;
            if(x==0)
                x=n;
        }
        for(int i=1;i<=n;i++)
        if(i==x)
        printf("%lld
    ",a[i]+sum+(n-1)*minn);
        else
        printf("%lld
    ",a[i]-minn);
        return 0;
    }
  • 相关阅读:
    用于图片处理的10个超级jQuery插件
    [VS2010].NET4.0环境下使用.NET2.0程序集,出现“混合模式程序集异常”
    对企业虚拟化应用的一些感受[原创]
    留学生不回国:中国物价超美国 没车没房没尊严!
    Research Assembly Setting!
    [转] 微软的软件测试方法(附读后感)
    应用 ZedGraph
    [转] LOGIGEAR SECURITY POLICIES
    一道程序运行结果题
    VS05 与 VS08并存时编译出现 The binding handle is invalid.
  • 原文地址:https://www.cnblogs.com/jhz033/p/6029446.html
Copyright © 2020-2023  润新知