题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=46  Meta-Loopless Sorts  Background Sorting holds an important place in computer science. Analyzing and implementing various so…
题目要求写一个直接用比较排序的pascal程序,挺有趣的一题. 我看题目数据范围就到8,本来以为贪个小便宜,用switch输出. 然后发现比较次数是阶乘级别的,8的阶乘也是挺大的,恐怕会交不上去. 于是改用回溯法. 其实他比较时就是把后面的数一个一个向前比较,然后插到那位前面,继续回溯. else的处理比较麻烦而已,改了好久终于跟标准答案一样了. 缩进没有处理,提交上去就ac了,看来oj没有检查缩进呢,如果有检查就还得处理一下了. 代码:(未进行缩进处理) #include <cstdio>…
 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…
 A Puzzling Problem  The goal of this problem is to write a program which will take from 1 to 5 puzzle pieces such as those shown below and arrange them, if possible, to form a square. An example set of pieces is shown here. The pieces cannot be rota…
题意:给出n,把从1到n排成一个环,输出相邻两个数的和为素数的序列 照着紫书敲的, 大概就是这个地方需要注意下,初始化的时候a[0]=1,然后dfs(1),从第1个位置开始搜 #include<iostream> #include<cstdio> #include<cstring> #include <cmath> #include<stack> #include<vector> #include<map> #includ…
看到next_permutation好像也能过╮(╯▽╰)╭ 这题学习点: 1.建图做映射 2.通过定序枚举保证字典序最小 3.strtok,sscanf,strchr等函数又复习了一遍,尽管程序中没有实际用上 4.剪枝,或者回溯 #include<bits/stdc++.h> using namespace std; ][],deg[]; ][];//判读连通 ]; ]; int k; ]; int cnt; ]; ]; void dfs(int d,int width) { if(d ==…
传送门 Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbers 1, 2, . . . , n into each circle separately, and the sum of numbers in two adjacent circles should be a prime. Note: the number of first circle sho…
Description   A ring is composed of n (even number) circles as shown in diagram. Put natural numbers 1,2,3,...,n into each circle separately, and the sum of numbers in two adjacent circles should be a prime. Note: the number of first circle should al…
题目: 给定一个4*4的棋盘和棋盘上所呈现出来的纸张边缘,问用不超过6张2*2的纸能否摆出这样的形状. 思路: dfs纸的张数,每一张中枚举这张纸左上角这个点的位置,暴力解题就可以了. 这个题的覆盖太恶心了,很容易搞混~~~(因为搞混一直TLE+WA…………) 代码: #include <bits/stdc++.h> #define inf 0x3f3f3f3f #define MAX 1000000000 #define mod 1000000007 #define FRE() freope…
题意:平面有k个障碍点.从(0,0)出发,第一次走1个单位,……,第n次走n个单位,恰好回到(0,0),每次必须转弯90°,图形可以自交,但不能经过障碍点.按字典序输出所有移动序列,并输出序列总数. 分析: 1.障碍点可能在出发点. 2.注意拐点不能重复!!! 3.按字典序输出. #pragma comment(linker, "/STACK:102400000, 102400000") #include<cstdio> #include<cstring> #i…