Virtual Judge Contest 1-F

F - Gaby Ivanushka
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

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 programThe 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.

Sample Input

input output
3
3 7 19

Sample Output

3 7 19
 
     
Solution:这道题太有趣了,说了这么多,说到底是想女儿快嫁出去呀。既然如此,无论我输入什么,
结果都应该是Beutiful Vasilisa,他老爸想得太周到了,那我就不客气啦。
输入为n,输出任意的n个正整数就可以过关了
基于python实现的粒子群的VRP(车辆配送路径规划)问题建模求解+源码+项目文档+算法解析,适合毕业设计、课程设计、项目开发。项目源码已经过严格测试,可以放心参考并在此基础上延申使用,详情见md文档 算法设计的关键在于如何向表现较好的个体学习,标准粒子群算法引入惯性因子w、自我认知因子c1、社会认知因子c2分别作为自身、当代最优解和历史最优解的权重,指导粒子速度和位置的更新,这在求解函数极值问题时比较容易实现,而在VRP问题上,速度位置的更新则难以直接采用加权的方式进行,一个常见的方法是采用基于遗传算法交叉算子的混合型粒子群算法进行求解,这里采用顺序交叉算子,对惯性因子w、自我认知因子c1、社会认知因子c2则以w/(w+c1+c2),c1/(w+c1+c2),c2/(w+c1+c2)的概率接受粒子本身、当前最优解、全局最优解交叉的父代之一(即按概率选择其中一个作为父代,不加权)。 算法设计的关键在于如何向表现较好的个体学习,标准粒子群算法引入惯性因子w、自我认知因子c1、社会认知因子c2分别作为自身、当代最优解和历史最优解的权重,指导粒子速度和位置的更新,这在求解函数极值问题时比较容易实现,而在VRP问题上,速度位置的更新则难以直接采用加权的方式进行,一个常见的方法是采用基于遗传算法交叉算子的混合型粒子群算法进行求解,这里采用顺序交叉算子,对惯性因子w、自我认知因子c1、社会认知因子c2则以w/(w+c1+c2),c1/(w+c1+c2),c2/(w+c1+c2)的概率接受粒子本身、当前最优解、全局最优解交叉的父代之一(即按概率选择其中一个作为父代,不加权)。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值