上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 13 下一页
摘要: 好题,自己想没想出来,虽然大家都说是水题 1 /* ID:linyvxi1 2 PROB:sort3 3 LANG:C++ 4 */ 5 #include <stdio.h> 6 #include <algorithm> 7 using namespace std; 8 int start_pos[1005]; 9 int final_pos[1005];10 int corr_map[4][4]={0};11 int main()12 {13 freopen("sort3.in","r",stdin);14 freopen(&q 阅读全文
posted @ 2012-02-19 09:35 linyvxiang 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 模拟,开始时以为要注意去重,当输出时,判断与前一个是否重复,后来发现没这必要,如果重复了,那后边那组肯定不是互质的analysis里给出了“super fast solution"的方法,类似杨辉三角,想起了高中时的阿炳老师--两个肩上数之和~~ 1 /* ID:linyvxi1 2 PROB:frac1 3 LANG:C++ 4 */ 5 #include <stdio.h> 6 #include <algorithm> 7 using namespace std; 8 typedef struct Frac{ 9 int up;10 int down;11 阅读全文
posted @ 2012-02-16 16:53 linyvxiang 阅读(194) 评论(0) 推荐(0) 编辑
摘要: http://ac.jobdu.com/problem.php?id=1140直接用的USACO上代码,不解释 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 int N=8; 5 bool placed[15][15]={false}; 6 int diagonals_l[50]={0}; 7 int diagonals_r[50]={0}; 8 bool column_ok[15]={true}; 9 int solutions[93]={0};10 int cur=1 阅读全文
posted @ 2012-02-15 21:23 linyvxiang 阅读(203) 评论(0) 推荐(0) 编辑
摘要: 经典八皇后问题只写的最基本的,对称剪枝,位运算都没有用,以后有时间再看 1 /* ID:linyvxi1 2 PROB:checker 3 LANG:C++ 4 */ 5 #include <stdio.h> 6 #include <stdlib.h> 7 #include <string.h> 8 int N; 9 int total_solutions=0;10 int times_already_output=0;11 bool placed[15][15]={false};12 int diagonals_l[50]={0};13 int diago 阅读全文
posted @ 2012-02-15 18:21 linyvxiang 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 枚举不可以,超时,加了剪枝,还是没有什么效果。不如生成,每次在数的末尾加上1,3,7,9,如果是素数,再继续加,直到加到长度满足为止,效率大大提高 1 /* ID:linyvxi1 2 PROB:sprime 3 LANG:C++ 4 */ 5 #include <stdio.h> 6 int n; 7 bool prime(int num) 8 { 9 if(num==1)10 return false;11 if(num==2)12 return true;13 int i;14 for(i=2;i*i<=num;... 阅读全文
posted @ 2012-02-10 23:23 linyvxiang 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 直接用最笨的方法。。。ANALYSIS里有讲,其实只算一半长度就行代码相当的难看。。。 1 /* 2 ID:linyvxi1 3 PROB:pprime 4 LANG:C++ 5 */ 6 #include <stdio.h> 7 #include <math.h> 8 void do_1(); 9 void do_2(); 10 void do_3(); 11 void do_4(); 12 void do_5(); 13 void do_6(); 14 void do_7(); 15 void do_8(); 16 inline bool prime(int n) 阅读全文
posted @ 2012-02-09 18:41 linyvxiang 阅读(428) 评论(0) 推荐(0) 编辑
摘要: 这个不解释了吧,提交后看了下后台数据,相当的大啊。。。 1 /* ID:linyvxi1 2 PROB:numtri 3 LANG:C++ 4 */ 5 #include <stdio.h> 6 #include <math.h> 7 #include <stdlib.h> 8 int max(int a,int b) 9 {10 return a>b?a:b;11 }12 int num_map[1001][1001];13 int main()14 {15 freopen("numtri.in","r",st 阅读全文
posted @ 2012-02-08 21:56 linyvxiang 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 还是感觉枚举好,搜索啥的越想越麻烦。因为表是圆的,每个表转四下会回到原来的位置,所以,对于每个表,最多转3次,或者不转,也就是说,对于9个表,每个表有四种可能,那么,一共有4^9种可能,依次枚举,第一个符合条件的即是最小的 1 /* ID:linyvxi1 2 PROB:clocks 3 LANG:C++ 4 */ 5 #include <stdio.h> 6 #include<string> 7 #include<algorithm> 8 using namespace std; 9 10 int ans[10], num[10], tmp[10];11 阅读全文
posted @ 2012-02-08 18:42 linyvxiang 阅读(226) 评论(0) 推荐(0) 编辑
摘要: DFS最容易理解,visited[A][B][C]表示a,b,c三桶此种状态有没有被搜索过,ans存放符合条件时,c桶的状态。对于每一个状态,下一状态有六种可能,详见代码中注释 1 /* 2 ID:linyvxi1 3 PROG:milk3 4 LANG:C++ 5 */ 6 #include <stdio.h> 7 #include <algorithm> 8 #include <stdlib.h> 9 #include <string.h>10 using namespace std;11 long ans[50],p=-1;12 long 阅读全文
posted @ 2012-02-08 14:25 linyvxiang 阅读(207) 评论(0) 推荐(0) 编辑
摘要: http://ac.jobdu.com/problem.php?id=1091牢记师姐的话~基本DFS,一开始越界了,搜索了好长时间,后来检查是内存越界了,不过奇怪,怎么没提示啥呢把方向存数组里,代码可以更短的。还有,某些人喜欢COPY别人的代码,不是好习惯,不管他了。 1 #include <stdio.h> 2 #define INF 0x7fffffff 3 int cost_array[8][8]; 4 int n; 5 int start_x,start_y,end_x,end_y; 6 int fin_cost=INF; 7 bool available(int x,i 阅读全文
posted @ 2012-02-07 16:40 linyvxiang 阅读(165) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 13 下一页