02 2012 档案
摘要:http://ac.jobdu.com/problem.php?id=1402位运算没的说,不过,如果每道题都考STL,那还有意思么? 1 #include <stdio.h> 2 #include <bitset> 3 using namespace std; 4 5 bitset<1000001> bits; 6 bitset<1000001> bits_assit; 7 int main() 8 { 9 int n;10 while(scanf("%d",&n)!=EOF){11 bits.reset();12
阅读全文
摘要:http://ac.jobdu.com/problem.php?id=1149 1 #include <iostream> 2 #include <stdio.h> 3 #include <map> 4 #include <string.h> 5 #include <string> 6 using namespace std; 7 8 char str[110]; 9 10 int main()11 {12 int len;13 while(scanf("%s",str)!=EOF){14 map<strin
阅读全文
摘要:dfs,好像有人说过其实搜索就是枚举,这下领会到了其实bfs应该更好的吧 1 /* ID:linyvxi1 2 PROB:holstein 3 LANG:C++ 4 */ 5 #include <stdio.h> 6 int v[26]; 7 typedef struct Vit{ 8 int num[26]; 9 }Vit;10 Vit vit[16];11 bool visited[16]={false};12 int final_result[16]={0};13 int V,G;14 int MIN=0x7fffffff;15 int cur_num[26]={0}...
阅读全文
摘要:好题,自己想没想出来,虽然大家都说是水题 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
阅读全文
摘要:模拟,开始时以为要注意去重,当输出时,判断与前一个是否重复,后来发现没这必要,如果重复了,那后边那组肯定不是互质的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
阅读全文
摘要: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
阅读全文
摘要:经典八皇后问题只写的最基本的,对称剪枝,位运算都没有用,以后有时间再看 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
阅读全文
摘要:枚举不可以,超时,加了剪枝,还是没有什么效果。不如生成,每次在数的末尾加上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;...
阅读全文
摘要:直接用最笨的方法。。。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)
阅读全文
摘要:这个不解释了吧,提交后看了下后台数据,相当的大啊。。。 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
阅读全文
摘要:还是感觉枚举好,搜索啥的越想越麻烦。因为表是圆的,每个表转四下会回到原来的位置,所以,对于每个表,最多转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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要:http://ac.jobdu.com/problem.php?id=1394写代码前先提醒自己牢记师姐的话~好像九度上没考虑某个数字重复的情况如果不考虑那种,那么,先排序,然后每个数字依次找,在长度范围内,如果有小于num+4的,需要添加的数字便少一个,然后找出所有数字中,这个值最小的 1 #include <stdio.h> 2 #include <algorithm> 3 using namespace std; 4 int N; 5 int num[1005]; 6 bool check(int i,int j) 7 { 8 if(i+j<N&&a
阅读全文
摘要:http://ac.jobdu.com/problem.php?id=1377首先庆祝昨天晚上没头疼~~~WA了无数次,找不到错误,两天之后双重写了一遍,一次就神奇的AC了。。从小往大放,因为,对于最小的数来说,肯定后面要放比它大1的数,依次类推,贪心是可行的。 1 #include <stdio.h> 2 #include <stdlib.h> 3 #define INF 0x7fffffff 4 int N; 5 int num_array[10005]; 6 void init() 7 { 8 int i; 9 for(i=0;i<=10000;i++)10
阅读全文
摘要:http://ac.jobdu.com/problem.php?id=1376N^2的算法超时优化算法想了好久没想出来,就当是学习一下STL的set了吧 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <math.h> 4 #include <set> 5 #include <iostream> 6 #define INF 0x7fffffff 7 using namespace std; 8 set<long long> S; 9 long long a,aa,
阅读全文

浙公网安备 33010602011771号