版权声明:本文作者靖心,靖空间地址: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. web.py

    #-*- coding:utf-8 -*- import web import json import requests #from web.contrib.template import rende ...

  2. Java 二分法查找

    算法:当数据量很大适宜采用该方法.采用二分法查找时,数据需是有序不重复的. 基本思想:假设数据是按升序排序的,对于给定值 x,从序列的中间位置开始比较,如果当前位置值等于 x,则查找成功:若 x 小于 ...

  3. 关于八数码问题中的状态判重的三种解决方法(编码、hash、&lt;set&gt;)

    八数码问题搜索有非常多高效方法:如A*算法.双向广搜等 但在搜索过程中都会遇到同一个问题.那就是判重操作(假设反复就剪枝),怎样高效的判重是8数码问题中效率的关键 以下关于几种判重方法进行比較:编码. ...

  4. 【BIEE】09_BIEE控制台乱码问题解决

    BIEE安装完成后,点击[启动BI服务] 接着从弹出窗口可以发现,全部汉字都是乱码 出现这种情况,想看一下BIEE启动情况是很费劲的,接着我们处理一下这个问题 1.从路径D:\obiee\user_p ...

  5. BF的真正意义

    http://www.jianglb.com/2010/11/25/whatisbf.html一个小男孩对小女孩说:“我是你的BF.”女孩扬起童真的脸,问:“什么是BF?”男孩嘻嘻笑道:“是BestF ...

  6. 跨discuz站获取

    1.在需要取得formhash的页面加入下面js代码,还需要jquery库. <script lanuage="javascript"> $(function(){ $ ...

  7. NHibernate 映射基础(第三篇) 简单映射、联合主键

    NHibernate 映射基础(第三篇) 简单映射.联合主键 NHibernate完全靠配置文件获取其所需的一切信息,其中映射文件,是其获取数据库与C#程序关系的所有信息来源. 一.简单映射 下面先来 ...

  8. MapReduce源码分析之新API作业提交(二):连接集群

    MapReduce作业提交时连接集群是通过Job的connect()方法实现的,它实际上是构造集群Cluster实例cluster,代码如下: private synchronized void co ...

  9. 调用bat文件执行java文件

    set path=./jre7/bin--设置jre路径,可以写jre的全路径java -cp "lib/*;" -Xms256m -Xmx512m com.shentong.Ma ...

  10. k8s集群部署

    环境: 两台虚拟机, 10.10.20.203 部署docker.etcd.flannel.kube-apiserver.kube-controller-manager.kube-scheduler ...