uva 110 Meta-Loopless Sorts

从零开始安装pytorch(包含GPU和CPU版本的安装) Pytorch是。 阅读详情

题目地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=46



题目描述:

 Meta-Loopless Sorts 

Background 

Sorting holds an important place in computer science. Analyzing and implementing various sorting algorithms forms an important part of the education of most computer scientists, and sorting accounts for a significant percentage of the world's computational resources. Sorting algorithms range from the bewilderingly popular Bubble sort, to Quicksort, to parallel sorting algorithms and sorting networks. In this problem you will be writing a program that creates a sorting program (a meta-sorter).

The Problem 

The problem is to create several programs whose output is a standard Pascal program that sorts  n  numbers where  n  is the only input to the program you will write. The Pascal programs generated by your program must have the following properties:

  • They must begin with program sort(input,output);

  • They must declare storage for exactly n integer variables. The names of the variables must come from the first n letters of the alphabet (a,b,c,d,e,f).

  • A single readln statement must read in values for all the integer variables.

  • Other than writeln statements, the only statements in the program are if then else statements. The boolean conditional for each if statement must consist of one strict inequality (either < or >) of two integer variables. Exactly n! writeln statements must appear in the program.

  • Exactly three semi-colons must appear in the programs
    1. after the program header: program sort(input,output);

    2. after the variable declaration: ...: integer;

    3. after the readln statement: readln(...);

  • No redundant comparisons of integer variables should be made. For example, during program execution, once it is determined that a < b, variables a and b should not be compared again.

  • Every writeln statement must appear on a line by itself.

  • The programs must compile. Executing the program with input consisting of any arrangement of any ndistinct integer values should result in the input values being printed in sorted order.

For those unfamiliar with Pascal syntax, the example at the end of this problem completely defines the small subset of Pascal needed.

The Input 

The input consist on a number in the first line indicating the number M of programs to make, followed by a blank line. Then there are M test cases, each one consisting on a single integer  n  on a line by itself with 1 $ \leq$ n $ \leq$ 8 . There will be a blank line between test cases.

The Output 

The output is M compilable standard Pascal programs meeting the criteria specified above. Print a blank line between two consecutive programs.

Sample Input 

1

3

Sample Output 

program sort(input,output);
var
a,b,c : integer;
begin
  readln(a,b,c);
  if a < b then
    if b < c then
      writeln(a,b,c)
    else if a < c then
      writeln(a,c,b)
    else
      writeln(c,a,b)
  else
    if a < c then
      writeln(b,a,c)
    else if b < c then
      writeln(b,c,a)
    else
      writeln(c,b,a)
end.



题意:写一个如上述 输出形式的排序程序,并且这里面还包含了 排序的结果。


题解:一开始想到用打表  毕竟只有8个字母要排序,后来想想不用打表 也可以很简单地搞出来。

我是用插空的思想来做的: 考虑只有1个字母 a  那么  用字母a去 插空 一个空集  及只有1个空可以插 那么  答案是 a

考虑有 2个字母 a,b  那么 a只有 一种插法  在递归到b  用b去插剩余的集合(只有a),那么有两个空可以插 (_a_)那么  答案是 ab ,ba

考虑三个字母 a,b,c  这里 由于前面已经讨论好a和b的插法了  直接看c 的插空  就是 (_a_b_)和 (_b_a_)  这样可以得到6个答案。

。。。。。。后面以此类推

如何将刚才的分析对应于程序的书写呢, 在此用3个字母的做样例说明:

首选考虑a的插法 程序中是没有体现的  那么直接考虑 b的插空  程序中的体现是 if a < b then  和  对应的 else  而这两条语句分别对应的是b插在a后面  和 b插在a前面 两个动作

然后 看下一级的c  以此类推 内推 分别是 c插 最后面 , c插 中间   和 c插在最前面。

以上:

按照这样的插空规律可以写出一个递归的程序。


代码:

/*

topcoder codeforce acm

*/
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;

int T=0,N=0;

