Gaby Ivanushka

Once upon a time there lived a tsar that has a daughter — Beautiful Vasilisa. There were many of the young men that wanted to marry her but she repelled all suitors. The tsar was tired of her jigs, he got angry and issued an order: "The first who solves my puzzle, will marry Vasilisa!" Ivanushka decided to try his fortune. He came to the tsar and the tsar told him: "This is a program for you. Input N numbers and the program will tell you who you should marry. I give you a day to think." Ivanuska looked at the program and got upset: there were unknown letters, omnifarious symbols. The time passed. Ivanushka has thought out nothing.
The program was as follows.
The C program The Pascal program
 #include <stdio.h>
long c;
long A[N]; long P(long l, long r)
{
long x=A[l],
i=l-1,
j=r+1,
t;
while(1)
{
do{--j; ++c;}
while(A[j]>x);
do{++i; ++c;}
while(A[i]<x);
if(i<j)
{
t=A[i];
A[i]=A[j];
A[j]=t;
}
else return j;
}
} void Q(long l, long r)
{
long n;
if(l<r)
{
n=P(l,r);
Q(l,n);
Q(n+1,r);
}
} int main(void)
{
c=0;
for(long i=0; i<N; ++i)
scanf("%ld", &A[i]);
Q(0,N-1);
if(c==(N*N+3*N-4)/2)
printf
("Beutiful Vasilisa");
else printf
("Immortal Koshcei");
return 0;
}
 var A:array [1..N] of
longint;
c:longint;
i:integer;
function
P(l,r:longint):longint;
var i,j,t,x:longint;
begin
x:=A[l]; i:=l-1; j:=r+1;
while true do
begin
repeat dec(j);inc(c)
until A[j]<=x;
repeat inc(i);inc(c)
until A[i]>=x;
if i<j then
begin
t:=A[i];
A[i]:=A[j];
A[j]:=t
end
else
begin P:=j; exit end
end
end; procedure Q(l,r:longint);
var n:longint;
begin
if l<r then
begin
n:=P(l,r);
Q(l,n);
Q(n+1,r)
end
end; begin
c:=0;
for i:=1 to N do
read(A[i]);
Q(1,N);
if c=(N*N+3*N-4) div 2
then
writeln
('Beutiful Vasilisa')
else writeln
('Immortal Koshcei');
end.
Now you know this program. You may try to help Ivanushka.

Input

The first line of an input contains a positive number N ≤ 1000.

Output

You are to write to an output N numbers in one line. The tsar's program given those numbers should output a message "Beautiful Vasilisa" The numbers should be separated with a space. If several variants are possible choose any you like.

Example

input output
3
3 7 19

//代码就是快排。

输出一个等差数列即可

  #include <stdio.h>
int main()
{
int n;
while (scanf("%d",&n)!=EOF)
{
int i;
for (i=;i<n;i++)
printf("%d ",i);
printf("%d\n",i);
}
}

