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. liferay中如何获取实例的id和portletId

    在Portlet中request分为两种renderRequet和actionRequest而portlet需要取得实例Id的时候都在renderRequest的时候才可以取到,如下例子 Portle ...

  2. javascript利用jquery-1.7.1来判断是否是谷歌Chrome浏览器

    <!DOCTYPE html> <html> <head>     <meta http-equiv="Content-Type" con ...

  3. X-UA-Compatible

    X-UA-Compatible是神马? X-UA-Compatible是IE8的一个专有<meta>属性,它告诉IE8采用何种IE版本去渲染网页,在html的<head>标签中 ...

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

    zw版[转发·台湾nvp系列Delphi例程]HALCON AngleLl procedure TForm1.Button1Click(Sender: TObject);var Row1, Row2 ...

  5. 【转】Linux进程绑CPU核

    1. 什么是绑核? 所谓绑核,其实就是设定某个进程/线程与某个CPU核的亲和力(affinity).设定以后,Linux调度器就会让这个进程/线程只在所绑定的核上面去运行.但并不是说该进程/线程就独占 ...

  6. EditPlus 4.3.2502 中文版已经发布(12月5日更新)

    新的版本修复了在之前某版本中键盘 End 键定位位置错误的问题.

  7. Linux基础命令---mknod

    mknod 创建块设备或者字符设备文件.此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE.Fedora.   1.语法       mknod [选项] ...

  8. spring中对象转json过滤(jackson)

    spring自带的json解析器是jackson jackson注解 @JsonIgnore 此注解用于属性上,作用是进行JSON操作时忽略该属性. @JsonFormat 此注解用于属性上,作用是把 ...

  9. Unity3D关于VR的Demo(一)

    https://blog.csdn.net/qq_15807167/article/details/52048998?locationNum=8&fps=1 阅读数:9716 最近有点忙,只有 ...

  10. SNMP学习笔记之SNMP介绍,OID及MIB库

    1.1.    SNMP概览 SNMP的基本知识介绍简单网络管理协议(SNMP-Simple Network Management Protocol)是一个与网络设备交互的简单方法.该规范是由IETF ...