char ch[10]={'a','a','b','c','d','e','f','g','h','i'};
vector<int> List;

/*print the 2*n  ' '*/
int PrintIndent(int n)
{
	int m=n+n;
	int i=0;
	for(i=0;i<=m-1;i++)
	{
		printf(" ");
	}
	return(0);
}

/*if else recursive,the n is the index of the ch not the List*/
int IfElse(char c,int n)
{
	if(n>N)
	{
		PrintIndent(n-1);
		printf("writeln(");
		int i=0;
		printf("%c",List[0]);
		for(i=1;i<=N-1;i++)
		{
			printf(",%c",List[i]);
		}
		printf(")\n");
	}
	else
	{
		int i=List.size()-1;//the pointer to the end of the vector
		//if structure
		PrintIndent(n-1);
		printf("if ");
		printf("%c < %c",List[i],c);
		printf(" then\n");
		//if's action
		List.insert(List.begin()+i+1,c);//insert the empty blank
		IfElse(ch[n+1],n+1);
		List.erase(List.begin()+i+1);//because of the recursive  we should recover for the present level's state
		
		i--;
		
		//else if structure
		for(;i>=0;i--)
		{
			PrintIndent(n-1);
			printf("else if ");
			printf("%c < %c",List[i],c);
			printf(" then\n");
			//else if action
			List.insert(List.begin()+i+1,c);
			IfElse(ch[n+1],n+1);
			List.erase(List.begin()+i+1);
		}
		

		//else structure
		i=0;
		PrintIndent(n-1);
		printf("else\n");
		//else action
		List.insert(List.begin()+i,c);
		IfElse(ch[n+1],n+1);
		List.erase(List.begin()+i);
		
	}
	return(0);
}

/*for test*/
int test()
{
	return(0);
}

/*main process*/
int MainProc()
{
	scanf("%d",&T);
	while(T--)
	{
		//intialize the vector
		List.clear();
		List.push_back('a');
		scanf("%d",&N);
		printf("program sort(input,output);\nvar\na");
		int i=0;
		for(i=2;i<=N;i++)
		{
			printf(",%c",ch[i]);
		}
		printf(" : integer;\n");
		//the start of the program
		printf("begin\n");

		PrintIndent(1);
		printf("readln(a");
		for(i=2;i<=N;i++)
		{
			printf(",%c",ch[i]);
		}
		printf(");\n");
		
		//recursive  if else structure
		IfElse(ch[2],2);
		
		//end of the program
		printf("end.\n");
		if(T>0)
		{
			printf("\n");
		}
	}
	return(0);
}

int main()
{
	MainProc();
	return(0);
}











芋道前后端分离项目跳过登录 在此页面中可以看到当在没有获取到token时,如果此页面在白名单中则直接进入,所以我们将刚刚配置在。在此路径下配置需要跳过登录的页面路径,记住path中编辑的名称。根据以上两图可以发现芋道的。将所有需要跳过登录的方法。,否则会提示登录状态过期。至此完成免登录进入页面。 阅读详情

相关推荐

自建智能算力中心与第三方算力租赁的深度分析

自建智算中心和第三方算力租赁的主要区别如下:对比维度自建算力中心第三方算力租赁初期成本数千万至数亿元硬件采购+机房基建零硬件投入,按需付费(如1元/卡时)部署速度6-12个月(采购、部署、调试)即时开通,分钟级资源调度运维难度需专业IT团队,承担断电、故障等风险服务商全托管,SLA保障99.95%可用性弹性扩展扩容需重新采购硬件,周期长、成本高支持秒级弹性伸缩,应对流量峰值技术迭代硬件更新周期长,易被淘汰自动升级。

2501_90999758的博客 2358

UVa 110 Meta-Loopless Sorts

本题要求编写一个程序,生成能排序n个整数的Pascal程序。生成的Pascal程序必须符合严格的语法规范:包含固定程序头、变量声明、输入语句,并仅能使用if-then-else语句进行变量比较。程序需要输出n!种可能的排序结果,每个结果对应一个writeln语句。通过递归构建插入排序的决策树,确保不重复比较且格式正确。输入n(1≤n≤8),输出对应的Pascal排序程序,程序间用空行分隔。

