
hdu
文章平均质量分 57
ehi11
这个作者很懒,什么都没留下…
展开
-
hdu Bomb 按位DP
/*就是求一个数中出现49的概率。dp[1][2][3][4]。1表示当前枚举到的位数。2表示当前位上的数字。3表示对应的状态。4是判断枚举的时候有没有超过数的上限。。就是判断上限的时候要注意一下即可。*/#include #include typedef long long LL;LL dp[100][10][3][2];char a[100];int main(){原创 2012-08-08 22:18:22 · 568 阅读 · 0 评论 -
确定比赛名次 hdu 拓扑输出字典序最小解
#include #include const int maxn=501;int map[maxn][maxn];int in[maxn];int ans[maxn];int main(){ int n,m,u,v; while(scanf("%d%d",&n,&m)==2) { memset(in,0,sizeof(in));原创 2012-08-28 16:00:56 · 1015 阅读 · 0 评论 -
Legal or Not 拓扑加邻接表 hdu
#include #include #include #include using namespace std;const int maxn=101;struct edge{ int from,to,next;} e[maxn<<1];int head[maxn];int in[maxn];int n,t,m;bool topsort(){ queue原创 2012-08-28 14:40:37 · 651 阅读 · 0 评论 -
Minimum Transport Cost hdu 点权和边权的最短路+输出字典序最小的路径
/*可以用path来记录前驱结点或者是后继结点。而对于输出最小的字典序必须要记录后继结点。主要是path记录路径方法的应用。而对于点权,可以直接进行加处理。然后一遍floyd即可。*/#include #include const int maxn=101;int map[maxn][maxn];int cost[maxn];int path[maxn][maxn];int ma原创 2012-08-28 22:29:42 · 1616 阅读 · 0 评论 -
tarjan hdu How far away ? 2586
#include #include struct edge{ int to,next,w;};int n,m,t,h;edge q[40001<<1],rq[401];//q存的是原数组,rq存的是询问数组。int head[40001],head1[40001],dis[40001],f[40001];//dis表示当前节点到跟节点的距离。bool vis[40001];原创 2012-09-14 22:06:47 · 571 阅读 · 0 评论 -
Redundant Paths poj&hoj 割边 tarjan
/*题意就是至少加多少条边,使得任意两点间至少有两条不同的路。求双连通分量。然后统计叶子个数,即入度为1的点的个数,然后ans=(num+1)/2.在求双连通分量的过程中low值相等的是在同一个分量里。不需要用stack来进行保存。*/#include #include #include using namespace std;const int maxm=10001;cons原创 2012-09-16 09:51:18 · 644 阅读 · 0 评论 -
Crazy Tea Party hoj poj 数学题
/*首先考虑一个没有成环的序列,从1 2 3 4 ... n 转移成 n ... 3 2 1的状态需要 n*(n-1)/2.即可以这样考虑,把1转移到最后端需要相邻调换n-1次,再把2转移到1右端需要n-2次。一次类推,总次数为1+2+3+...+n-1=n*(n-1)/2.现在再考虑成环的情况,即可以在中间选一个点,将环拆成两条链,自然是取中点,即N/2,*/#include int原创 2012-09-18 23:05:00 · 669 阅读 · 0 评论 -
Go hdu 4158 hoj 简单搜索
/*搜索中状态加入队列时就要立即更新标志,不能出队的时候更新,否则中间有部分状态会重复搜索造成错误。*/#include #include #include #include using namespace std;int map[21][21];bool vis[21][21];int dx[4]= {1,-1,0,0};int dy[4]= {0,0,-1,1};in原创 2013-01-23 21:36:33 · 1080 阅读 · 0 评论 -
Myacm Triangles hoj,poj,uva 计算几何
123原创 2012-09-05 07:22:20 · 697 阅读 · 0 评论 -
Number Sequence hdu 构造矩阵乘法
/*题目所给的a,b和f的初始值很重要。一次来确定矩阵的元素和幂。[a b1 0]×[f(n−1)f(n−2)]=[f(n)f(n−1)][a b1 0]n−2×[11]=[f(n)f(n−1)]因为f[1]=1,f[2]=1,所以递推到n-2次幂,间接矩阵为1,1.如果初始条件改变的话,次幂也间接矩阵也会随之改变。要灵活应用。*/#include #include const原创 2012-09-22 09:00:28 · 924 阅读 · 0 评论 -
A Simple Math Problem hdu 1757
#include #include #include using namespace std;typedef long long LL;LL tmp[11][11],a[11][11],b[11][11];int mod;void mul(LL a[][11],LL b[][11]){ for(int i=0; i<10; i++) for(int j=0;原创 2013-02-27 11:00:29 · 929 阅读 · 0 评论 -
How many ways?? hdu 2157
#include #include #include using namespace std;int tmp[21][21],ans[21][21],b[21][21];int N;void mul(int a[][21],int b[][21]){ memset(tmp,0,sizeof(tmp)); for(int i=1; i<=N; i++)原创 2013-02-27 11:01:24 · 923 阅读 · 0 评论 -
Fibonacci hdu 1568
#include #include #include #include #define c (sqrt(5.0)+1.0)/2.0using namespace std;int main(){ int f[40]; f[0]=0; f[1]=1; for(int i=2; i<=20; i++) f[i]=f[i-1]+f[i-2];原创 2013-02-27 11:03:14 · 616 阅读 · 0 评论 -
多校 4686 Arc of Dream hdu 矩阵解
构造矩阵如下:Ai*bi AX*BX AX*BY AY*BX AY*BY 0 a(i-1)*b(i-1)Ai 0 AX 0 AY 0 a(i-1)Bi原创 2013-08-20 18:09:31 · 1274 阅读 · 1 评论 -
Factstone Benchmark hoj 数学题
/*题意是求满足n!<2^bit的最大n。只能题意太特么晦涩了。然后可以转化一下。1*2*3...*n<2*2*2...*2.则循环2^bit次。n=(2^bit)/(n-1)!。每步运算的时候,满足sum>k,就k++,将sum/=k。*/#include #include #include int main(){ int n; while(scanf("%d",原创 2012-09-04 22:38:02 · 686 阅读 · 0 评论 -
Power of Cryptography 数学题 注意double能表示的最大范围
/*整型 int -2*10^9 ~ 2*10^9单精度型 float -3.4*10^38 ~ 3.4*10^38双精度型 double -1.7*10^308 ~ 1.7*10^308*/#include #include int main(){ double n,x; while (scanf("%l原创 2012-09-04 22:33:47 · 699 阅读 · 0 评论 -
hdu Max Sum of Max-K-sub-sequence 单调队列优化DP
/*求一个环的连续最大子段和。并且输出该最大字段和的和,启示位置和终止位置。s[i]-s[j]课表示任意最大字段和。当枚举i的时候,只需要求出此时最小的s[j]即可。此时可以维护一个单调上升的队列。每次取队首元素即可为s[j]的最小值。*/#include #include #define maxn 200001struct node{ int num,id; nod原创 2012-08-09 09:39:55 · 1553 阅读 · 0 评论 -
Rotational Painting hdu 好的计算几何题!!
/*一道很好的计算几何题啊。题目是求一个多边形能稳定摆放有多少种方式。这道题知道是考查重心。但是一开始没有思路,特别是对凹多边形。原来可以先出重心。然后再求凸包。将所有的四边形补成凸的。这样每一条边就对应着一种放法。然后只要判断重心和这条边的两个角是否为锐角即可。*/#include #include #include #include #define maxn 50001usi原创 2012-08-13 22:00:41 · 628 阅读 · 0 评论 -
hdu 迷宫城堡 极大强连通分量的tarjan算法模板题
/*极大强连通分量的tarjan算法模板题。*/#include#include #include using namespace std;struct EDGE{ int to,next;} e[100005]; //边结点数组int head[10010],stack[10010],DFN[10010],Low[10010],Belong[100010];/原创 2012-08-15 23:10:52 · 1806 阅读 · 0 评论 -
hdu 过山车 二分匹配模板
#include #include bool map[501][501];bool vis[501];int match[501];int n,m;//注意,定义在主函数里的变量在main函数里面不能再定义。否则就失效,按0来计算!bool find(int x)//寻找A可能匹配的点集合{ for(int i=1; i<=m; i++)//m为待匹配集的个数 {原创 2012-08-16 10:33:33 · 573 阅读 · 0 评论 -
A Plug for UNIX 最大流
/*题意就是给了你m个电器,n个插头,tt个转换器,以及自己增加一个虚拟的源点和汇点。将转换器和插头相连的边置为无穷大。其余的边长度都置为1.该模板中n表示图中节点的总数。最后要记得修改。还有一点需要注意的就是转换不是只有样例中给出的'X,可能有无数个,无数种类型。在这里借鉴了一种网上map的写法。很简介。下面这个网址给了一张图很详细。一看便知http://www.cnblogs.com/lo原创 2012-08-20 08:24:04 · 816 阅读 · 0 评论 -
Power Network 最大流基础 hoj
/*题意中给出多个节点和多个发电站与消费站。可以建一个虚拟的源点和虚拟的汇点,将所有的发电站和源点连一条边,将所有的消费占和汇点连一条边。然后利用网络流建图即可。下面是SAP算法。*/#include #include #include #define SETZR(a) memset(a,0,sizeof(a))using namespace std;const int MAXM =原创 2012-08-20 08:18:29 · 695 阅读 · 0 评论 -
Sightseeing trip floyd求最小环
/*无向图的最小环问题: 无向图的最小环的求法不可能和有向图的求法一样, 因为在有向图中i 到j 和 j 到i 算是一个环,但在无向图中不是一个环,如果直接用flody算法将会出错, 有向图的环可以为2个顶点,而无向图的环至少要三个顶点; 所以为了求无向图的最小环, 我们采用的原理是: 枚举最大环中的连接点,更新环的权重;比普通Floyd多出来的部分,主要利用到的原理是当处理到k时,所有以原创 2012-08-30 22:30:44 · 1313 阅读 · 0 评论 -
The Bottom of a Graph 强连通分量加缩点
/*题意比较晦涩,大致就是求一个图缩点后出度为0的点的个数。*/#include #include #include #include using namespace std;vector e[5010];int dfn[5001];int low[5001];int stack[5001];bool instack[5001];int belong[5001];int原创 2012-08-20 08:52:51 · 1408 阅读 · 1 评论 -
Visible Lattice Points 欧拉函数应用
/*根据题意。如果该点是不可见的。则必定经过整数点。也就是非互质。相反,如果是可见的,那么必定是互质的。则题目转为求1-n内的互质点对数。即为求1-ai(i:1-n)内的欧拉函数值。可现在1-n的范围内用递推打表生成欧拉函数值。*/#include const int maxn=1001;int phi[maxn];void get_phi()//获取1-maxn范围内的欧拉函数表{原创 2012-08-22 22:27:53 · 1370 阅读 · 0 评论 -
Calculation 快速幂
/*本来是稍有复杂的数学题。第一次用快速幂取模果断超时,最后将表打出,找规律。水过之,代码很短。*/#include int main(){ int a,b; while(scanf("%d%d",&a,&b)==2) { int ans=0; int sum=0; if(a%2==0) {原创 2012-08-22 22:40:32 · 543 阅读 · 0 评论 -
Divisors 欧拉函数的应用
#include #include #define mm 500bool fuck[mm];int wokao[mm][100];long long ca[mm][mm];int p[100];int main(){ int t=0,x,n; memset(fuck,0,sizeof(fuck)); fuck[0]=fuck[1]=0; for(in原创 2012-08-23 07:51:25 · 1640 阅读 · 0 评论 -
Calculation 2 欧拉函数的应用
/*题意是求和n不互质的数的总和。可用总和1-(n-1)减去互质的数的总和。课用欧拉函数求1-n的互质的数的个数num。则若a和n互质,n-a必定也和n互质(a<n)。也就是说num必定为偶数。其中互质的数成对存在。其和为n。则总和为num*n/2 */#include int phi(long long n){ int rea=n; for(int i=2;i*i<=原创 2012-08-23 07:55:49 · 1757 阅读 · 0 评论 -
Relatives 欧拉函数基础
#include int phi(int n){ int rea=n; for(int i=2;i*i<=n;i++) if(n%i==0) { rea=rea-rea/i; do n/=i; while(n%i==0); } if(n>1) rea=rea-rea/n;原创 2012-08-22 22:18:45 · 1183 阅读 · 0 评论 -
最远曼哈顿距离小结 poj 2926 Requirements&hdu 4666 Hyperspace
首先对于两点(x1,y1),(x2,y2)二维的曼哈顿距离为|x1-x2|+|y1-y2|将绝对值去掉,再将同一点的坐标归于一处可得四种情况:1.x1-x2+y1-y2->(x1+y1)-(x2+y2)2.x2-x1+y1-y2->(-x1+y1)-(-x2+y2)3.x1-x2+y2-y1->(x1-y1)-(x2-y2)4.x2-x1+y2-y1->(-x1-y1)-(-x2-y2)原创 2013-08-14 11:31:49 · 1751 阅读 · 0 评论