题意:小牌叠在大牌上,问叠成一堆的最小移动距离 思路:将所有状况进行一次DFS #include<bits/stdc++.h>using namespace std;int a[11];int s;int vis[11];void dfs(int k,int ans){ if(ans>s)retur Read More
posted @ 2017-03-31 14:21 地对地导弹2 Views(171) Comments(0) Diggs(0)
A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacen Read More
posted @ 2017-03-30 17:56 地对地导弹2 Views(140) Comments(0) Diggs(0)
# include <cstdio> # include <cmath> # include <algorithm> using namespace std; int n, s[10]; int main(){ int i, j, k, a, b, c, ans; scanf("%d", &n); Read More
posted @ 2017-03-30 16:58 地对地导弹2 Views(109) Comments(0) Diggs(0)
标题: 幻方填空 16 ? ? 13 ? ? 11 ? 9 ? ? * ? 15 ? 1 答案是一个整数,请通过浏览器直接提交该数字。 注意:不要提交解答过程,或其它辅助说明类的内容。 #include<cstdio>#include<iostream>#include<algorithm>usin Read More
posted @ 2017-03-29 20:42 地对地导弹2 Views(475) Comments(0) Diggs(0)
#include<iostream>using namespace std;int a[4][5];int s;//保存计数器void bck(int i, int j)//递归{ if (a[i][j] == 8){ s++; return; }//函数出口 if (i + 1 > 4 || j Read More
posted @ 2017-03-29 18:59 地对地导弹2 Views(241) Comments(0) Diggs(0)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 17654 Accepted Submission(s): 8830 Read More
posted @ 2016-11-14 16:37 地对地导弹2 Views(97) Comments(0) Diggs(0)
#include <iostream> #include <algorithm> /// next_permutation, sort里卖弄包括两个函数,桉顺序获得下一个要排列的数,也可以自己写一个泪时的函数。。 using namespace std; int main () { char myi Read More
posted @ 2016-04-30 18:31 地对地导弹2 Views(107) Comments(0) Diggs(0)
#include<iostream>#include<string.h>#include<algorithm>using namespace std;void swap(char &a,char &b){ char t=a; a=b;b=t;} bool Isright(char* a,int st Read More
posted @ 2016-04-27 21:22 地对地导弹2 Views(285) Comments(1) Diggs(0)
三、全排列的非递归实现 要考虑全排列的非递归实现,先来考虑如何计算字符串的下一个排列。如"1234"的下一个排列就是"1243"。只要对字符串反复求出下一个排列,全排列的也就迎刃而解了。 如何计算字符串的下一个排列了?来考虑"926520"这个字符串,我们从后向前找第一双相邻的递增数字,"20"、"52"都是非递增的,"26 "即满足要求,称前一个数字2为替换数,替换数的下标称为替换点,再从后面找一个比替换数大的最小数(这个数必然存在),0、2都不行,5可以,将5和2交换得到"956220",然后再将替换点后的字符串"6220"颠倒即得到"950226"。 对于像“4321”这种已经是最“大”的排列,采用STL中的处理方法,将字符串整个颠倒得到最“小”的排列"1234"并返回false。 这样,只要一个循环再加上计算字符串下一个排列的函数就可以轻松的实现非递归的全排列算法。按上面思路并参考STL中的实现源码,不难写成一份质量较高的代码。值得注意的是在循环前要对字符串排序下,可以自己写快速排序的代码(请参阅《白话经典算法之六 快速排序 快速搞定》),也可以直接使用VC库中的快速排 Read More
posted @ 2016-04-27 21:22 地对地导弹2 Views(342) Comments(2) Diggs(0)