寂静山林 537

hMailServer安装配置

hMailServer安装配置 使用宝塔面板上的宝塔邮件服务器2.1版本,进行安装hMailServer。 宝塔在安装hMailServer是有做了一些配置,如果是手工安装需要注意一下配置点: 1、\hMailServer\Bin 目录下增加mysql连接文件libmysql.dll,要去下载32位的。 libmysql.dll下载 链接:https://pan.baidu.com/s/1YGJXzjowlJ9n_MiqB4xiqw 提取码:wz90 2、 需要提前安装mysql,并创建hM.

王者的博客 5868

uva 110 Meta-Loopless Sorts(递归)

Meta-Loopless Sorts  Background  Sorting holds an important place in computer science. Analyzing and implementing various sorting algorithms forms an important part of the educatio

不慌不忙、不急不躁 1433

利用图层自动识别算法实现CAD到Revit BIM模型的高效转换 - VS2022与AutoCAD2024开发环境配置指南

本文详细介绍了如何配置VS2022与AutoCAD2024开发环境,并利用图层自动识别算法实现CAD图纸到Revit BIM模型的高效自动化转换。通过解析CAD图层的规律性,该算法能智能识别并分类墙、门、窗等构件,提取几何信息并驱动Revit自动创建三维模型,从而将传统繁琐的人工“翻模”工作转化为高效、准确的自动化流程,大幅提升BIM模型创建效率。

Apple的专栏 1128

利用随机矩阵理论(random matrix theory)确定微生物网络构建阈值

利用随机矩阵理论(random matrix theory)确定微生物网络构建阈值

微生物生态学分析 7639

uva110-Meta-Loopless Sorts(没有循环的排序程序)

对于这个题,我也尝试了多种结构,如链表,二叉树,数组;最后我还是按照类似插入排序的方法做出来的。 以a,b,c, d为例,加入已经排好了a if c 则把d放在第四个位置。得到abcd的顺序。  else if b 则把d与c交换位置,得到abdc的顺序。 else if a 则把d与b的位置交换,得到adbc的顺序。 else 则把d放到a前面,就是与a的位置交换。得到dabc的顺序。

稻草人 483

基于Simulink的PMSM轮毂电机崎岖路面悬架协同控制仿真

本文完成了基于Simulink的PMSM轮毂电机崎岖路面悬架协同控制仿真,实现了:✅ 构建了四轮独立驱动+主动悬架高保真整车模型✅ 实现了Skyhook主动悬架控制✅ 设计了驱动-悬架状态共享与协同决策机制✅ 验证了5 m/s高速下连续颠簸路面稳定通过能力✅ 为高性能移动机器人提供一体化底盘解决方案。

xiaoheshang_123的博客 190

UVA 110 Meta-Loopless Sorts

