摘要: 题目:http://poj.org/problem?id=2635高精度求模 同余模定理。题意:给定一个大数K,K是两个大素数的乘积的值。再给定一个int内的数L问这两个大素数中最小的一个是否小于L,如果小于则输出这个素数。思路:Char格式读入K。把K转成千进制Kt,同时变为int型。把数字往大进... 阅读全文
posted @ 2013-11-02 23:50 水门 阅读(239) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=1942题意:给定一个矩形网格的长m和高n,其中m和n都是unsigned int32类型,一格代表一个单位,就是一步,求从左下角到右上角有多少种走法,每步只能向上或者向右走题解:就是 上和 右的排列。用c(m,n)=n!/m!*(n-m)!;最重要的是算阶乘。 1 #include 2 #include 3 #include 4 using namespace std; 5 6 unsigned comb(unsigned m,unsigned n) 7 { 8 unsigned a,b; 9 double cnt=... 阅读全文
posted @ 2013-10-30 20:30 水门 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=1159 1 #include 2 #include 3 #include 4 using namespace std; 5 6 int mmin(int a,int b) 7 { 8 return a>b?b:a; 9 }10 short int d[5010][5010];11 int main()12 {13 int n,i,j;14 char s[5010];15 memset(d,0,sizeof(d));16 cin>>n;17 for(i=1; i>s[i];19 ... 阅读全文
posted @ 2013-10-28 21:32 水门 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=1080题意:比较两个基因序列,测定它们的相似度,将两个基因排成直线,如果需要的话插入空格,使基因的长度相等,然后根据那个表格计算出相似度。题解:考虑f[i][j]:①s1取第i个,s2取第j个,f[i][j] = f[i-1][j-1]+value[m(s1[i])][m(s2[j])];②s1取第i个,s2用’-’,f[i][j] = f[i][j-1]+value[m(s1[i])][m(‘-’)];③s1用’-’,s2取第j个,f[i][j] = f[i-1][j]+value[m(‘-’)][m(s2[j])];f[i][j] 阅读全文
posted @ 2013-10-28 20:44 水门 阅读(188) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=1836题意:最长上升子序列问题, 站队,求踢出最少的人数后,使得队列里的人都能看到 左边的无穷远处 或者 右边的无穷远处。代码O(n^2): 1 #include 2 #include 3 using namespace std; 4 5 int main() 6 { 7 int n,i,j,d1[1100],d2[1100],mx; 8 double a[1100]; 9 cin>>n;10 for(i=1; i>a[i];12 d1[1]=1;13 for(i=2; i0&&d1[... 阅读全文
posted @ 2013-10-26 19:50 水门 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=2533题意:最长上升子序列。。。。 以前做过,课本上的思想 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 int main() 8 { 9 int m,a[1100];10 int d[1100],i,j,n;11 int nmax;12 cin>>n;13 for(i=1; i>a[i];16 }17 d[1]=1;18 for(i=1; i... 阅读全文
posted @ 2013-10-24 21:01 水门 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=1260题意:给出几类珍珠,以及它们的单价,要求用最少的钱就可以买到相同数量的,相同(或更高)质量的珍珠。珍珠的替代必须是连续的,不能跳跃替代(这个不难证明,因为假如用第i+2类去替代第i类珍珠,会使最终的支付价格降低,那么用第i+1类去替代第i类珍珠会使最终的支付价格更加低) 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 int main() 8 { 9 int t,i,j,num,minn,sum;10 int d[11... 阅读全文
posted @ 2013-10-24 19:41 水门 阅读(170) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=1850题意:按给定的规则给字母编号。一个很简单的题目,但是却做了好久。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。 1 #include 2 #include 3 #include 4 using namespace std; 5 int c[30][30]; 6 void init()//用杨辉三角的方法求组合数,C(n,m) 7 { 8 int i,j; 9 for(i=0; i>s;21 22 k=strlen(s);23 for(i=0; ... 阅读全文
posted @ 2013-10-18 20:20 水门 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=1276题意:费用和价值相同的多重背包。以前看背包的时候做过,今天又做了一遍。二进制优化代码 1 #include 2 #include 3 #include 4 using namespace std; 5 6 int _max(int ... 阅读全文
posted @ 2013-10-14 21:23 水门 阅读(163) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=1837题意:求平衡状态, c个位置,g个物体重量,求有多少种平衡状态。 1 #include 2 #include 3 #include 4 using namespace std; 5 6 int main() 7 { 8 int c,g,d[25][15000],h[25],w[25];//d 的第一个代表物品个数,第二个代表现在的平衡状态,>7500为向右偏 9 cin>>c>>g;10 for(int i=1; i>h[i];12 for(int i=1; i>w[i];14 mems 阅读全文
posted @ 2013-10-14 19:09 水门 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 我的dfs真的好虚啊……,又是看的别人的博客做的 题目==题目:http://poj.org/problem?id=1416题意:给你两个数n,m;n表示最大数,m则是需要切割的数。切割m,使得切割之后的数的和小于等于n。求出最大的切割方法;例: 50 1234612346可以切割为 1 2 34 ... 阅读全文
posted @ 2013-08-31 21:30 水门 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=2531题意:一个矩阵,分成两个集合,求最大的 阻碍量改的 一位大神的代码,比较简洁 1 #include 2 #include 3 int n,max; 4 int g[30][30]; 5 int v[30]; 6 void dfs(int x,int sum) 7 { 8 int i,t=sum; 9 v[x]=1;10 for(i=1; imax)17 max=t;18 for(i=x+1; isum)20 {21 dfs(i,t);22 ... 阅读全文
posted @ 2013-08-28 21:46 水门 阅读(175) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=1129题意:求最小m,使平面图能染成m色,相邻两块不同色由四色定理可知顶点最多需要4种颜色即可。我们于是从1开始试到3即可。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include10 #include11 #include12 using namespace std;13 14 int n,G[30][30],vis[30][5],ans;15 void pri(... 阅读全文
posted @ 2013-08-28 19:38 水门 阅读(192) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=3414题意:给出了两个瓶子的容量A,B, 以及一个目标水量C,对A、B可以有如下操作:FILL(i) fill the pot i (1 ≤ i ≤ 2) from the tap;DROP(i) empty the pot i to the drain;POUR(i,j) pour from pot i to pot j; after this operation either the pot j is full (and there may be some water left in the pot i), or the pot 阅读全文
posted @ 2013-08-28 18:22 水门 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=3009参考博客:http://www.cnblogs.com/LK1994/ 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include10 #include11 #include12 using namespace std;13 14 int w,h,G[30][30];15 int d[4][2]={{1,0},{0,-1},{-1,0},{0,1}};16 int minstep;17 18. 阅读全文
posted @ 2013-08-27 22:02 水门 阅读(168) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=2488题意:给出一个国际棋盘的大小,判断马能否不重复的走过所有格,并记录下其中按字典序排列的第一种路径。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include10 #include11 #include12 using namespace std;13 14 struct node15 {16 int x,y;17 }q[30]; //记录路径18 int p,c;19 int vi... 阅读全文
posted @ 2013-08-27 16:42 水门 阅读(172) 评论(0) 推荐(0) 编辑
摘要: dfs 用的还是不行啊,做题还是得看别人的博客!!!题目:http://poj.org/problem?id=2676题意:把一个9行9列的网格,再细分为9个3*3的子网格,要求每行、每列、每个子网格内都只能使用一次1~9中的一个数字,即每行、每列、每个子网格内都不允许出现相同的数字。0是待填位置,其他均为已填入的数字。要求填完九宫格并输出(如果有多种结果,则只需输出其中一种)如果给定的九宫格无法按要求填出来,则输出原来所输入的未填的九宫格参考博客:http://www.cnblogs.com/tanhehe/archive/2013/08/07/3243073.htmlhttp://blog 阅读全文
posted @ 2013-08-27 15:30 水门 阅读(188) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=3087题意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块牌归为s1,最顶的c块牌归为s2,依此循环下去。现在输入s1和s2的初始状态 以及 预想的最终状态s12问s1 s2经过多少次洗牌之后,最终能达到状态s12,若永远不可能相同,则输出"-1"。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 阅读全文
posted @ 2013-08-27 09:57 水门 阅读(166) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=1426题意:输入一个数,输出这个数的整数 倍,且只有0和1组成程序里写错了一个数,结果一直MLE.…… 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include10 #include11 #include12 using namespace std;13 14 long long a;15 void bfs()16 {17 queueq;18 int i,j;19 lon... 阅读全文
posted @ 2013-08-26 20:57 水门 阅读(365) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=3126题意:给定两个四位数,求从前一个数变到后一个数最少需要几步,改变的原则是每次只能改变某一位上的一个数,而且每次改变得到的必须是一个素数; 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include10 #include11 #include12 using namespace std;13 14 int p[10010],vis[10010];15 int a,b,t;16 struct n. 阅读全文
posted @ 2013-08-26 20:03 水门 阅读(153) 评论(0) 推荐(0) 编辑