260C - Balls and Boxes

思路:模拟。在x前面找到最小值,如果没有,从0跳到n,继续找到最小值,边找最小值路过的点边减1。然后所有值都减去最小值,最小值那个点加上减去的值。

找到x前面离x最近的最小值的原因:如果如果在x到最小值之间还有最小值,那么这个最小值最后会变成-1。

简单代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+;
const ll INF=0x7f7f7f7f;
ll a[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie();
ll n,x,minn=INF;
cin>>n>>x;
for(int i=;i<=n;i++)cin>>a[i];
for(int i=;i<=n;i++)
{
minn=min(minn,a[i]);
}
ll sum=;
while(a[x]!=minn)
{
a[x]--;
sum++;
x--;
if(x==)x=n;
}
for(int i=;i<=n;i++)
{
if(i!=x)cout<<a[i]-minn;
else cout<<a[i]+sum+(n-)*minn;
if(i!=n)cout<<' ';
else cout<<endl;
}
return ;
}

复杂点的代码(找最小值时没有减1):

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+;
const ll INF=0x7f7f7f7f;
ll a[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie();
ll n,x,minn=INF,d=INF,index=-;
cin>>n>>x;
for(int i=;i<=n;i++)cin>>a[i];
for(int i=;i<=n;i++)
{
if(a[i]<=minn)
{
minn=a[i];
index=i;
}
}
bool flag=true;
for(int i=x;i>=;i--)
{
if(a[i]==minn)
{
index=i;
flag=false;
break;
}
}
if(flag)for(int i=n;i>x;i--)
{
if(a[i]==minn)
{
index=i;
break;
}
}
ll cnt=;
if(index<x)
{
cnt=index*minn+(n-x)*minn+(x-index)*(minn+);
for(int i=;i<=index;i++)a[i]-=minn;
for(int i=index+;i<=x;i++)a[i]-=minn+;
for(int i=x+;i<=n;i++)a[i]-=minn;
a[index]+=cnt;
}
else if(index>x)
{
cnt=x*(minn+)+(n-index)*(minn+)+(index-x)*minn;
for(int i=;i<=x;i++)a[i]-=minn+;
for(int i=x+;i<=index;i++)a[i]-=minn;
for(int i=index+;i<=n;i++)a[i]-=minn+;
a[index]+=cnt;
}
else
{
cnt=n*minn;
for(int i=;i<=n;i++)a[i]-=minn;
a[index]+=cnt;
}
for(int i=;i<n;i++)cout<<a[i]<<' ';
cout<<a[n]<<endl;
return ;
}

Codeforces 260C - Balls and Boxes的更多相关文章

  1. 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 i ...

  2. CodeForces - 260C

    CodeForces - 260C Little Vasya had n boxes with balls in the room. The boxes stood in a row and were ...

  3. HDU 5810 Balls and Boxes(盒子与球)

     Balls and Boxes(盒子与球) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  4. HDU 5810 Balls and Boxes (找规律)

    Balls and Boxes 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...

  5. HDU5810 Balls and Boxes

    Balls and Boxes                                                                            Time Limi ...

  6. HDU 5810 Balls and Boxes 数学

    Balls and Boxes 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...

  7. hdu-5810 Balls and Boxes(概率期望)

    题目链接: Balls and Boxes Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/O ...

  8. hdu 5810 Balls and Boxes 二项分布

    Balls and Boxes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  9. 2016 多校联赛7 Balls and Boxes(概率期望)

    Mr. Chopsticks is interested in random phenomena, and he conducts an experiment to study randomness. ...

随机推荐

  1. 将Pytorch模型从CPU转换成GPU

    1. 如何进行迁移 对模型和相应的数据进行.cuda()处理.通过这种方式,我们就可以将内存中的数据复制到GPU的显存中去.从而可以通过GPU来进行运算了. 1.1 判定使用GPU 下载了对应的GPU ...

  2. zw版【转发·台湾nvp系列Delphi例程】HALCON MirrorImage2

    zw版[转发·台湾nvp系列Delphi例程]HALCON MirrorImage2 procedure TForm1.Button1Click(Sender: TObject);var op: HO ...

  3. python 命令执行文件传递参数

    import os,sys for root,dirs,files in os.walk(sys.argv[1]): for name in files: print(os.path.join(roo ...

  4. 查看firefox浏览器 驱动geckodriver.exe文件的版本号的方法,以及下载链接

    1-进入到geckodriver.exe文件的目录: 2-在路径栏下输入cmd: 3-命令行界面下输入:geckodriver.exe -h 可以看到文件的帮助信息,其中第一行就列出了版本号 为0.1 ...

  5. 最新 mysql登录报错“Access denied for user 'root'@'localhost' (using password: NO”的处理方法

    1.关闭正在运行的MySQL.2.打开DOS窗口,转到mysql\bin目录.3.输入mysqld --skip-grant-tables回车.如果没有出现提示信息,那就对了.(正常的情况是光标闪烁没 ...

  6. STM32硬件IIC

    /** * @brief 写一个字节到I2C设备中 * @param * @arg pBuffer:缓冲区指针 * @arg WriteAddr:写地址 * @retval 正常返回1,异常返回0 * ...

  7. Eclipse启动Tomcat时,45秒超时解决方式

    Eclipse启动Tomcat时,45秒超时解决方式 在Eclipse中启动Tomcat服务器时,经常由于系统初始化项目多,导致出现45秒超时的Tomcat服务器启动错误.  一般通过找到XML配置文 ...

  8. assert_param

    在STM32的固件库和提供的例程中,到处都可以见到assert_param()的使用.如果打开任何一个例程中的stm32f10x_conf.h文件,就可以看到实际上assert_param是一个宏定义 ...

  9. Pycharm 2017 激活码

    Pycharm 2017 激活码 server选项里边输入:  http://idea.liyang.io 我是通过这个成功的

  10. Ruby基础教程

    一.Ruby基础知识 1.关于Ruby Ruby是脚本语言 Ruby是面向对象语言 Ruby是跨平台语言 Ruby是开放源码软件 2.Ruby入门书籍推荐 <Ruby.Programming向R ...