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. C#使用StreamWriter类写入文件文件

    除了使用FileStream类读写文本文件,.net还提供了StreamWriter类和StreamReader类专门处理文本文件.这两个类从底层封装了文件流,读写时不用重新编码,提供了更文件的读写方 ...

  2. 机器学习算法实践:决策树 (Decision Tree)(转载)

    前言 最近打算系统学习下机器学习的基础算法,避免眼高手低,决定把常用的机器学习基础算法都实现一遍以便加深印象.本文为这系列博客的第一篇,关于决策树(Decision Tree)的算法实现,文中我将对决 ...

  3. 【Docker】Docker管理平台 Rancher ---- 你应该学学Rancher是怎么做容器的管理的

    Elasticsearch is a Lucene-based search engine developed by the open-source vendor, elastic. With pri ...

  4. DevExpress控件之popupMenu

    一.首次创建 1.可直接从工具栏拉一个PopupMenu出来, 2.右键Customize,Yes(提示是否自动创建BarManager,并为popupmenu绑定这个BarManager): 3.编 ...

  5. http header 具体解释

    HTTP(HyperTextTransferProtocol)即超文本传输协议,眼下网页传输的的通用协议. HTTP协议採用了请求/响应模型,浏览器或其它client发出请求,server给与响应. ...

  6. MySQL5.7 基于二进制包的安装

    1.MySQL5.7安装注意事项 1.在MySQL5.7中mysql_install_db已经不再推荐使用,建议改成mysqld-initialize 完成实力初始化.(mysql_install_d ...

  7. WCF 404.3 MIME 映射错误

    WCF部署在IIS下,报错如下: HTTP 错误 404.3 - Not Found由于扩展配置问题而无法提供您请求的页面.如果该页面是脚本,请添加处理程序.如果应下载文件,请添加 MIME 映射. ...

  8. Intent之对象传递(Parcelable传递对象和对象集合)

    接着上一篇文章,以下我们讨论一下怎样利用Parcelable实现Intent之间对象的传递 一.实现对象传递 首先创建User.java实现Parcelable接口: package org.yayu ...

  9. 了解MVC框架开发

    版权声明:本文为博主原创文章,未经博主允许不得转载. 前言:本篇文章我们浅谈下MVC各个部分,模型(model)-视图(view)-控制器(controller), 以及路由. 对于使用MVC的好处大 ...

  10. 进程的基本属性:进程ID、父进程ID、进程组ID、会话和控制终端

    摘要:本文主要介绍进程的基本属性,基本属性包含:进程ID.父进程ID.进程组ID.会话和控制终端. 进程基本属性 1.进程ID(PID) 函数定义:      #include <sys/typ ...