codeforces Gravity Flip 题解
版权声明:本文作者靖心,靖空间地址: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!
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 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.
- 4
- 3 2 1 2
- 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 题解的更多相关文章
- Codeforces Round #556 题解
Codeforces Round #556 题解 Div.2 A Stock Arbitraging 傻逼题 Div.2 B Tiling Challenge 傻逼题 Div.1 A Prefix S ...
- Codeforces Round #569 题解
Codeforces Round #569 题解 CF1179A Valeriy and Deque 有一个双端队列,每次取队首两个值,将较小值移动到队尾,较大值位置不变.多组询问求第\(m\)次操作 ...
- Codeforces Round #557 题解【更完了】
Codeforces Round #557 题解 掉分快乐 CF1161A Hide and Seek Alice和Bob在玩捉♂迷♂藏,有\(n\)个格子,Bob会检查\(k\)次,第\(i\)次检 ...
- CFEducational Codeforces Round 66题解报告
CFEducational Codeforces Round 66题解报告 感觉丧失了唯一一次能在CF上超过wqy的机会QAQ A 不管 B 不能直接累计乘法打\(tag\),要直接跳 C 考虑二分第 ...
- Codeforces 238 div2 A. Gravity Flip
题目链接:http://codeforces.com/contest/405/problem/A 解题报告:有n列箱子竖直放置,每列箱子上都有数量不等的箱子,这些箱子之间没有固定,当重力方向改为平行向 ...
- codeforces CF475 ABC 题解
Bayan 2015 Contest Warm Up http://codeforces.com/contest/475 A - Bayan Bus B - Strongly Connected Ci ...
- Codeforces Round #542 题解
Codeforces Round #542 abstract I决策中的独立性, II联通块染色板子 IIIVoronoi diagram O(N^2 logN) VI环上距离分类讨论加取模,最值中的 ...
- Codeforces Choosing Laptop 题解
这题实在是太水了,具体看注释 蒟蒻的方法是一边找过时的电脑一边比大小 蒟蒻不才,只会C++ 其实还会free basic,但它已经过时了 附: 本题洛谷网址 Codeforces网址 希望蒟蒻的题解能 ...
- Codeforces 381 简要题解
做的太糟糕了...第一题看成两人都取最优策略,写了个n^2的dp,还好pre-test良心(感觉TC和CF的pretest还是很靠谱的),让我反复过不去,仔细看题原来是取两边最大的啊!!!前30分钟就 ...
随机推荐
- XQuery获取节点的属性名与值
e.g: DECLARE @xmlSource XML SET @xmlSource = '<t topA="1"> <a x="2" z=& ...
- 拒绝IP登陆
tail -n 30 /var/log/messages 发现很多IP尝试登陆,直接封禁. 解决方案:1. vi /etc/hosts.allow 添加 sshd:143.63.182.238 [注意 ...
- 【Datasatge】使用Datastage装载数据时候,报错:Missing record delimiter “”,saw EOF instead
如题,报错截图如下: 根据以上警告信息我们可以清晰看出,是字段DEFAULT_FLAG出错了!于是我们找到对应的字段,结果一看,导出文件中DS表结构中该字段为DECIMAL(18,2),但是导出文件中 ...
- xcode 项目证书跟签名都正确的时候,还报证书错误
原因,安装证书错误,导致无法匹配证书, 方案:删除原来的证书,重新安装 打开终端 1.cd Library/ 2.cd MobileDevice/ 3.open Provisioning\ Profi ...
- HTTP图解--了解Web及网络基础
1.网络基础TCP/IP 通常使用的网络是在TCP/IP协议族的基础上运行的,http属于它内部的一个子集. TCP/IP协议族按层次分别分为:应用层.传输层.网络层和数据链路层.分层的好处在于各司其 ...
- nightwatch-js -- test group
Test group 可以将你的测试脚本划分到组中,并根据需要运行它们.要将测试组合在一起,只需将它们放在相同的子文件夹中,文件夹的名字即是组的名字.例如:lib/├── selenium-serve ...
- Redis 的学习和使用
安装Redis 官方网站:http://redis.io/ 官方下载:http://redis.io/download 可以根据需要下载不同版本 windows版:https://github.com ...
- 利用$(window).resize()实现窗口大小自适应宽度问题
© 版权声明:本文为博主原创文章,转载请注明出处 问题描述:利用iframe做页面引入,用$(window).resize()作自适应:结果窗口变小时,利用$(window).width()获取到的宽 ...
- Spring Boot从入门到实战:整合通用Mapper简化单表操作
数据库访问是web应用必不可少的部分.现今最常用的数据库ORM框架有Hibernate与Mybatis,Hibernate貌似在传统IT企业用的较多,而Mybatis则在互联网企业应用较多.通用Map ...
- 如何在Windows 10 IoT Core中添加其他语言的支持,如中文
目前很多开发者已经开始使用Windows 10 IoT来做物联网领域的开发了,目前Windows 10 IoT Core的版本支持树莓派2(以及新出的树莓派3).Minnowboard Max以及Dr ...