C - Gravity Flip
Problem description
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.
Examples
Input
4
3 2 1 2
Output
1 2 2 3
Input
3
2 3 8
Output
2 3 8
Note
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns.
解题思路:升序排列并输出,水过!
AC代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,a[];
cin>>n;
for(int i=;i<n;++i)cin>>a[i];
sort(a,a+n);
for(int i=;i<n;++i)
cout<<a[i]<<(i==n-?"\n":" ");
return ;
}
C - Gravity Flip的更多相关文章
- codeforces Gravity Flip 题解
版权声明:本文作者靖心,靖空间地址:http://blog.csdn.net/kenden23/,未经本作者同意不得转载. https://blog.csdn.net/kenden23/article ...
- Codeforces 238 div2 A. Gravity Flip
题目链接:http://codeforces.com/contest/405/problem/A 解题报告:有n列箱子竖直放置,每列箱子上都有数量不等的箱子,这些箱子之间没有固定,当重力方向改为平行向 ...
- CodeForces - 405A
Gravity Flip Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- [LeetCode] Flip Game 翻转游戏之二
You are playing the following Flip Game with your friend: Given a string that contains only these tw ...
- [LeetCode] Flip Game 翻转游戏
You are playing the following Flip Game with your friend: Given a string that contains only these tw ...
- poj Flip Game 1753 (枚举)
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 27005 Accepted: 11694 Descr ...
- POJ1753 Flip Game(bfs、枚举)
链接:http://poj.org/problem?id=1753 Flip Game Description Flip game is played on a rectangular 4x4 fie ...
- Android之layout_gravity与gravity解析
相信layout_gravity和gravity这两个属性一直困扰着很多人,很多初学者都分不清这两个属性有什么区别,以及怎样区分它们.它们中,有一个表示的是一个控件在父布局中的位置,而另一个表示的是一 ...
随机推荐
- Java中字符串的常用属性与方法
•字符串常用的属性 string.length()————>返回字符串的长度,int类型. •字符串常用的方法 String.contains(";")——————>判 ...
- Spring Boot 集成 JWT 实现单点登录授权
使用步骤如下:1. 添加Gradle依赖: dependencies { implementation 'com.auth0:java-jwt:3.3.0' implementation('org.s ...
- CVPR2016 Paper list
CVPR2016 Paper list ORAL SESSIONImage Captioning and Question Answering Monday, June 27th, 9:00AM - ...
- IE低版本和高级浏览器对文本输入事件兼容
1 一般 使用oninput 事件可以监控文本输入事实触发 2 兼容需要使用onpropertychange . 3 兼容写法 var evenInput=DOM元素.oninput || DOM ...
- TCP/IP UDP 协议首部及数据进入协议栈封装的过程
数据的封装 UDP 封装 TCP 封装 IP 封装 检验和算法 当应用程序用TCP传送数据时,数据被传送入协议栈中,然后逐一通过每一层直到被当作一串比特流送入网络 注: UDP数据TCP数据基本一致. ...
- hdu2006 求奇数的乘积【C++】
求奇数的乘积 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- SGC强制最低128位加密,公钥支持ECC加密算法的SSL证书
Pro SSL证书,验证企业域名所有权和企业身份信息,采用SGC(服务器门控)技术强制128位以上至256位加密,属于企业OV验证级专业版(Pro) SSL证书:即使用户使用低版本浏览器(比如浏览 ...
- 【郑轻邀请赛 G】密室逃脱
[题目链接]:https://acm.zzuli.edu.cn/zzuliacm/problem.php?id=2133 [题意] [题解] 考虑每一个二进制数的最高位->第i位; 肯定是1(这 ...
- JavaSE 学习笔记之String字符串(十四)
API:(Application Programming Interface,应用程序编程接口)是一些预先定义的函数,目的是提供应用程序与开发人员基于某软件或硬件的以访问一组例程的能力,而又无需访问源 ...
- 重庆OI2017 老 C 的任务
老 C 的任务 时间限制: 2 Sec 内存限制: 512 MB 题目描述 老 C 是个程序员. 最近老 C 从老板那里接到了一个任务——给城市中的手机基站写个管理系统.作为经验丰富的程序员,老 C ...