Gaby Ivanushka(快排)的更多相关文章

  1. F#之旅4 - 小实践之快排

    参考文章:https://swlaschin.gitbooks.io/fsharpforfunandprofit/content/posts/fvsc-quicksort.html F#之旅4 - 小 ...

  2. 快排 快速排序 qsort quicksort C语言

    现在网上搜到的快排和我以前打的不太一样,感觉有点复杂,我用的快排是FreePascal里/demo/text/qsort.pp的风格,感觉特别简洁. #include<stdio.h> # ...

  3. iOS常见算法(二分法 冒泡 选择 快排)

    二分法: 平均时间复杂度:O(log2n) int halfFuntion(int a[], int length, int number)  { int start = 0; int end = l ...

  4. C++ 快排

    // 进行一轮快排并返回当前的中间数 int getMiddle( int* arr, int low, int high ) { auto swaparr = [&]( int i, int ...

  5. 先贴上代码:Random快排,快排的非递归实现

    设要排序的数组是A[0]……A[N-1],首先任意选取一个数据(通常选用数组的第一个数)作为主元,然后将所有比它小的数都放到它前面,所有比它大的数都放到它后面,这个过程称为一趟快速排序.值得注意的是, ...

  6. Java常见的几种排序算法-插入、选择、冒泡、快排、堆排等

    本文就是介绍一些常见的排序算法.排序是一个非常常见的应用场景,很多时候,我们需要根据自己需要排序的数据类型,来自定义排序算法,但是,在这里,我们只介绍这些基础排序算法,包括:插入排序.选择排序.冒泡排 ...

  7. ACM/ICPC 之 快排+归并排序-记录顺序对(TSH OJ-LightHouse(灯塔))

    TsingHua OJ 上不能使用<algorithm>头文件,因此需要手写快排(刚开始写的时候自己就出了很多问题....),另外本题需要在给横坐标排序后,需要记录纵坐标的顺序对的数量,因 ...

  8. 数组第K小数问题 及其对于 快排和堆排 的相关优化比较

    题目描述 给定一个整数数组a[0,...,n-1],求数组中第k小数 输入描述 首先输入数组长度n和k,其中1<=n<=5000, 1<=k<=n 然后输出n个整形元素,每个数 ...

  9. 结构体快排回顾(sort)

    一般来说,我做竞赛的时候排序一般用快排 很快很方便 普通sort(从小到大) sort(a,a+n); 直接贴一段代码吧,包含了vector,sort,结构体等简单东西综合 #include < ...

随机推荐

  1. crossapp的屏幕适配

    1.分辨率是的某个尺寸大小的屏幕里的像素点数ppi 2.crossapp茶用iphone4为基准比例值为1 3.其它分辨率设备的换算dp = px * 320/ 屏幕PPI 4.crossapp里点. ...

  2. display:inline-block;在各浏览器下的问题和终极兼容办法

    display:inline-block;在各浏览器下的问题和终极兼容办法 一.IE 5.5.6.7 .8(Q)中display:inline-block;失效 兼容办法: IE 5.5.6.7 .8 ...

  3. redhat mount iso as one yum repository

    prepare redhat DVD iso rhel-server-6.4-x86_64-dvd.iso mount cd / mkdir /mnt/rhel mount -o loop rhel- ...

  4. 2017.6.30 安装IDEA的插件mybatis plugin(破解版)

    参考来自:http://blog.csdn.net/u011410529/article/details/54098067 正常情况下的安装: 但是我的界面中找不到这个插件,而且这个插件是收费的. 1 ...

  5. 转: NetBean 远程开发的好文2 --> 工欲善其事,必先利其器系列--Netbeans之远程开发

    转自:  http://www.cnblogs.com/zuoca/archive/2012/07/09/Remote_Development_With_Netbeans_origin.html 实践 ...

  6. JAVA Eclipse如何设置点击按钮切换图片

    右击图片文件夹,新建一个Android XML文件   设置文件的名称,注意这个新建的xml文件就是会被用作按钮的background属性的,所以名字不要太奇怪,设置Root Element为sele ...

  7. Win7删除虚拟机新建的用户怎么恢复

    11月3日 VMware Workstation 7 Installed in Windows 7 AutoLogon Problem 安装VMware Workstation 7 在Windows ...

  8. 从程序员到asp.net架构师转变[转]

    微软的DotNet开发绝对是属于那种入门容易提高难的技术.而要能够成为DotNet架构师没有三年或更长时间的编码积累基本上是不可能的.特别是在大型软件项目中,架构师是项目核心成员,承上启下,因此 RU ...

  9. redhat 用yum安装的apache、mysql一般默认安装在哪个目录下?

    使用yum安装成功后,使用rpm -qa | grep httpd和rpm -qa | grep mysql查看是否安装成功然后使用rpm -ql httpd和rpm -ql mysql查看安装文件都 ...

  10. rk3288 LED上加入heartbeat功能

    平台:瑞芯的rk3288 作者:fulinux *****本文同意转载.只是请注明出处:http://blog.csdn.net/fulinus**** 1.硬件环境 随意选取一个GPIO引脚作为he ...