随笔分类 - ACM — 数论
摘要:http://www.bnuoj.com/bnuoj/problem_show.php?pid=16493【题解】:矩阵快速幂【code】: 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 int N; 8 struct matrix 9 { 10 double a[100][100]; 11 }origin,res; 12 13 14 matrix multiply(matrix x,matrix y) 15 { 16 matrix tem...
阅读全文
摘要:http://acm.csu.edu.cn/OnlineJudge/problem.php?cid=2037&pid=1【题解】:卡特兰数取模h(n) = h(n-1)*(4*n-2)/(n+1)这题我们公式选择错了,不过还是能AC的因为要取模,应该选 h(n)=h(0)*h(n-1)+h(1)*h(n-2)+...+h(n-1)*h(0) (n>=2)【code-java】: 1 import java.math.BigInteger; 2 import java.util.Scanner; 3 4 public class Main { 5 6 public stati...
阅读全文
摘要:【题解】:二进制拆分 任意一个整数都可以拆分成 2^0 + 2^1 + 2^2 + 2^3 + ....+ m【code】: 1 #include 2 #include 3 #include 4 #include 5 6 using namespace std; 7 8 int main() 9 {10 int n;11 while(~scanf("%d",&n))12 {13 int i,sum=0;14 for(i=0;;i++)15 {16 sum+=pow(2,i);17 ...
阅读全文
摘要:http://www.bnuoj.com/bnuoj/problem_show.php?pid=4187【题意】:如题【题解】:取n,m的最小值进行遍历就可以了: 注意 0 1 这组测试数据【code】: 1 #include 2 #include 3 #include 4 #include 5 #include 6 7 using namespace std; 8 9 int main()10 {11 int t;12 scanf("%d",&t);13 while(t--)14 {15 int n,m;16 ch...
阅读全文
摘要:http://www.bnuoj.com/bnuoj/problem_show.php?pid=4225【题意】:给定任意杨辉三角的行数n,请输出杨辉三角中前n行中总共有多少偶数。【题解】: 找规律:1为奇数 0为偶数 打出表1111011111100011100111010101111111111000000011100000011101000001011111000011111000100010001110011001100111010101010101011111111111111111该发现什么了吧!!!【code】: 1 #include 2 #include 3 #inclu...
阅读全文
摘要:http://www.bnuoj.com/bnuoj/problem_show.php?pid=20834【题意】:每次减少一半的空格,问经过多少次操作能得到每个单词之间的空格为1,输入字符串大小小于等于1MB【题解】:1、如果单词之间最大的空格数为2的n次方,那么输出22、否则输出n+1注意字符串大小1MB,这里用C++中string进行处理【code】: 1 #include 2 #include 3 #include 4 #include 5 #include 6 7 using namespace std; 8 9 int main()10 {11 string ...
阅读全文
摘要:http://www.bnuoj.com/bnuoj/problem_show.php?pid=4359【题意】:输入N,表示几位数,0-这个N位数,有多少个满足条件的号码,不满足的情况为出现4,13的情况【题解】: 写暴力代码找规律 1 92 80 3 711 4 6319得出规律 a[i] = a[i-1]*9 - a[i-2]另外注意处理减法出现负数的情况【code】: 1 #include 2 #include 3 #include 4 #include 5 6 #define MOD 100000000 7 #define N 1000000 8 ...
阅读全文
摘要:http://www.bnuoj.com/bnuoj/problem_show.php?pid=4353【题意】:每次选择一个小格后,该小格的右上部分就全被删去了,且要求每次至少删去一个格子,选中左下角格子的人算输。【题解】:这个题嘛,这个题嘛,这个题嘛,还是看代码吧,不解释。。。【code】: 1 #include 2 #include 3 #include 4 #include 5 6 using namespace std; 7 8 int main() 9 {10 int t;11 scanf("%d",&t);12 while(t--)13 ...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4722【题意】: 找GoodNumbers一个数N,如果它每一个位数字之和可以整除10,那么它就是GoodNumbers,比如451就是一个4+5+1=10,求[A,B]之间这样的数的个数【题解】: 先写一个暴力代码用来找规律发现: 0-10 1 0-100 10 0-1000 100 0-990 99 0-992 100 0-997 100 基本规律为 n/10 + (1或0) 加1的情况为:n/10*10到 n 有满足条件的 比如:997: 99 + (990到997是否有满足条...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2566假设一堆由1分、2分、5分组成的n个硬币总面值为m分,求一共有多少种可能的组合方式(某种面值的硬币可以数量可以为0)。输入数据第一行有一个正整数T,表示有T组测试数据;接下来的T行,每行有两个数n,m,n和m的含义同上。对于每组测试数据,请输出可能的组合方式数;每组输出占一行。Sample Input2 3 5 4 8Sample Output1 2【题解】: 这里没有给出n,m的范围,建议使用第三种【code3】方式解【code1】:暴力O(N*N) 1 #include 2 #include 3..
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4715【code】: 1 #include 2 #include 3 #include 4 #include 5 6 using namespace std; 7 #define N 1000151 8 9 int prim[N+10];10 int hash[1000000];11 int mark[1000010];12 int cjsb[1000010];13 int hash_cnt=0;14 int lowbit(int i)15 {16 return i&-i;17 }18 v...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4710【code】: 1 #include 2 #include 3 #include 4 #include 5 6 using namespace std; 7 #define N 1000151 8 9 int prim[N+10];10 int hash[1000000];11 int mark[1000010];12 int cjsb[1000010];13 int hash_cnt=0;14 int lowbit(int i)15 {16 return i&-i;17 }18 v...
阅读全文
摘要:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=13031303: DecimalTime Limit: 1 Sec Memory Limit: 128 MB Submit: 589 Solved: 61 [Submit][Status][Web Board]Description任意一个分数都是有理数,对于任意一个有限小数,我们都可以表示成一个无限循环小数的形式(在其末尾添加0),对于任意一个无限循环小数都可以转化成一个分数。现在你的任务就是将任意一个无限循环小数转化成既约分数形式。所谓既约分数表示,分子和分母的最大公约数是1。Input有多
阅读全文
摘要:http://poj.org/problem?id=2262Goldbach's ConjectureTime Limit:1000MSMemory Limit:65536KTotal Submissions:34323Accepted:13169DescriptionIn 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following conjecture:Every even number greater
阅读全文
摘要:http://poj.org/problem?id=1348ComputingTime Limit:1000MSMemory Limit:10000KTotal Submissions:1681Accepted:248DescriptionInput any five positive integral numbers n1, n2, n3, n4, n5, such that 0 2 #include 3 #include 4 #include 5 6 using namespace std; 7 8 struct Nod 9 { 10 int son; //分子...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1021Fibonacci AgainTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29201 Accepted Submission(s): 14148 Problem DescriptionThere are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) +
阅读全文
摘要:http://poj.org/problem?id=2440DNATime Limit:1000MSMemory Limit:65536KTotal Submissions:3254Accepted:1285DescriptionA kind of virus has attacked the X planet, and many lives are infected. After weeks of study, The CHO (Creature Healthy Organization) of X planet finally finds out that this kind of vir
阅读全文
摘要:http://ac.nbutoj.com/Problem/view.xhtml?id=1475[1475] Bachelor时间限制: 1000 ms 内存限制: 65535 K问题描述炎热的暑期集训就要结束了,在这短短的20天,大家都很努力,因为很多都是光棍嘛。balabala 所以 Marknoon 先森一直耿耿于怀,毕竟他也是单身嘛。 有一天,Marknoon 先森看着一串数字,发现了那个跟他同命相连的数字1,所以他就开始无聊起来,想知道从数字1到数字N,一共出现了几个1。 例如N=12,则1的个数为5,出现1的数字分别为1,10,11,12。输入输入一个数N(1 2 #include.
阅读全文
摘要:hdu 1597 find the nth digitProblem Description假设:S1 = 1S2 = 12S3 = 123S4 = 1234.........S9 = 123456789S10 = 1234567891S11 = 12345678912............S18 = 123456789123456789..................现在我们把所有的串连接起来S = 1121231234.......123456789123456789112345678912.........那么你能告诉我在S串中的第N个数字是多少吗?Input输入首先是一个数字K,
阅读全文
摘要:hdu 1280 前m大的数Problem Description还记得Gardon给小希布置的那个作业么?(上次比赛的1005)其实小希已经找回了原来的那张数表,现在她想确认一下她的答案是否正确,但是整个的答案是很庞大的表,小希只想让你把答案中最大的M个数告诉她就可以了。给定一个包含N(N<=3000)个正整数的序列,每个数不超过5000,对它们两两相加得到的N*(N-1)/2个和,求出其中前M大的数(M<=1000)并按从大到小的顺序排列。 Input输入可能包含多组数据,其中每组数据包括两行:第一行两个数N和M,第二行N个数,表示该序列。Output对于输入的每组数据,输出M
阅读全文

浙公网安备 33010602011771号