随笔分类 - 算法入门
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 9 const int nMax = 3000; 10 int A[nMax+1]; 11 int B[nMax+1];//用来每次5分法后保存要比较的值在A中的下...
        阅读全文
            
摘要:/*调用算法中函数求写一个排序*/#include #include#include#include#include#include#include#includeusing namespace std;#define maxn 2600000typedef int State[9];State st[maxn],goal;int dist[maxn];const int dx[]= {-1,1,0,0};const int dy[]= {0,0,-1,1};int vis[36288],fact[9];/*void init_lookup_table(){ int i; fact...
        阅读全文
            
摘要:/* Monthly ExpenseTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 10757 Accepted: 4390DescriptionFarmer John is an astounding accounting wizard and has realized he might run out of money to run the farm. He has already calculated and recorded the exact amount of money (1 ≤ mo...
        阅读全文
            
摘要:/*二分查找(范围统计)*/#include #include#include#include#include#include#include#includeusing namespace std;#define maxn 1000int A[maxn];int lower_bound1(int *A,int x,int y,int v)//二分查找求下界{ int m; while(x=v)//看区别 y=m; else x=m+1; } return x;}int upper_bound1(int *A,in...
        阅读全文
            
摘要:/*困难串(无两个相邻的重复字串)*/#include #include#include#include#include#include#include#includeusing namespace std;#define maxn 1000int cnt,n,L;int S[maxn];int dfs(int cur)//返回0表示已经得到解,无须继续搜索{ int i,ok,j,k,equals; if(cnt++==n)//输出方案 { for(i=0; i<cur; i++) printf("%c",'A'+S[i]); ...
        阅读全文
            
摘要:/*n皇后问题*/#include #include#include#include#include#include#include#includeusing namespace std;#define maxn 1000int n,tot,col[maxn],vis[3][maxn];void search(int cur){ int i,j; if(cur==n) { tot++; printf("----解%d:----\n",tot); for(i=0; i<n; i++) { printf...
        阅读全文
            
摘要:/*摘抄自博客:Recursively Palindromic PartitionsTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 472 Accepted: 345DescriptionA partition of a positive integer N is a sequence of integers which sum to N, usually written with plus signs between the numbers of the partition. For exampl...
        阅读全文
            
摘要:Prime CutsTime Limit:1000MSMemory Limit:10000KTotal Submissions:9339Accepted:3562DescriptionA prime number is a counting number (1, 2, 3, ...) that is evenly divisible only by 1 and itself. In this problem you are to write a program that will cut some number of prime numbers from the list of prime n
        阅读全文
            
摘要:Prime GapTime Limit:5000MSMemory Limit:65536KTotal Submissions:7392Accepted:4291DescriptionThe sequence of n − 1 consecutive composite numbers (positive integers that are not prime and not equal to 1) lying between two successive prime numberspandp+nis called a prime gap of lengthn. For example, ‹24
        阅读全文
            
摘要:/*杭电2011和2012级同学如何加入ACM集训队?微软招聘信息(主要针对已经有工作经验的) 统计硬币Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2497 Accepted Submission(s): 1727Problem Description假设一堆由1分、2分、5分组成的n个硬币总面值为m分,求一共有多少种可能的组合方式(某种面值的硬币可以数量可以为0)。 Input输入数据第一行有一个正整数T,表示有T组测试数...
        阅读全文
            
摘要:/*放大的XTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5732 Accepted Submission(s): 1747Problem Description请你编程画一个放大的’X’。如3*3的’X’应如下所示:X X XX X5*5的’X’如下所示:X X X X X X XX X Input输入数据第一行是一个整数T,表示有T组测试数据;接下来有T行,每行有一个正奇数n(3 <= n <= 79),表示放大的...
        阅读全文
            
摘要:/*微软招聘信息(主要针对已经有工作经验的) 又见GCDTime Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6407 Accepted Submission(s): 2634Problem Description有三个正整数a,b,c(0<a,b,c<10^6),其中c不等于b。若a和c的最大公约数为b,现已知a和b,求满足条件的最小的c。 Input第一行输入一个n,表示有n组测试数据,接下来的n行,每行输入两个正整数a,b。 Ou
        阅读全文
            
摘要:/*矩形A + BTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2570 Accepted Submission(s): 1946Problem Description给你一个高为n ,宽为m列的网格,计算出这个网格中有多少个矩形,下图为高为2,宽为4的网格. Input第一行输入一个t, 表示有t组数据,然后每行输入n,m,分别表示网格的高和宽 ( n < 100 , m < 100). Output每行输出网格中有多少个矩形
        阅读全文
            
摘要:/*统计问题Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3119 Accepted Submission(s): 1797Problem Description在一无限大的二维平面中,我们做如下假设:1、 每次只能移动一格;2、 不能向后走(假设你的目的地是“向上”,那么你可以向左走,可以向右走,也可以向上走,但是不可以向下走);3、 走过的格子立即塌陷无法再走第二次;求走n步不同的方案数(2种走法只要有一步不一样,即被...
        阅读全文
            
摘要:/*月之数Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4180 Accepted Submission(s): 2448Problem Description当寒月还在读大一的时候,他在一本武林秘籍中(据后来考证,估计是计算机基础,狂汗-ing),发现了神奇的二进制数。如果一个正整数m表示成二进制,它的位数为n(不包含前导0),寒月称它为一个n二进制数。所有的n二进制数中,1的总个数被称为n对应的月之数。例如,3二进制数总共有...
        阅读全文
            
摘要:/*Big NumberTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 17223 Accepted Submission(s): 7703Problem DescriptionIn many applications very large integers numbers are required. Some of these applications are using keys for secure transmission...
        阅读全文
            
摘要:/*杭电2011和2012级同学如何加入ACM集训队?微软招聘信息(主要针对已经有工作经验的) 汉字统计Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 14437 Accepted Submission(s): 8011Problem Description统计给定文本文件中汉字的个数。 Input输入文件首先包含一个整数n,表示测试实例的个数,然后是n段文本。 Output对于每一段文本,输出其中的汉字的个数,每个测试实例的输出...
        阅读全文
            
摘要:/*一个人的旅行Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10787 Accepted Submission(s): 3674Problem Description虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷路的人,汗~),但是草儿仍然很喜欢旅行,因为在旅途中 会遇见很多人(白马王子,^0^),很多事,还能丰富自己的阅历,还可以看美丽的风景……草儿想去很多地方,她想要去东京铁塔看夜景,去威尼斯看电影,去阳明山上...
        阅读全文
            
摘要:/*Least Common MultipleTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 18649 Accepted Submission(s): 6949Problem DescriptionThe least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by ...
        阅读全文
            
摘要:/*微软招聘信息(主要针对已经有工作经验的) 还是畅通工程Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15993 Accepted...
        阅读全文
            
                    
                
浙公网安备 33010602011771号