摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1106比较简单,不过还是出错了、输入一行数字,如果我们把这行数字中的‘5’都看成空格,那么就得到一行用空格分割的若干非负整数(可能有些整数以‘0’开头,这些头部的‘0’应该被忽略掉,除非这个整数就是由若干个‘0’组成的,这时这个整数就是0)。你的任务是:对这些分割得到的整数,依从小到大的顺序排序输出。#include <stdio.h>#include <string.h>#include <stdlib.h>int cmp(const void *a,const void
阅读全文
摘要:题目连接http://acm.hdu.edu.cn/showproblem.php?pid=1325http://poj.org/problem?id=1308在POJ上WA了,看来还是有问题的呀#include <iostream>#include <cstdio>#include <string.h>using namespace std;int hr[100003],hs[100003];int mer[100003];int main(){ // freopen("in.txt","r",stdin); int
阅读全文
摘要:题目连接:http://poj.org/problem?id=1423#include #include #include #include #include #include #include using namespace std;int a[10000001];int main(){ //freopen("in.txt","r",stdin); int n,i,t,m; double sum; for(i=1;i<=10000000;i++)//打表,开始忘记了,果断TLT,得长记性! { sum+=log10(double(i)); a[i
阅读全文
摘要:题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1026在这博客学的 ttp://www.wutianqi.com/?p=2354感觉看了这个之后收获良多#include <queue>#include <stack>#include <cstdio>#include <iostream>#include <string.h>#include <algorithm>using namespace std;typedef struct node{ int x,y,dis; int
阅读全文
摘要:http://www.cnblogs.com/lonelycatcher/archive/2011/05/27/2060158.htmlGiven you n sets.All positive integers in sets are not less than 1 and not greater than m.If use these sets to combinate the new set,how many different new set you can get.The given sets can not be broken.InputThere are several case
阅读全文
摘要:“ 改革春风吹满地,不会AC没关系;实在不行回老家,还有一亩三分地。谢谢!(乐队奏乐)”话说部分学生心态极好,每天就知道游戏,这次考试如此简单的题目,也是云里雾里,而且,还竟然来这么几句打油诗。好呀,老师的责任就是帮你解决问题,既然想种田,那就分你一块。这块田位于浙江省温州市苍南县灵溪镇林家铺子村,多边形形状的一块地,原本是linle 的,现在就准备送给你了。不过,任何事情都没有那么简单,你必须首先告诉我这块地到底有多少面积,如果回答正确才能真正得到这块地。发愁了吧?就是要让你知道,种地也是需要AC知识的!以后还是好好练吧...Input输入数据包含多个测试实例,每个测试实例占一行,每行的开始
阅读全文
摘要:HOHO,终于从Speakless手上赢走了所有的糖果,是Gardon吃糖果时有个特殊的癖好,就是不喜欢将一样的糖果放在一起吃,喜欢先吃一种,下一次吃另一种,这样;可是Gardon不知道是否存在一种吃糖果的顺序使得他能把所有糖果都吃完?请你写个程序帮忙计算一下。Input第一行有一个整数T,接下来T组数据,每组数据占2行,第一行是一个整数N(0<N<=1000000),第二行是N个数,表示N种糖果的数目Mi(0<Mi<=1000000)。Output对于每组数据,输出一行,包含一个"Yes"或者"No"。Sample Input2
阅读全文
摘要:N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色。但是N次以后lele已经忘记了第I个气球已经涂过几次颜色了,你能帮他算出每个气球被涂过几次颜色吗?Input每个测试实例第一行为一个整数N,(N <= 100000).接下来的N行,每行包括2个整数a b(1 <= a <= b <= N)。当N = 0,输入结束。Output每个测试实例输出一行,包括N个整数,第I个数代表第I个气球总共被涂色的次数。Sample Input
阅读全文
摘要:Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for the venue. Japan is tall island with N cities on the East coast and M cities on the West coast (M <= 1000, N <= 1000). K superhighways will be build. Cities on each coast are numbered 1, 2, ... from North to
阅读全文
摘要:Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given star. Astronomers want to know the distribution of the levels of the s
阅读全文
摘要:Little Valentine liked playing with binary trees very much. Her favorite game was constructing randomly looking binary trees with capital letters in the nodes.This is an example of one of her creations:D/ \/ \B E/ \ \/ \ \A C G//FTo record her trees for future generations, she wrote down two strings
阅读全文
摘要:As we know,the shape of a binary search tree is greatly related to the order of keys we insert. To be precisely:1.insert a key k to a empty tree, then the tree become a tree withonly one node;2.insert a key k to a nonempty tree, if k is less than the root ,insertit to the left sub-tree;else insert k
阅读全文
摘要:A binary tree is a finite set of vertices that is either empty or consists of a root r and two disjoint binary trees called the left and right subtrees. There are three most important ways in which the vertices of a binary tree can be systematically traversed or ordered. They are preorder, inorder a
阅读全文
摘要:An encoding of a set of symbols is said to be immediately decodable if no code for one symbol is the prefix of a code for another symbol. We will assume for this problem that all codes are in binary, that no two codes within a set of codes are the same, that each code has at least one bit and no mor
阅读全文
摘要:判断两序列是否为同一二叉搜索树序列Input开始一个数n,(1#include inta[1024],b[1024];voidcta(charc,inti)//这个和下面可以合并一个,用指针传递数组{ if(a[i]==0) {a[i]=c;return;} if(a[i]>c) cta(c,ic) ctb(c,im2?m2:m1;//递归回程,判断树是否一样}intmain(){inti,n; charc[13],s[13]; while(scanf("%d",&n),n) { memset(a,0,sizeof(a)); scanf("%s&qu
阅读全文
摘要:Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall.A blockhouse is a small castle that has four openings through which to shoot. The four openings are facing North, East, South, and West
阅读全文
摘要:The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone was a trap, and he tried desperately to get out of this maze.The maze was a rectangle with sizes N b
阅读全文
摘要:在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的:有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少?已经告诉你了,这是个DP的题目,你能AC吗?Input输入数据首先包括一个整数C,表示测试实例的个数,每个测试实例的第一行是一个整数N...
阅读全文
摘要:Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in th...
阅读全文
摘要:今年暑假不AC?”“是的。”“那你干什么呢?”“看世界杯呀,笨蛋!”“@#$%^&*%...”确实如此,世界杯来了,球迷的节日也来了,估计很多ACMer也会抛开电脑,奔向电视了。作为球迷,一定想看尽量多的完整的比赛,当然,作为新时代的好青年,你一定还会看一些其它的节目,比如新闻联播(永远不要忘记关心国家大事)、非常6+7、超级女生,以及王小丫的《开心辞典》等等,假设你已经知道了所有你喜欢看的电视节目的转播时间表,你会合理安排吗?(目标是能看尽量多的完整节目)Input输入数据包含多个测试实例,每个测试实例的第一行只有一个整数n(n<=100),表示你喜欢看的节目的总数,然后是n行
阅读全文
摘要:FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean.The warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and requires F[i] pounds of cat food. FatMouse does not have to trade for all the JavaBeans in
阅读全文
摘要:给你n个整数,请按从大到小的顺序输出其中前m大的数。Input每组测试数据有两行,第一行有两个数n,m(0//比用快排做快了200Ms#include #include inta[1000001];intmain(){ //freopen("in.txt","r",stdin); intn,m,k; while(scanf("%d%d",&n,&m)!=EOF) { memset(a,0,sizeof(a)); while(n--) { scanf("%d",&k); a[k+500000]
阅读全文
摘要:当n为3时,我们在验证xxx定律的过程中会得到一个序列,3,5,8,4,2,1,将3称为关键数,5,8,4,2称为覆盖数。现在输入n个数字a[i],根据关键数与覆盖数的理论,我们只需要验证其中部分数就可以确定所有数满足xxx定律,输出输入的n个数中的关键数。如果其中有多个关键数的话按照其输入顺序的逆序输出。Input输入数据包含多个用例,每个用例首先包含一个整数n,然后接下来一行有n个整数a[i],其中:1#include #include using namespacestd;boolh[200000];intmain(){ intn,m,i,k,a[503],b[503]; while(s
阅读全文
摘要:As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here comes a problem, there is only one railway where all the trains stop. So all
阅读全文
摘要:#include #include #include #include #include #include using namespace std;int main(){queue Q;stack S;int i;for(i=1;i M //例如 queue Q,q,、、查看是否为空范例 M.empty() 是的话返回1,不是返回0;从已有元素后面增加元素 M.push()输出现有元素的个数 M.size()显示第一个元素 M.front()显示最后一个元素 M.back()清除第一个元素 M.pop()入栈,如例:s.push(x);出栈,如例:s.pop();注意,出栈操作只是删除栈顶元.
阅读全文
摘要:愚人节的礼物四月一日快到了,Vayko想了个愚人的好办法——送礼物。嘿嘿,不要想的太好,这礼物可没那么简单,Vayko为了愚人,准备了一堆盒子,其中有一个盒子里面装了礼物。盒子里面可以再放零个或者多个盒子。假设放礼物的盒子里不再放其他盒子。用()表示一个盒子,B表示礼物,Vayko想让你帮她算出愚人指数,即最少需要拆多少个盒子才能拿到礼物。Input本题目包含多组测试,请处理到文件结束。每组测试包含一个长度不大于1000,只包含'(',')'和'B'三种字符的字符串,代表Vayko设计的礼物透视图。你可以假设,每个透视图画的都是合法的。Outpu
阅读全文
摘要:在进行堆排序之前必须知道堆的性质。堆分为大根堆和小根堆,我们只说下大根堆,小根堆其实和大根堆没多大区别:ki>=k(2i)且ki>=k(2i+1)(1≤i≤ n),当然,这是大根堆,小根堆则换成//堆排序#include #include #define swap(x,y) {int t=x;x=y;y=t;}#define N 10int len;void kph(int *a,int n)//堆的性质维护{ //该函数实现前提是:以节点n的左右孩子为根的二叉树是堆 int k=n,l,r; l=k*2; r=l+1; if(ra[k]) { swap(a[k],a[l]); k
阅读全文
摘要:归并(Merge)排序法是将两个(或两个以上)有序表合并成一个新的有序表,即把待排序序列分为若干个子序列,每个子序列是有序的。然后再把有序子序列合并为整体有序序列。如 设有数列{6,202,100,301,38,8,1} 初始状态: [6] [202] [100] [301] [38] [8] [1] 比较次数 i=1 [6 202 ] [ 100 301] [ 8 38] [ 1 ] 3 i=2 [ 6 100 202 301 ] [ 1 8 38 ] 4 i=3 [ 1 6 8 38 100 202 301 ] 4 总计: 11次#include #include #define...
阅读全文
摘要:程序一:#include #include #define M 10001 //看完程序后想想这个M干嘛用的,可以去看看哈希算法噢#define N 10int main(){ int a[N],b[M]; int i,n; memset(b,0,sizeof(b)); for(i=0;i#include #define M 10001#define N 10int main(){ int a[N],b[M]; int i,n; memset(b,0,sizeof(b)); for(i=0;i=0;i--) a[b[i]--]=i+1; for(i=1;i<=N;i++) printf(
阅读全文
摘要:快排,据说是平均情况下最好的排序了,算法比较好实现,快排的关键是确定轴的位置,我这里用的轴是在末尾的。 有关快排的资料可以看http://baike.baidu.com/view/19016.htm根据上图的算法思想(我觉得这种最好写代码了,呵呵)#include #define N 10#define swap(x,y) {int t=x;x=y;y=t;}void qs(int l,int r,int *a){ if(l>=r) //这是递归的出口 return; int i=l,j; for(j=l;j<r;j++) if(a[j]<a[r])//每次都是和最后那个比较
阅读全文
摘要:#include #define N 10int main(){ int a[N]; int i,j,temp; for(i=0;i#define N 10int main(){ int a[N]; int i,j,temp,flag;//添加了一个flag标志 for(i=0;i#define N 10#define swap(x,y) {int t=x;x=y;y=t;}int main(){ int a[N]; int i,j,flag=1; for(i=0;i#define N 10#define swap(x,y) {int t=x;x=y;y=t;}int main(){ ...
阅读全文
摘要:插入排序,就像好多书上讲的像抓牌时将刚抓的新牌插入手里已经排好序的牌。a数组像牌堆,b数组像已经抓到我们手里的牌#include #define N 10 //这里是定义要排序的数目int main(){ int a[N],b[N]; //定义数组,a数组用来存输入的数,b数组用来存排序的结果 int i,j; for(i=0;ia[i])//这里作比较大小(b数组从小到大排) { b[j]=b[j-1];//这里就是后移操作,毕竟是计算机,插入数据前还是要先让出空间的。 j--; } b[j]=a[i]; } for(i=0;i#define N 10int main(){ int a[N]
阅读全文
摘要:从去年开始接触ACM,作为一位大一新生,找到了自己的大学方向,因为觉得对算法很有兴趣。于是就开始自学算法了! 不过学算法前还是的会一门语言的,学校里给我们(软件)专业安排的是C++语言,到了2012年才开始了自己的算法之路。 记得去年参加了杭电的百校菜鸟杯,貌似是第84名,当时基本不会什么算法,只是通过在杭电上做题,然后看别人的代码,学习。一点的系统性都没有,就感觉是看到啥学些啥(基本上是比较简单的),到了寒假,带了本算法书回家看,怎么说呢,有时就是看的云里雾里,无奈之下就把C语言学了下。 到了这个学期开学,就开始真的算法学习之路了,在百度找了许多的算法,看到算法书上介绍的,把自己能看懂的学.
阅读全文