ACM-ICPC
文章平均质量分 50
Fenice
狂奔的蜗牛
展开
-
动态规划详解
1 1,13 2 2,1 2,24 10 1原创 2012-09-26 16:51:18 · 851 阅读 · 0 评论 -
大数阶乘
#include #include using namespace std;const int maxn=3000;int f[maxn];int main(){ int i,j,n; scanf("%d",&n); memset(f,0,sizeof(f)); f[0]=1; for(i=2;i<=n;i++) {原创 2012-09-17 22:51:16 · 625 阅读 · 0 评论 -
欧拉回路
有一个经典的七桥问题.是否存在一条路线,可以不重复的走过7座桥.用图论的语言改写后即为.能否从无向图的一个节点出发走出一条道路,每条边恰好经过一次.这样的路线叫做欧拉回路,俗称”一笔画”欧拉回路中进和出是对应的,除起始点外,其它点的进出次数应该相等,换句话说,除起始点外,其它店的度数都为偶数.如果一个无向图是连通的,最多有两个奇点,则一定存在欧拉回路.对于有向图,最多两个点的出度不原创 2012-09-18 19:50:52 · 2332 阅读 · 0 评论 -
poj1493
//it cannot be simple more,but notice its' input#include #include #include using namespace std;int N;int space[13];char ch;int sum;int main(){ while(cin>>N,N) { memset(spa原创 2012-09-19 17:18:00 · 689 阅读 · 0 评论 -
并查集
在一些有N个元素的集合应用问题中,我们通常是在开始时让每个元素构成一个单元素的集合,然后按一定顺序将属于同一组的元素所在的集合合并,其间要反复查找一个元素在哪个集合中。这一类问题近几年来反复出现在信息学的国际国内赛题中,其特点是看似并不复杂,但数据量极大,若用正常的数据结构来描述的话,往往在空间上过大,计算机无法承受;即使在空间上勉强通过,运行的时间复杂度也极高,根本就不可能在比赛规定的运行时间(翻译 2012-09-20 21:04:54 · 649 阅读 · 0 评论 -
hdu1009贪心
#include #include #include using namespace std;int M,N;typedef struct { float J; float F; double Aver;}room;room Rooms[3001];int Cmp(const room a,const room b){原创 2012-11-30 15:13:18 · 573 阅读 · 0 评论 -
hdu1007分治法
把所有点按x坐标的大小排序,从中间一份为二。最近点对有三种情况,都在左边,都在右边,左右都有递归求出都在左边和都在右边的情况,选一个最小值curmin。然后求出两边各有一个的情况得结果为tmp,求法请参考给个链接取tmp和curmin的最小值为结果#include #include #include #include #include using namespace std;typ原创 2012-11-30 23:37:44 · 678 阅读 · 0 评论 -
剪枝方法
搜索的进程可以看作从树根出发,遍历一颗倒置的树---搜索树的过程。所谓剪枝就是通过某种判断,避免一些不必要的遍历过程,就是剪去搜索树中的某些枝条。剪枝的原则:(1)正确性 必须保证不能丢失正确的解,这是前提。通过解答必须具备的特征,必须满足的条件来考察待判断的枝条能否被剪掉。(2)准确性 即能够尽可能多的剪去不能得到正确解的枝条。(3)高效性原创 2012-12-02 16:31:18 · 6491 阅读 · 0 评论 -
动态规划1
动态规划的有效性依赖于待求解问题本身具有两个重要的性质:最优子结构性质和自问题重叠。(1)最优字结构性质,如果问题的最优解包含的自问题的解也是最优的,就称该问题具有最优子结构性质(满足最优化原理),最优字结构性质为动态规划算法解决问题提供线索。(2)子问题重叠性质。子问题重叠性质是指在用递归算法自顶向下对问题求解时,每次产生的子问题并不总是新问题,有些自问题会被重复计算多次。动态规划正式利原创 2012-12-02 16:32:06 · 553 阅读 · 0 评论 -
hdu1003最大子序列和
看了一些别人的题解,说实话,我现在还不会证明这个,我不知道为什么这样是最大值//hdu1003最大连续子序列和// sum[i] = sum[i-1]>0 ? sum[i-1]+a[i]:a[i];//只有当sum处于增长状态时才会得到最大子序列//当sum处于减小状态时,应当更新起点 #include using namespace std;#define MAX 10000原创 2012-12-02 18:02:47 · 690 阅读 · 0 评论 -
hdu1012求e的近似值
//简单数学题#include #include using namespace std;int main() {int i;double s, sum;printf ("n e\n");printf ("- -----------\n");printf ("0 1\n");printf ("1 2\n");printf ("2 2.5\n");printf ("3 2原创 2012-12-02 18:20:21 · 950 阅读 · 0 评论 -
hdu1010搜索+剪枝
Tempter of the BoneTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 42078 Accepted Submission(s): 11382Problem DescriptionThe原创 2012-12-02 21:14:04 · 780 阅读 · 0 评论 -
Java汉诺塔
import java.util.Scanner;public class TowersofHanoi{ public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter number of原创 2012-12-02 14:53:01 · 674 阅读 · 0 评论 -
线段树
1、概述线段树,也叫区间树,是一个完全二叉树,它在各个节点保存一条线段(即“子数组”),因而常用于解决数列维护问题,它基本能保证每个操作的复杂度为O(lgN)。2、线段树基本操作线段树的基本操作主要包括构造线段树,区间查询和区间修改。(1) 线段树构造首先介绍构造线段树的方法:让根节点表示区间[0,N-1],即所有N个数所组成的一个区间,然后,把区间分转载 2012-11-18 16:39:37 · 590 阅读 · 0 评论 -
hdu1013
这题陷阱有点深啊,数字长度太大,得用字符串,开始一直WA ,不知道什么情况。。其实这个方法也是借鉴的大牛的。埃,戒浮躁才能AC #include #include using namespace std;int main(){ int n; string s; while(cin>>s&&s[0]!='0') { n=0;原创 2012-12-03 21:03:46 · 700 阅读 · 0 评论 -
hdu1002
简单大数,纠结了很久,PE若干次,最后不能留空行#include #include #include using namespace std; const int MAXN = 9999;const int DLEN = 4;const int DIGIT = 500; // 数字在该类中每四位逆序存放。// 实现了加减乘除着四个最基本的运算。// 乘法的时间复杂度为)O(n原创 2012-11-23 01:08:07 · 370 阅读 · 0 评论 -
hdu1014
暴力#includeint main(){ int s,m,i; while(scanf("%d%d",&s,&m)!=EOF) { int a[100001]={0},seed=0; while(!a[seed]) { a[seed]=1; seed=(seed+s)%原创 2012-12-06 16:07:43 · 711 阅读 · 0 评论 -
hdu 1005
//找循环周期#include #include using namespace std;int f[1000001];int main(){ int a,b,n; while(cin>>a>>b>>n) { if(a==0&&b==0&&n==0) break; f[1]=1; f[原创 2012-11-24 14:53:06 · 671 阅读 · 0 评论 -
hdu1008
//实在太水了。。。#include #include using namespace std;int main(){ int N; int CurrFloor; int DesFloor; int time; while(cin>>N,N!=0) { CurrFloor = 0; time = 0;原创 2012-11-24 22:51:58 · 1257 阅读 · 0 评论 -
hdu1037
//a+b系列水题#include using namespace std;int main(){ int A[3]; bool flag = true; int j; for(int i = 0; i < 3; i++) { cin>>A[i]; if(A[i] < 168)原创 2012-11-24 23:14:14 · 658 阅读 · 0 评论 -
hdu1042大数阶乘
#include #include using namespace std;const int maxn=50000;int f[maxn];int main(){ int i,j,n; while(scanf("%d",&n)!= EOF) {memset(f,0,sizeof(f)); f[0]=1; //先让个位为1原创 2012-12-11 13:15:13 · 508 阅读 · 0 评论 -
hdu1040水题
#include #include #include using namespace std;int F[32767];int TI;int N;int main(){ cin>>TI; while(TI--) { cin>>N; memset(F,0,sizeof(F)); for(int i =原创 2012-12-11 13:28:56 · 555 阅读 · 0 评论 -
hdu1108
#include using namespace std;int gcd(int m,int n){ if(m < n) { int temp = m; m = n; n = temp; } int x = m%n; while(x!=0) { m = n; n原创 2012-12-11 13:37:29 · 719 阅读 · 0 评论 -
hdu 1017数学水题
#include #include using namespace std;int main(){ int t,c,n,m,i,j,result; cin>>t; while(t--) { c=1; while(cin>>n>>m,!(m==0 && n==0)) { result原创 2012-12-25 01:37:27 · 594 阅读 · 0 评论 -
hdoj 1016经典问题素数环
//经典搜索题 #include #include using namespace std;int primelist[38] = {0,0,1,1,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1};//素数表, int n;int A[21]; //存放序列结果 int vis[21]原创 2012-12-25 01:15:49 · 1407 阅读 · 0 评论 -
hdu 1018
这道题我是百度的,数论一点也不会 = =#include#include#define pi 3.14159265int num,result;void JC(){ double t; t = (num*log(num) - num + 0.5*log(2*num*pi))/log(10); result = (int)t+1; printf("%d\n"原创 2012-12-26 00:32:06 · 495 阅读 · 0 评论 -
hdu1093
//a^b循环节为4#include #include using namespace std;int cal(int a,int b){ a = a%10; if( b >= 1 && b <= 4) return ((int)pow((float)a,(float)b))%10; else if(b > 4) return cal(原创 2012-12-13 10:11:50 · 782 阅读 · 0 评论 -
hdu1021
#includeint main( ){ int n; while( scanf( "%d",&n ) != EOF ) if( ( n + 2 ) % 4 == 0 ) puts( "yes" ); else puts( "no" ); return 0;}坑爹,原创 2012-12-13 17:05:42 · 820 阅读 · 0 评论 -
hdu1076顺秒
#include using namespace std;bool isLeapYear(int year){ if((year % 4 == 0 && year %100 != 0)|| year % 400 == 0) return true; else return false;}int main()原创 2012-12-13 13:11:14 · 1208 阅读 · 0 评论 -
Korsaraju算法 强连通分量
1.对原图进行DFS并将出栈顺序进行逆序,得到的顺序就是拓扑顺序 2.将原图每条边进行反向 3.按照1中生成顺序再进行DFS染色染成同色的是一个强连通块 合理性:如果是强连通子图,那么反向没有任何影响,依然是强连通子图。 但如果是单向的边连通,反向后再按原序就无法访问了(因此反向处理是对非强连通块的过滤)/*Kosaraju算法的简单演示,使用邻接矩阵储存图 */原创 2012-12-27 21:20:36 · 773 阅读 · 0 评论 -
图论-1 求连通分量
DFS框架: vector G[maxn]; int vis[maxn]; void dfs(int u) { vis[u] = 1; PREVISIT(u); int d = G[u].size(); for(int i原创 2012-12-27 01:03:21 · 2291 阅读 · 0 评论 -
hdu1015
#include #include #include #include using namespace std;int flag[100],s[100],f[5];long target;#define res(v,w,x,y,z) v-w*w+x*x*x-y*y*y*y+z*z*z*z*zint dfs(int step,int len,int n){ if(st原创 2012-12-14 23:32:01 · 1529 阅读 · 0 评论 -
hdu 1019
//注意用__int64#include #include using namespace std;__int64 N;__int64 n;__int64 gcd(__int64 a,__int64 b){ __int64 s = a*b; if(a < b) { __int64 tmp = a; a = b;原创 2012-12-27 17:58:01 · 524 阅读 · 0 评论 -
hdu1020
#include #include #include using namespace std;int T;string str;int _count[26];char cc;int main(){ cin>>T; while(T--) { cin>>str; memset(_count,0,sizeof(_count))原创 2012-12-17 11:38:43 · 560 阅读 · 0 评论 -
hdu 1049
#include using namespace std;int n,u,d;int height;int _time;int main(){ while(cin>>n>>u>>d) { if((n&&u&&d)==0) break; height = 0; _time = 0;原创 2012-12-17 00:19:05 · 687 阅读 · 0 评论 -
hdu1064只切水题
#include int main(){ float sum = 0; float aver = 0; float a; for(int i = 0; i < 12;i++) { scanf("%f",&a); sum += a; } aver = sum/12; printf("$%.2f\原创 2012-12-17 00:27:45 · 1044 阅读 · 0 评论 -
hdu 1072
#include using namespace std;int map[10][10];int _time[10][10];int step[10][10];int T,N,M;int mins;int sx,sy;int dirx[4] = {-1,0,1,0};int diry[4] = {0,1,0,-1};bool flag;void DFS(int x,in原创 2012-12-16 23:47:46 · 584 阅读 · 0 评论 -
hdu1072 BFS
#include #include #include using namespace std;int map[10][10];int sx,sy;int step[10][10];int _time[10][10];int T,N,M;int dirx[4] = {-1,0,1,0};int diry[4] = {0,1,0,-1};typedef struct{原创 2012-12-17 00:59:30 · 473 阅读 · 0 评论 -
Dijkstra算法
这是一个按路径长度递增的次序产生最短路径的算法。通过一步步求出它们之间顶点的最短路径,过程中都是基于已经求出的最短路径的基础上,求出更远点的最短路径。#define MAXVEX 9#define INFINITY 65535typedef int Pathmatrix[MAXVEX];//用于储存最短路径下标的数组typedef int ShortPathTable[MAXVEX]原创 2012-12-29 13:21:35 · 478 阅读 · 0 评论 -
hdu 1874最短路
//注意陷阱,还有,尽量不要用memset初始化二维数组#include #include #include using namespace std;#define INFINITY 100000000const int maxn = 210;int N,M;int S,T;int G[maxn][maxn];int Dist[maxn];bool final[maxn];原创 2012-12-31 00:26:21 · 448 阅读 · 0 评论