恒邪

2014年3月31日 #

hdu acm 1051 Zipper

摘要: dfs 有点麻烦,不过也不是很难 1 #include 2 #include 3 #include 4 char str1[205],str2[205],str3[405]; 5 int flag; 6 int len1,len2,len3; 7 int hash[205][205]; 8 void dfs(int a,int b,int c) 9 {10 if(flag)11 return;12 if(c==len3)13 {14 flag=1;15 return;16 }17 if(hash[a][b])18 ... 阅读全文

posted @ 2014-03-31 20:48 恒邪 阅读(205) 评论(0) 推荐(0) 编辑

[ACM] poj 2369 Permutations (置换群循环节长度)

摘要: DescriptionWe remind that the permutation of some final set is a one-to-one mapping of the set onto itself. Less formally, that is a way to reorder elements of the set. For example, one can define a permutation of the set {1,2,3,4,5} as follows: This record defines a permutation P as follows: P(1) = 阅读全文

posted @ 2014-03-31 20:05 恒邪 阅读(439) 评论(0) 推荐(0) 编辑

hdu 1035 Robot Motion

摘要: 算是搜索题吧。。。。 1 /* 2 hdu 1035 Robot Motion 3 简单题 虽然代码有些长 但是写起来简单,不费脑子 4 */ 5 #include 6 #include 7 #include 8 using namespace std; 9 int p;10 int m,n;11 int a[15][15];12 char c[15][15];13 void fun(int x,int y)14 {15 p++;16 if(x=m) throw -2;//需先判断是否出界,否则WA17 if(y=n) throw -2;18 i... 阅读全文

posted @ 2014-03-31 19:52 恒邪 阅读(107) 评论(0) 推荐(0) 编辑

最大公约数求解

摘要: 方法一:辗转相除法优点:代码简单,容易写。缺点:开销大,用时间多。代码:int gcd(int a,int b){ return b==0?a:gcd(b,a%b);}方法二:二进制算法优点:速度快。主要思想:前提:a>b,分情况讨论:1.a和b均为偶数,gcd(a,b)=2*gcd(a/2,b/2);2.a为偶数b为奇数,gcd(a,b)=gcd(a/2,b);3.a和b均为奇数,gcd(a,b)=gcd(a-b,b)代码:int gcd(int a,int b){ int t=1,c,d; while(a!=b) { if(a>=1; ... 阅读全文

posted @ 2014-03-31 18:04 恒邪 阅读(170) 评论(0) 推荐(0) 编辑

导航