UVA-110题意:给出pascal的写法,然后问你一个n个数的排序,只用if,要怎么比较出来。然后要用pascal的写法写输出出来。 解题思路:学过pascal,好久没有用了,本来是一个美好的回忆,却被这题无情摧毁了。 言归正传。很明显每次只是对两个数进行比较,很容易想到DFS逐一控制输出。难度还好,就是第一次遇到这种题有点懵。注意每深入一次DFS前面的空格数会+2。/************

QzNarsh的博客 491

芒果YOLO11改进21:检测头Head篇:即插即用|新颖轻量化非对称多级压缩LADH检测头,原创改进适配YOLOv8高效检测头,检测头新颖性改进,全网首发独一份

检测头Head篇:即插即用|新颖轻量化非对称多级压缩LADH检测头,原创改进适配YOLOv8高效检测头,检测头新颖性改进,全网首发独一份

包括YOLOv5、YOLOv7、YOLOv8等模型改进 792

YOLO11多个点组合创新:GC10-DET缺陷检测 | DCNv4结合SPPF+11Detect创新性结合

DCNv4结合SPPF+11Detect创新性结合,原始mAP50为0.633 提升至0.651

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 1290

UVa Problem 110 - Meta-Loopless Sorts

[cpp] view plaincopyprint? // UVa Problem 110 - Meta-Loopless Sorts   // Verdict: Accepted   // Submission Date: 2011-11-25   // UVa Run Time: 0.196s   //   // 版权所有(C)2011,邱秋。metaphysis #

xujiangang_mmi的专栏 270

用群辉NAS打造影视墙(Jellyfin篇)

之前的文章提到过,用群辉NAS组建影视播放系统可以采用官方提供的Video Station套件,不过影视信息配比较差,响应速度也欠佳,今天我们就聊聊别的套件。在影音媒体方面,常见的还有Emby、Plex、Jellyfin。本文主讲Jellfin的原因是它胜在免费,而且功能比较齐全,完全够用。详细信息可以参考Jellyfin的官网:https://jellyfin.org/

dgnankai的专栏 7324

UVA110 Meta-Loopless Sorts【暴力】

Sorting holds an important place in computer science. Analyzing and implementing various sorting algorithms forms an important part of the education of most computer scientists, and sorting accounts f...

海岛Blog 554

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

UVA - 110 Meta-Loopless Sorts

Meta-Loopless Sorts  Background  Sorting holds an important place in computer science. Analyzing and implementing various sorting algorithms forms an important part of the education of

七夜 546

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

uva110 - Meta-Loopless Sorts

对于不了解的规律题要跳出来从全局看规律。 今天解决了UVa 110 Meta-Loopless Sort。这道题的关键在于生成全排列的同时也需要确定如何进行比较可以得到此种全排列。生成全排列的方法有很多,但是有一种方法最适合此题: 假设我们获得了1~n的全排列,如何获得1~n+1的全排列?对于每个1~n的全排列x(1), x(2), ... x(n),可以看作该排列中有n+1个空位,即,,

飞鸟的专栏 709

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

uva 110 - Meta-Loopless Sorts

这道题一开始也是不知道怎么下手,本来想看别人的代码的,不过都很长,实在是看不下去,后来注意到了一点,就是整个过程都是“ #include typedef struct Node{     char ch;     Node *pre,*next; }Node; Node *head; int n; void print_space(int n){

wgf3341869的专栏 619

UVa 110 - Meta-Loopless Sorts

/* 稍微不同的全排列,每层插空. 中间变量的保存有点麻烦,我用1个int类型来记录数组。每次深度遍历之前用数组生成这个int,遍历之后用int恢复数组。 AC时间:0.052s.(速度还可以啊) */ #include #include #include using namespace std; const int MAX = 8+2; int n; char A[MAX]; void

cugfjp的专栏 549

UVA 110 Meta-Loopless Sorts

Background  Sorting holds an important place in computer science. Analyzing and implementing various sorting algorithms forms an important part of the education of most computer scientists, and sor

Occult 638

uva-110-Meta-Loopless Sorts

eta-Loopless Sorts  Background  Sorting holds an important place in computer science. Analyzing and implementing various sorting algorithms forms an important part of the education of mo

写东西的地方 656

Uva110 Meta-Loopless Sorts

Meta-Loopless Sorts Background Sorting holds an important place in computer science. Analyzing and implementing various sorting algorithms forms an important part of the education of most comput...

weixin_33739541的博客 179

UVA110- Meta-Loopless Sorts(模拟全排列)

题目链接 题意:给你n个数,要求按照题目所给的规则大小排序,输出所有可能的结果。 思路:其实求出来的所有序列是n个数的全排列,那么难点在于怎么按照题目所给的格式输出。我们可以看出其实是在已知的序列上插空,所以就可以使用回溯来插入元素,这里可以使用vector,方便元素的插入。 #include #include #include #include #include

懒人一枚。 929
上一篇: Milk hdu 1070
下一篇: uva 216 Getting in Line
hackerwin7
博客等级 码龄14年 115粉丝 144原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值