版权声明:本文作者靖心,靖空间地址:http://blog.csdn.net/kenden23/,未经本作者同意不得转载。

https://blog.csdn.net/kenden23/article/details/24832151

Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.

There are n columns of toy cubes in the box arranged in a line. The i-th
column contains ai cubes.
At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have
changed their position are highlighted with orange.

Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the n columns after the gravity switch!

Input

The first line of input contains an integer n (1 ≤ n ≤ 100),
the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th
number ai (1 ≤ ai ≤ 100)
denotes the number of cubes in the i-th column.

Output

Output n integer numbers separated by spaces, where the i-th
number is the amount of cubes in the i-th column after the gravity switch.

Sample test(s)
input
4
3 2 1 2
output
1 2 2 3 

非常有趣,非常有新意的题目。

原来能够这么改变gravity,形成这种效果的。有意思。

只是题解却是非常容易的,就是一个排序问题。O(∩_∩)O~。可是没看到这种题目还真没想过。

void GravityFlip()
{
unsigned n;
cin>>n;
int *A = new int[n]; for (unsigned i = 0; i < n; i++)
{
cin>>A[i];
} sort(A, A+n);
for (unsigned i = 0; i < n; i++)
{
cout<<A[i]<<' ';
} delete [] A;
}

codeforces Gravity Flip 题解的更多相关文章

  1. Codeforces Round #556 题解

    Codeforces Round #556 题解 Div.2 A Stock Arbitraging 傻逼题 Div.2 B Tiling Challenge 傻逼题 Div.1 A Prefix S ...

  2. Codeforces Round #569 题解

    Codeforces Round #569 题解 CF1179A Valeriy and Deque 有一个双端队列,每次取队首两个值,将较小值移动到队尾,较大值位置不变.多组询问求第\(m\)次操作 ...

  3. Codeforces Round #557 题解【更完了】

    Codeforces Round #557 题解 掉分快乐 CF1161A Hide and Seek Alice和Bob在玩捉♂迷♂藏,有\(n\)个格子,Bob会检查\(k\)次,第\(i\)次检 ...

  4. CFEducational Codeforces Round 66题解报告

    CFEducational Codeforces Round 66题解报告 感觉丧失了唯一一次能在CF上超过wqy的机会QAQ A 不管 B 不能直接累计乘法打\(tag\),要直接跳 C 考虑二分第 ...

  5. Codeforces 238 div2 A. Gravity Flip

    题目链接:http://codeforces.com/contest/405/problem/A 解题报告:有n列箱子竖直放置,每列箱子上都有数量不等的箱子,这些箱子之间没有固定,当重力方向改为平行向 ...

  6. codeforces CF475 ABC 题解

    Bayan 2015 Contest Warm Up http://codeforces.com/contest/475 A - Bayan Bus B - Strongly Connected Ci ...

  7. Codeforces Round #542 题解

    Codeforces Round #542 abstract I决策中的独立性, II联通块染色板子 IIIVoronoi diagram O(N^2 logN) VI环上距离分类讨论加取模,最值中的 ...

  8. Codeforces Choosing Laptop 题解

    这题实在是太水了,具体看注释 蒟蒻的方法是一边找过时的电脑一边比大小 蒟蒻不才,只会C++ 其实还会free basic,但它已经过时了 附: 本题洛谷网址 Codeforces网址 希望蒟蒻的题解能 ...

  9. Codeforces 381 简要题解

    做的太糟糕了...第一题看成两人都取最优策略,写了个n^2的dp,还好pre-test良心(感觉TC和CF的pretest还是很靠谱的),让我反复过不去,仔细看题原来是取两边最大的啊!!!前30分钟就 ...

随机推荐

  1. vector list map 遍历删除指定元素

    #include <stdio.h> #include <stdint.h> #include <vector> #include <list> #in ...

  2. Vector的一种实现(一)

    注意几点: 分配内存不要使用new和delete,因为new的同时就把对象构造了,而我们需要的是原始内存. 所以应该使用标准库提供的allocator类来实现内存的控制.当然也可以重载operator ...

  3. 在PreferenceAcitity中使用Fragement时避免额外的Left和RightPadding

    On Android 4.4 遇到过这种问题: 注意到.上面的ActionBar部分的左右各有48像素的padding. 要了解该问题的成因,要首先了解其结构: 该页面的Activity是一个Pref ...

  4. 如何去掉MapReduce输出的默认分隔符

    我们在用MapReduce做数据处理的时候,经常会遇到将只需要输出键或者值的情况,如context.write(new Text(record), new Text("")),这样 ...

  5. 模拟和数字低通滤波器的MATLAB实现

    低通滤波器参数:Fs=8000,fp=2500,fs=3500,Rp=1dB,As=30dB,其他滤波器可以通过与低通之间的映射关系实现. %%模拟滤波器 %巴特沃斯——滤波器设计 wp=2*pi*2 ...

  6. C#中使用泛型对照使用通用基础类型效率减少近一倍

     C#中使用泛型对照使用通用基础类型效率减少近一倍 以下是測试结果: CSharp class and generic TotalMilliseconds: 270772.9229CSharp g ...

  7. oracle查询当前会话数量

    SELECT a.inst_id,sid,username,event,sql_id,a.PROGRAM FROM gv$session a WHERE a.STATUS='ACTIVE' AND u ...

  8. Linux中终端和控制台区别

    Linux中终端和控制台区别: 终端:英文名叫terminal 控制台:英文名叫console 两者区别要从以前的多人使用的计算机开始 以前,由于计算机很昂贵,所用一台计算机一般由多个人同时使用.这样 ...

  9. 使用Application Loader上传APP流程解读[APP公布]

    本文仅仅是提供一个公布流程的总体思路.假设没有公布经验.建议阅读苹果官方公布文档或者Google搜索具体教程. 1.申请开发人员账号:99美金的(须要信用卡支付),详细流程网上有非常多样例.自行搜索. ...

  10. mac 编译ffmpeg真简单!

    brew info ffmpeg 有安装选项,并且会提示依赖库安装状态 安装依赖库 brew install automake fdk-aac git lame libass libtool libv ...