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. 最新IP地址数据库Dat格式-高性能高并发版(2019年3月)

    最新IP地址数据库->Dat  二进制文件 高性能高并发-qqzeng-ip.dat 格式 全球IP数据库-20190301-Dat 版                国内IP数据库-20190 ...

  2. ElasticSearch 安装中文分词器

    1.安装中文分词器IK 下载地址:https://github.com/medcl/elasticsearch-analysis-ik 在线下载安装: elasticsearch-plugin.bat ...

  3. oracle find blocking session

    show current session id     select sid from v$mystat where rownum=1; show blocking session     selec ...

  4. spring 配置多数据源 (可行)

    可以看到AbstractRoutingDataSource获取数据源之前会先调用determineCurrentLookupKey方法查找当前的lookupKey,这个lookupKey就是数据源标识 ...

  5. ubuntu apt-get install xxx时一直报错E: Unable to locate package xxxxxxx

    $ sudo add-apt-repository main $ sudo add-apt-repository universe $ sudo add-apt-repository restrict ...

  6. node - 上传文件并且修改名称

    html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

  7. Recycling Settings for an Application Pool <recycling>

    Overview The <recycling> element contains configuration settings that control the conditions t ...

  8. react-native 项目实战 -- 新闻客户端(4) -- 请求网络数据

    1.Home.js /** * 首页 */ import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Te ...

  9. JavaScript 数组去重 方法汇总

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  10. IP数据库生成器

    代码地址如下:http://www.demodashi.com/demo/12688.html 项目放在github上,python版本ipdb_creator,java版本ip-locator. 项 ...