04 2012 档案
摘要:题意: 给你一个DNA序列,求其逆序数。分析: 直接模拟即可。View Code #include<stdio.h>#include<string.h>#include<stdlib.h>struct node{ int xu,ni;}q[101];int cmp(const void*p1,const void*p2){ struct node* c=(node*)p1; struct node* d=(node*)p2; return c->ni-d->ni;}char s[102][55];int n,m;int re(char *s){
阅读全文
摘要:题意: 有 n 条鱼,雄的会攻击他认为是雌的鱼,一条鱼一旦被攻击,就会生下一定数量的孩子,每条鱼只能被攻击一次, 问最后最多可以生下多少孩子。分析: 因为每条鱼只能被攻击一次,正好符合二分图的性质,此题只要找出完全匹配下的最优匹配即可。模板一:View Code #include<stdio.h>#include<string.h>#define INF 0x1f1f1f1fint sx[101],sy[101];int lx[101],ly[101];char a[102][102];int map[102][102];int link[101];int va[101
阅读全文
摘要:题意: 告诉你有 N 湖是,并告诉你和每个湖相连湖的个数,问你能否找到一种可能的连通方式。分析: 问题的目的就是看看能否重建这个连通图,可以用Havel算法Havel算法的思想简单的说如下:(1)对序列从大到小进行排序。(2)设最大的度数为 t ,把最大的度数置0,然后把最大度数后(不包括自己)的 t 个度数分别减1(意思就是把度数最大的点与后几个点进行连接)(3)如果序列中出现了负数,证明无法构成。如果序列全部变为0,证明能构成,跳出循环。前两点不出现,就跳回第一步!举例说明:4 4 3 3 2 2第二步后0 3 2 2 1 2排完续后3 2 2 2 1 0第二步后0 1 1 1 1 0排完
阅读全文
摘要:题意: 给你一个二叉树,如图:给你一个节点,输出以这个节点为根的最小值和最大值。分析: 经观察可以发现,叶子节点是连续的的奇数,所以只要找到所给节点的数的区间上最小奇数和最大奇数即可。View Code #include<stdio.h>int main(){ int t,n,min,max,lowbit; scanf("%d",&t); while(t--) { scanf("%d",&n); lowbit=(n)&(-n); // 取最后一个 1 min=n-(lowbit-1); // 取得个该区间上的最小奇数。
阅读全文
摘要:题意: 给你一个 n 个人的队列,从中去掉一些人使剩下的人满足 任何一个人可以看到他 至少一侧的所有人。分析: 从前往后 和 从 后往前分别 求一次LIS,然后枚举分割点。View Code #include<stdio.h>#include<string.h>int main(){ int res,n,i,j,tmp; double a[1002]; int dp1[1002]; int dp2[1002]; while(scanf("%d",&n)!=EOF) { for(i=1;i<=n;i++) scanf("%l..
阅读全文
摘要:题意: 给你 n 个绳子,从里面选出任意根绳子,求最大承受力, 当承受力大的和小的放在一起时,每个绳子的承受力和小的一样,分析: 先对绳子排序,然后求出以每个绳子为最小承受力的绳子的最大值。View Code #include<stdio.h>#include<stdlib.h>int cmp(const void*p1,const void*p2){ return *(int*)p1-*(int*)p2;}int a[10005];int main(){ int t,n,i; scanf("%d",&t); while(t--) { sca
阅读全文
摘要:题意: 给你一个 含有 n 个珠子的项链,规定只有相邻的珠子才能合到一起并得到能量,合到一起的到的新的珠子,可以和其相邻的珠子继续合成,前后次序没有要求, 问你最大能的到多大的能量;分析 :用 dp[i][j]来表示从 i 到 j 合成得到的最大能量,则状态转移方程为 dp[i][j]=max(dp[i][j],dp[i][k]+dp[k][j]+a[i].left*a[k].right*a[j].right) 通过枚举 I 和 J 的分割点来得到 dp[i][j]的最大值。View Code #include<stdio.h>#include<string.h>#de
阅读全文
摘要:题意: 给你个n*n 的位图,让你放大k 倍后输出。分析: 最终图案的每一部分都是有原图相应位置扩大而来,可以用递归实现。View Code #include<stdio.h>#include<math.h>#include<string.h>char a[30][30];char v[3005][3005];int n;void dfs(int k,int x,int y){ int tmp,i,j,tot,l; if(k==1) { for(i=x;i<x+n;i++) for(j=y;j<y+n;j++) ...
阅读全文
摘要:题意: 给你两个字符串,让你找出第一个字符串的头部和第二个字符串尾部重合的部分,并尽可能的长,例如 aasdfs bdevaa 答案为 aa 2分析: 利用 KMP 算法得到的 next 函数的特点,把两字符串连到一起,找出头部和尾部重合的部分。View Code #include<stdio.h>#include<string.h>char s1[50005];char s2[50005];int next[100010];int len1,len2,len;void get(){ int i=0,j=-1; next[0]=-1; while(i<len) {
阅读全文
摘要:题意:给你一个字符串,要求将字符串的全部字符最少循环2次需要添加的字符数。分析: next 数组的巧用。View Code #include<stdio.h>#include<string.h>int next[100005];char b[100005];int len;void get(){ int i=0,j=-1; next[0]=-1; while(i<len) { if(j==-1||b[i]==b[j]) next[++i]=++j; else j=next[j]; }}int main(){ int ...
阅读全文
摘要:题意: 一个字符串,从头到某个位置,字符串的前缀最多重复了多少次。转一相关讲解:kmp next函数 kmp的周期问题,深入了解kmp中next的原理----------------------------------------------k m x j i由上,next【i】=j,两段红色的字符串相等(两个字符串完全相等),s[k....j]==s[m....i]设s[x...j]=s[j....i](xj=ji)则可得,以下简写字符串表达方式kj=kx+xj;mi=mj+ji;因为xj=ji,所以kx=mj,如下图所示------------- -----------...
阅读全文
摘要:题意: 一共有 n 个任务, m 台机器, 知道了每个机器处理每个任务的时间,一个任务只有在处理完之后才能处理其他任务,问你最少需要多少时间, 才能做完所有的任务。分析: 以 任务为 X 集合 第 i 个任务在第 j 台机器 倒数第 k 个完成为 Y 集合,找到完全匹配下的最小权匹配,此题构图方法依然是 拆点。View Code #include<stdio.h>#include<string.h>#define INF 0x1f1f1f#define clr(x)memset(x,0,sizeof(x))int sx[55],sy[2550];int lx[55],l
阅读全文
摘要:分析: 和 poj 1840很像,用poj 的方法跑了960多毫秒,用 lzsz1212 大牛的方法跑了 200多毫秒View Code #include<stdio.h>#include<string.h>int h[2000000];const int di=1000000;int main(){ int p[101]; int i,j,a,b,c,d,sum; for(i=1;i<=100;i++) p[i]=i*i; while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF) {
阅读全文
摘要:题意: 给你一个包含 n 个城市的距离,并告诉你其中的一些路的距离,让你用一些环去覆盖所有点,且每个点只能覆盖一次,问环的最小城市多少。分析:每个点只出现一次,而每一个点对应一个入的边和一个出的边,可以将入边放入 X 集合, 出边放入 Y 集合,二分该图,求其完全匹配下的最小权值 匹配。View Code #include<stdio.h>#include<string.h>#define INF 0x1f1f1f#define clr(x)memset(x,0,sizeof(x))int sx[202],sy[202];int lx[202],ly[202];int
阅读全文
摘要:题意: 给你一个图HH. .m. . . . .. . . . .. . . . .mm. .Hm代表人 H 代表房子,一个人只能进一个房子,问你如何安排人进房,使得总步数最小。分析: 可以用最小费用最大流,也可以用二分图最优匹配。#include<stdio.h>#include<string.h>#define min(a,b)(a)<(b)?(a):(b)#define INF 0x1f1f1f#define maxn 105#define clr(x)memset(x,0,sizeof(x))int abs(int x){ return x>0?x:
阅读全文
摘要:题意: 给你 n 个 男的 ,m 女的,男的之间都是相互认识的,女的同样,告诉你一些男女关系,让你找出最多的人使其中任意一个人都相互认识。分析: 同上一题。。。/*独立集:任意两点都不相连的顶点的集合独立数:独立集中顶点的个数完全子图:任意两点都相连的顶点的集合最大完全数:最大完全子图中顶点的个数最大完全数=原图的补图的最大独立数最大独立数=顶点数-最大匹配数这样,就可以求出最大完全数完全图G就是指图G的每个顶点之间都有连边。这样,令完全图G的阶|G|=N,那么完全图G具有如下性质:1.图G有(N-1)*N/2条边。2.图G上的生成树有N^(N-2)种。3.★图G的补图G'中没有边。由
阅读全文
摘要:题意: 给你 n 个人,和四个条件,两个人只要满足其中任意一个条件就不能成为夫妻, 问从中最多能找出多少人使得他们任意两个人都不可能成为夫妻。分析: 二分图最大独立权集,把男的放到一个集合 ,女的放到另一个几何,二分该图, 如果两个人能成为夫妻,则他们构成一个匹配,找出最大匹配,最大独立全集即为 总人数 - 最大匹配View Code #include<stdio.h>#include<string.h>#define clr(x)memset(x,0,sizeof(x))struct node{ int to,next;}q[200005];int head[505]
阅读全文
摘要:题意: 告诉你 Q 格街区,一共有 M d 个任务分布在这Q 个街区里面,知道了每个任务的开始时间和需要一个人的完成时间, 问最少需要派多少人才能做完所有的任务。分析: 求二分图的最小路径覆盖,分两种情况 ① 两个第 I 个任务和 第 J g个任务在同一街区,如果满足 t[i]+d[i]<=t[j] 那么两个任务构成一个匹配, 即第I 个任务和 第J 个任务可由同一个人先后完成, ②两个任务在不同街区,如果满足 t[i]+d[i]+dis[i][j]<=t[j],那么两任务亦构成一个匹配。 求出最大匹配,最小路径覆盖即为m - 最大匹配 其中每个点之间的最短路径可...
阅读全文
摘要:题意: 给你一个农场 例如*.*..******...*. 其中 *代表障碍物, . 代表空地,你可以用宽度为1 长度不限的木板去覆盖这些障碍,木块可以重叠,问你最少需要多少木块 可以把所有 * 覆盖掉。分析: 二分图最小点权覆盖,这道题建图比较特别,之前的 POJ 3041 是一次覆盖一行或一列,可以 把行看成 X集合, 把列看成是 Y 集合,进行二分图匹配,但是这题每一行或每一列的 障碍物可能是不连续的, 所以要把同一行的各个连续的障碍段分开进行建图,可以把每一行或每一列连续的一段标记成同一个序号,每一个点看成是行这一段的障碍和列这一段障碍的边, 建立关系,最后求...
阅读全文
摘要:题意: 给你一个 n*m 的方格,但是里面有些地方是有洞的,问你能否用1 X 2 的板砖铺满空白的地方, 例如:分析: 二分图匹配,关键在于建图,以奇数格(i+j)%2==1 为一个集合,以偶数格为另一个集合,因为任意一个铺设都是有一个奇数格和一个偶数格构成的, 最后如果匹配的个数是空白格数的一半,即完全匹配,说明能够铺满。View Code #include<stdio.h>#include<string.h>#define clr(x)memset(x,0,sizeof(x))struct node{ int to,next;}q[1000000];int head
阅读全文
摘要:DescriptionProfessor Leyni likes to play with LOLIs and he has a lot of LOLIs to manage.For easy management, Leyni numbered them from 1 to n, then arranged some leading relationships between them, such as, x leads y.This relationship is transitive (i.e. if x is the leader of y, y leads z, and then x
阅读全文
摘要:题意: 给你 n 个机器,m 头牛,每台机器最多可供 cap 头牛使用,并告诉你每个物体之间的距离,找出一个距离满足所有的牛都分配到机器且里面走最远的牛 走的距离最小。分析: 用 floyd 计算出每个物体的最短距离,然后二分枚举距离,如果在该距离下满足完全匹配,该距离即为合法距离,匹配用到多重匹配。二分图多重匹配 #include<stdio.h>#include<string.h>#define clr(x)memset(x,0,sizeof(x))int cap;int link[33][202];int vlink[33];int v[33];struct no
阅读全文
摘要:题意: 有 n 牛, m 个 房子, 每个牛都只住在自己想住的房子里面,一个房子只能住一个牛,问最多可以安排多少头牛入住。分析: 求最大匹配。View Code #include<stdio.h>#include<string.h>#define clr(x)memset(x,0,sizeof(x))struct node{ int to,next;}q[40005];int tot;int head[202];void add(int s,int u){ q[tot].to=u; q[tot].next=head[s]; head[s]=tot++;}int link
阅读全文
摘要:题意: 给你N 个球,如果两个球球有重叠部分的话就称这两个球是联通的 ,如果两个球不想交,可以在他们之间建立一个桥梁,使其联通,问最少需要建多少长度的桥梁才能是全部的球联通。分析: 图建好后就是最小生成树问题。View Code #include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>int u[5005],v[5005],f[103],r[5005];double w[5005];int cmp(const void*p1,const void*p2){ retu
阅读全文
摘要:题意:给你n 个学生 p 个课程,每一个课程都有一定的学生会选,能否找出p 个学生使他们满足每个学生选的课都不同。分析:看看能否找到一个完全匹配的二分图。View Code #include<stdio.h>#include<string.h>#define clr(x)memset(x,0,sizeof(x))struct node{ int to,next;}q[100000];int head[103];int tot;void add(int s,int u){ q[tot].to=u; q[tot].next=head[s]; head[s]=tot++;}i
阅读全文
摘要:题意: 两台机器,有 k 个工作,每个工作可以在 a 机器的 P模式或在 b 机器的 q 模式下解决,两台机器初始状态为 0 模式,每台机器没变换一次模都要重启一次, 问至少重启多少次可以完成所有工作。分析: 构图方式 if(x*y!=0) g[x][y]=1; 求出最小点覆盖,即找到最少的点来覆盖所有的边。View Code #include<stdio.h>#include<string.h>#define clr(x)memset(x,0,sizeof(x))struct node{ int to,next;}q[100000];int head[102];int
阅读全文
摘要:题意: 给你一些课程和他们的上课时间,求在不冲突的情况下最多能上几节课。分析: 裸的二分图。View Code #include<stdio.h>#include<string.h>#define clr(x)memset(x,0,sizeof(x))struct node{ int to,next;}q[10000000];int tot;int head[303];void add(int s,int u){ q[tot].to=u; q[tot].next=head[s]; head[s]=tot++;}int link[303];int v[100];int f
阅读全文
摘要:Description搞ACM不能只局限于看书和刷题,还要把它用到实际工作中,更是要把平时所学用到实际生活中去。下面就是动态规划的经典运用!你追一个MM的时候,需要对该MM身边的各闺中密友都好,这样你追MM这个问题就分解为对其MM朋友的问题,只有把这些问题都解决了,最终你才能追到MM。 该方法适用于聪明的MM,懂得“看一个人,不是看他如何对你,而是看他如何对他人。”的道理,并且对付这样的MM总能得到最优解。 该方法的缺点是开销较大,因为每个子问题都要好好对待。。。。 (如果是MM追GG,可以直接AC。) 所以,需要先把MM的朋友处理好,才能获得最终解。 GG需要获得MM朋友的好感,这样才有利于
阅读全文
摘要:Problem DescriptionYou, the leader of Starship Troopers, are sent to destroy a base of the bugs. The base is built underground. It is actually a huge cavern, which consists of many rooms connected with tunnels. Each room is occupied by some bugs, and their brains hide in some of the rooms. Scientist
阅读全文
摘要:DescriptionThe 15-puzzle has been around for over 100 years; even if you don't know it by that name, you've seen it. It is constructed with 15 sliding tiles, each with a number from 1 to 15 on it, and all packed into a 4 by 4 frame with one tile missing. Let's call the missing tile '
阅读全文
摘要:【题目描述】一个众所周知的事实,在每一慧星后面是一个不明飞行物UFO。这些不明飞行物时常来收集来自在地球上忠诚的支持者。不幸地,他们的飞碟在每次旅行只能带上一定数目的支持者。 他们要做的是用一种聪明的方案让每一个团体人被慧星带走。他们为每个慧星起了一个独有名字,通过这些名字来决定一个团体是不是特定的慧星带走。 那个相配方案的细节在下面被给出;你的工作要写一个程序来通过团体的名字和彗星的名字来决定一个组是否应该与在那一颗慧星后面的不明飞行物搭配。团体的名字和慧星的名字都以下列各项方式转换成一个数字: 这个最后的数字代表名字中所有字母的信息,"A" 是1 和 "Z&q
阅读全文
摘要:Description给出一个有向带权图G,针对该图有如下的两种操作:(1)标记该图的一个点(2)找到两点间的只通过已标记点的最短路径长度输入:输入包括多组测试,每组测试中第一行包括三个整数N,M,Q,N表示图中的节点数量,N<=300,M表示边的数量,M<=100000;Q表示执行多少次操作,Q<=100000,所有点被编号为0,1,2,...,N-1,最初所有的点都是未标记的,接下来M行每行包括三个整数x,y,c,表示从x到y有一条边长度为c,c>0,然后为Q行,每行表示一次操作,0 x表示将点x标记,1 x y表示查找x到y的只通过已标记点的最短路径长度,N=M=
阅读全文
摘要:DescriptionConsider equations having the following form:a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0The coefficients are given integers from the interval [-50,50].It is consider a solution a system (x1, x2, x3, x4, x5) that verifies the equation, xi∈[-50,50], xi != 0, any i∈{1,2,3,4,5}.Determine how many sol
阅读全文
摘要:Problem DescriptionA school bought the first computer some time ago(so this computer's id is 1). During the recent years the school bought N-1 new computers. Each new computer was connected to one of settled earlier. Managers of school are anxious about slow functioning of the net and want to kn
阅读全文
摘要:DescriptionLeyni喜欢机器人,这次,他得到了一个机器人,这个机器人能接受两种命令,"T"(向后转),"F"(前进一步)。他还得到了一个用于控制这个机器人的指令序列,他计划恰好修改k次这个指令序列(一次只能修改其中一个指令,同一个指令也可以被反复修改)后让机器人去执行,并使这个机器人最终停下的位置离起点尽量远。他想知道这个机器人最终停下的位置离起点的最远距离,请你帮助他!Input本题有多组测试数据,输入的第一行是一个整数T代表着测试数据的数量,接下来是T组测试数据。对于每组测试数据:第1行 包含一个长度不超过100的仅由"T&qu
阅读全文
摘要:Description设有N*N的方格图(N<=10),我们将其中的某些方格中填入正整数,而其他的方格中则放人数字0。如下图所示(见样例 ,黄色和蓝色分别为两次走的路线,其中绿色的格子为黄色和蓝色共同走过的):A1367142141514B某人从图的左上角的A点出发,可以向下行走,也可以向右走,直到到达右下角的B 点。在走过的路上,他可以取走方格中的数(取走后的方格中将变为数字0)。此人从A点到B点共走两次,试找出2条这样的路径,使得取得的数之和为最大。Input有多组测试数据,每组格式如下: 第一行为一个整数N(表示N*N的方格图),接下来的每行有三个整数,前两个表示位置,第三个数为该
阅读全文
摘要:DescriptionLeyni经过了若干年的征战,终于建立了自己的国家,这个国家包含n个城市,编号为1到n,而且这些城市之间存在m条双向通行的道路。不过Leyni的国家刚刚建立,所以他对每一条道路定义了道路警戒级别,由高到低分别为,a级,b级,c级。接下来,每条路径的路径警戒级别就等于这条路径所经过的所有道路的最高警戒级别;每两个城市之间的城际警戒级别就等于这两个城市之间的所有路径中的最低路径警戒级别。现在,Leyni告诉了你所有道路的道路警戒级别,他想知道某些城市之间的城际警戒级别,请你帮助他!Input本题有多组测试数据,输入的第一行是一个整数T代表着测试数据的数量,接下来是T组测试数据
阅读全文
摘要:Description给定一个有权图的每两个节点间的最短路径长度,判断能否找到原图。Input输入包括多组测试,每组测试的第一行为一个整数N,N<=100,表示图中有N个节点,然后是N行,每行有N个整数,第i行的第j个整数k表示从i节点到j节点的最短路径距离为k,k<1000000.Output对于每组测试数据,如果能够找到原图,则输出构成原图所需要的最少边数,否则输出“impossible“。Sample Input30 1 11 0 11 1 030 1 34 0 27 3 030 1 41 0 24 2 0Sample Output64impossibleView Code
阅读全文
摘要:Description教授Leyni喜欢跟罗莉一起玩,这次,XianGe也来了,他们处在一个r*c的矩形区域中。Leyni处在矩形区域的入口外(左上角左侧),XianGe处在矩形区域的出口外(右下角右侧),罗莉处在矩形区域内。现在Leyni要喊话给XianGe,可是声音在这个矩形区域内只能横向或者垂直传递,而且,如果某个罗莉听到了声音(听到声音的罗莉不会阻碍声音继续传播),Leyni可以命令她作为传递者向四周传递一次声音,使得与她同一行同一列的罗莉都能听到声音(如下图右侧情况);当然,Leyni也可以让听到声音的罗莉不传递(如下图左侧情况);Leyni处在入口(左上角)的左侧,所以他只能向第一
阅读全文
摘要:DescriptionJimmy experiences a lot of stress at work these days, especially since his accident made working difficult. To relax after a hard day, he likes to walk home. To make things even nicer, his office is on one side of a forest, and his house is on the other. A nice walk through the forest, se
阅读全文
摘要:DescriptionSuppose there is a tree named A. All nodes of A have a weight v(0<v<4000000).Now, we will give the definition of "Prime Node".A node is a Prime Node if the following conditions are satisfied.The subtree of A whose root node is b will be marked as B. If all nodes in B have
阅读全文
摘要:DescriptionUnit Fraction is a special fraction.For example,1/2 , 1/3 and so on are Unit Fractions, as their numerator is 1 and denominator is the positive integer greater than 1.The ancient Greeks worship this type fraction.They think that everything in the world can be measured by the Unit Fraction
阅读全文
摘要:Problem descriptionThe best friends Mr. Li and Mr. Liu are touring in beautiful country M.M has n cities and m two-way roads in total. Each road connects two cities with fixed length.We assume that the cost of car traveling on the road is only related to the length of road,the longer road the more m
阅读全文
摘要:DescriptionBoss xnby owns a company, as you know, in the company there are lots of jobs to do.Each job J has a processing requirementpj(denoting the number of machine days required to complete the job), a release date rj(representing the beginning of the day when job j becomes avalible for processin
阅读全文
摘要:Problem DescriptionNetwork flow is a well-known difficult problem for ACMers. Given a graph, your task is to find out the maximum flow for the weighted directed graph.InputThe first line of input contains an integer T, denoting the number of test cases.For each test case, the first line contains two
阅读全文
摘要:Problem DescriptionIn 2100, since the sea level rise, most of the cities disappear. Though some survived cities are still connected with others, but most of them become disconnected. The government wants to build some roads to connect all of these cities again, but they don’t want to take too much m
阅读全文
摘要:POJ推荐50题1. 标记 难 和 稍难 的题目大家可以看看,思考一下,不做要求,当然有能力的同学可以直接切掉。2. 标记为 A and B 的题目是比较相似的题目,建议大家两个一起做,可以对比总结,且二者算作一个题目。3. 列表中大约有70个题目。大家选做其中的50道,且每类题目有最低数量限制。4. 这里不少题目在 BUPT ACM FTP 上面都有代码,请大家合理利用资源。5. 50个题目要求每个题目都要写总结,养成良好的习惯。6. 这50道题的规定是我们的建议,如果大家有自己的想法请与我们 Email 联系。7. 建议使用 C++ 的同学在 POJ 上用 G++ 提交。8. 形成自己编写
阅读全文
摘要:Problem DescriptionThe Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentlessly, so the large road network is too expensive to maintain. The Council of Elders must
阅读全文
摘要:Input输入数据首先包含一个正整数N,表示测试实例的个数,然后是N行数据,每行包括三个正整数A,B,C。Output对每个测试实例请输出计算后的结果,每个实例的输出占一行。Sample Input3 2 3 4 3 3 5 4 4 6Sample Output0 2 4code:View Code #include<stdio.h>int mod;int fu(long long a,long long b){ long long ans=1,m=a; while(b) { if(b&1) ans=(ans*m)%mod; ...
阅读全文
摘要:Problem Description在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt。但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店到赛场的路线,你可以帮助他们吗?Input输入包括多组数据。每组数据第一行是两个整数N、M(N<=100,M<=10000),N表示成都的大街上有几个路口,标号为1的路口是商店所在地,标号为N的路口是赛场所在地,M则表示在成都有几条路。N=M=0表示输入结束。接下来M行,每行包括3个整数A,B,C(1<=A,B<=N,1<=C<=1000),表示在
阅读全文
摘要:DescriptionYou have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.InputInput consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message
阅读全文
摘要:DescriptionCc is a lovely monkey. It likes to play the game "catching plates".The game is as follows.There are n pegs in a line numbered from 1 to n. Cc stands on the first peg at the beginning. It is rather hard for Cc to jump from peg i to peg i+1(i+1<=n) or peg i-1(i-1>=1), which
阅读全文
摘要:Description俗话说“月有阴晴圆缺,人有悲欢离合。”。虽然大家都没这么悲催,但是心情的波动在所难免。MM的心情也会有波动,心情好心情值就高,心情不好心情值就低,每个小时都不一样,GG想知道MM最长的上升心情值的子序列,这样GG才好。。。按时间先后给出n个小时的心情值e[i],GG要求一个最长的子序列,使得该子序列e1< e2<e3<e4..<ek,并且使得e1+e2+e3+..+ek的和最大。Input有多组数据,对于每组数据,第一行是一个整数n(<=1000),接下来有n个整数ei。Output每组数据输出一行,该行包含两个数,表示最长子序列的长度和子序
阅读全文
摘要:Problem Description假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26。那么,对于给定的字母,可以找到多少价值<=50的单词呢?单词的价值就是组成一个单词的所有字母的价值之和,比如,单词ACM的价值是1+3+14=18,单词HDU的价值是8+4+21=33。(组成的单词与排列顺序无关,比如ACM与CMA认为是同一个单词)。Input输入首先是一个整数N,代表测试实例的个数。然后包括N行数据,每行包括26个<=20的整数x1,x2,.....x26.Output对于每个测试实例,
阅读全文
摘要:Problem Description2007年到来了。经过2006年一年的修炼,数学神童zouyu终于把0到100000000的Fibonacci数列(f[0]=0,f[1]=1;f[i] = f[i-1]+f[i-2](i>=2))的值全部给背了下来。接下来,CodeStar决定要考考他,于是每问他一个数字,他就要把答案说出来,不过有的数字太长了。所以规定超过4位的只要说出前4位就可以了,可是CodeStar自己又记不住。于是他决定编写一个程序来测验zouyu说的是否正确。Input输入若干数字n(0 <= n <= 100000000),每个数字一行。读到文件尾。Out
阅读全文
摘要:Problem Description妈妈你别哭泪光照亮不了我们的路让我们自己慢慢的走妈妈我会记住你和爸爸的模样记住我们的约定来生一起走上面这首诗节选自一位诗人纪念遇难同胞的作品,并没有华丽的语言,但是每位读者都应该能感受到作品传达的浓浓爱意,也许还有丝丝无奈。确实,太多的关于孩子不幸的报道冲击着我们每一颗柔弱的心。正如***总理所说“多难兴邦”,这场灾难让我们很多80后的年轻人一下子成熟了起来,其中很多人以自愿者的身份走上了抗震救灾的第一线。今天,灾区又来了n位志愿者,抗震救灾指挥部需要将他们分为若干个小组,小组的数量不限,但是要求每个小组的人数必须为素数,请问我们有几种分组的方法呢?特别说
阅读全文
摘要:Description将整数n分成k份,且每份不能为空,任意两份不能相同(不考虑顺序)。例如:n=7,k=3,下面三种分法被认为是相同的。1,1,5; 1,5,1; 5,1,1;问有多少种不同的分法。Input有多则测试数据。对于每组测试数据,仅有一行,包括两个整数n,k (6<n<=200,2<=k<=6)。Output对于每组测试数据,输出一个整数,即不同的分法。Sample Input7 3Sample Output4Hint输入: 7 3输出:4 {四种分法为:1,1,5; 1,2,4; 1,3,3; 2,2,3;}分析:此题和母函数①的不同之处在于划分数目是固
阅读全文
摘要:Problem Description开学了,杭电又迎来了好多新生。ACMer想为新生准备一个节目。来报名要表演节目的人很多,多达N个,但是只需要从这N个人中选M个就够了,一共有多少种选择方法?Input数据的第一行包括一个正整数T,接下来有T组数据,每组数据占一行。每组数据包含两个整数N(来报名的人数,1<=N<=30),M(节目需要的人数0<=M<=30)Output每组数据输出一个整数,每个输出占一行Sample Input53 25 34 43 68 0Sample Output310101方法一: 为防止溢出,可以采用乘一个除一个的方法。View Code #
阅读全文
摘要:Problem DescriptionTo improve the organization of his farm, Farmer John labels each of his N (1 <= N <= 5,000) cows with a distinct serial number in the range 1..20,000. Unfortunately, he is unaware that the cows interpret some serial numbers as better than others. In particular, a cow whose s
阅读全文
摘要:Problem DescriptionIn many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryption, etc. In this problem you are given a number, you have to determine the number of digits in the factorial of the number.InputInput c
阅读全文
摘要:DescriptionIn 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following conjecture:Every even number greater than 4 can bewritten as the sum of two odd prime numbers.For example:8 = 3 + 5. Both 3 and 5 are odd prime numbers.20 = 3 + 17 =
阅读全文
摘要:要求: 输入正整数n,(2<=n<=100)把阶乘分解成素数因子相乘的形式,从小到大输出各个素数的指数。sample input:523sample output:5!=3 1 153!=49 23 12 8 4 4 3 2 2 1 1 1 1 1 1 1code:View Code #include<stdio.h>#include<string.h>//素数判定int isprime(int n){ if(i%2==0&&i!=2) return 0;for(i=2;i*i<=n;i++) if(n%i==0) return 0;
阅读全文
摘要:Problem DescriptionThe digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits are summed and the process is repeated. This is cont
阅读全文
摘要:Problem DescriptionIgnatius is poor at math,he falls across a puzzle problem,so he has no choice but to appeal to Eddy. this problem describes that:f(x)=5*x^13+13*x^5+k*a*x,input a nonegative integer k(k<10000),to find the minimal nonegative integer a,make the arbitrary integer x ,65|f(x)ifno exi
阅读全文
摘要:Problem DescriptionWe all know that Bin-Laden is a notorious terrorist, and he has disappeared for a long time. But recently, it is reported that he hides in Hang Zhou of China! “Oh, God! How terrible! ”Don’t be so afraid, guys. Although he hides in a cave of Hang Zhou, he dares not to go out. Laden
阅读全文
摘要:Problem DescriptionPeople in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (=17^2), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 289-credit coins, are available in Silverland
阅读全文
摘要:Problem Description"Well, it seems the first problem is too easy. I will let you know how foolish you are later." feng5166 says."The second problem is, given an positive integer N, we define an equation like this:N=a[1]+a[2]+a[3]+...+a[m];a[i]>0,1<=m<=N;My question is how man
阅读全文
摘要:Problem Description1,2,...,n表示n个盘子.数字大盘子就大.n个盘子放在第1根柱子上.大盘不能放在小盘上.在第1根柱子上的盘子是a[1],a[2],...,a[n]. a[1]=n,a[2]=n-1,...,a[n]=1.即a[1]是最下面的盘子.把n个盘子移动到第3根柱子.每次只能移动1个盘子,且大盘不能放在小盘上.问第m次移动的是那一个盘子.Input每行2个整数n (1 ≤ n ≤ 63) ,m≤ 2^n-1.n=m=0退出Output输出第m次移动的盘子的号数.Sample Input63 1 63 2 0 0Sample Output1 2分析:从 移动看出
阅读全文
摘要:Problem Description据说在很久很久以前,可怜的兔子经历了人生中最大的打击——赛跑输给乌龟后,心中郁闷,发誓要报仇雪恨,于是躲进了杭州下沙某农业园卧薪尝胆潜心修炼,终于练成了绝技,能够毫不休息得以恒定的速度(VR m/s)一直跑。兔子一直想找机会好好得教训一下乌龟,以雪前耻。最近正值HDU举办50周年校庆,社会各大名流齐聚下沙,兔子也趁此机会向乌龟发起挑战。虽然乌龟深知获胜希望不大,不过迫于舆论压力,只能接受挑战。比赛是设在一条笔直的道路上,长度为L米,规则很简单,谁先到达终点谁就算获胜。无奈乌龟自从上次获胜以后,成了名龟,被一些八卦杂志称为“动物界的刘翔”,广告不断,手头也有
阅读全文
摘要:Problem DescriptionAs we know, Big Number is always troublesome. But it's really important in our ACM. And today, your task is to write a program to calculate A mod B.To make the problem easier, I promise that B will be smaller than 100000.Is it too hard? No, I work it out in 10 minutes, and my
阅读全文
摘要:Problem DescriptionThere are many students in PHT School. One day, the headmaster whose name is PigHeader wanted all students stand in a line. He prescribed that girl can not be in single. In other words, either no girl in the queue or more than one girl stands side by side. The case n=4 (n is the n
阅读全文
摘要:Problem DescriptionIn a Lotto I have ever played, one has to select 6 numbers from the set {1,2,...,49}. A popular strategy to play Lotto - although it doesn't increase your chance of winning - is to select a subset S containing k (k>6) of these 49 numbers, and then play several games with ch
阅读全文
摘要:Problem DescriptionThe Really Neato Calculator Company, Inc. has recently hired your team to help design their Super Neato Model I calculator. As a computer scientist you suggested to the company that it would be neato if this new calculator could convert among number bases. The company thought this
阅读全文
摘要:Problem DescriptionThe annual Games in frogs' kingdom started again. The most famous game is the Ironfrog Triathlon. One test in the Ironfrog Triathlon is jumping. This project requires the frog athletes to jump over the river. The width of the river is L (1<= L <= 1000000000). There are n
阅读全文
摘要:DescriptionA TV-network plans to broadcast an important football match. Their network of transmitters and users can be represented as a tree. The root of the tree is a transmitter that emits the football match, the leaves of the tree are the potential users and other vertices in the tree are relays
阅读全文
摘要:题意:有 n个人想移居到m 个星球,知道了每个人可以移居前往的星球和每个星球的人口容量,问是否所有人都能够成功迁移。分析: 二分图多重匹配。View Code #include<stdio.h>#include<string.h>int cap[12]; //cap[i] 表示i点的匹配上限 int map[100002][12];int vlink[12]; //vlink[i] 表示i点当前的匹配数 int link[12][100002]; //li...
阅读全文
摘要:Problem DescriptionWhile studying the history of royal families, you want to know how wealthy each family is. While you have various 'net worth' figures for each individual throughout history, this is complicated by double counting caused by inheritance. One way to estimate the wealth of a f
阅读全文
摘要:DescriptionBob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he has the following problem. He must defend a medieval city, the roads of which form a tree. He has to put the minimum number of soldiers on t
阅读全文
摘要:DescriptionLet us define a regular brackets sequence in the following way: 1. Empty sequence is a regular sequence. 2. If S is a regular sequence, then (S) and [S] are both regular sequences. 3. If A and B are regular sequences, then AB is a regular sequence. For example, all of the following sequen
阅读全文
摘要:Recently, researchers on Mars have discovered N powerful atoms. All of them are different. These atoms have some properties. When two of these atoms collide, one of them disappears and a lot of power is produced. Researchers know the way every two atoms perform when collided and the power every two
阅读全文
摘要:Problem DescriptionThere are N cities in the country. Each city is represent by a matrix size of M*M. If city A, B and C satisfy that A*B = C, we say that there is a road from A to C with distance 1 (but that does not means there is a road from C to A).Now the king of the country wants to ask me som
阅读全文
摘要:Problem DescriptionAfter coding so many days,Mr Acmer wants to have a good rest.So travelling is the best choice!He has decided to visit n cities(he insists on seeing all the cities!And he does not mind which city being his start station because superman can bring him to any city at first but only o
阅读全文


浙公网安备 33010602011771号