上一页 1 ··· 6 7 8 9 10 11 12 下一页
摘要: Find Function Optimization:After Path compression:int find(int x){ return root[x] == x ? x : (root[x] = find(root[x]));}Avoid Stack overflow:int fi... 阅读全文
posted @ 2014-04-23 20:42 Jeremy Wu 阅读(244) 评论(0) 推荐(0)
摘要: 跟小希的迷宫基本一样,只是此题是有向图,要注意:1无环 2只有一个入度为0的结点(根结点),不存在入度大于1的结点。输入结束条件是两个负数,而不是-1,不然会TLE。 1 #include 2 #define NUM 23 3 int root[NUM], visit[NUM], lu[NUM]; ... 阅读全文
posted @ 2014-04-23 20:11 Jeremy Wu 阅读(211) 评论(0) 推荐(0)
摘要: 提醒:答案要约分,不然会错! 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 const int MAXSIZE = 2000000;10 int prime[MAXSIZE];11 void init_prim(){12 for (int i=2;i<MAXSIZE;i++)13 prime[i]=1;14 prime[0]=0; prime[1]=0;15 for (int i=1;i<MAXSI... 阅读全文
posted @ 2014-04-10 20:54 Jeremy Wu 阅读(213) 评论(0) 推荐(0)
摘要: #include#include#include#include#include#includeusing namespace std;int main(){ char a[10][6] = {"Jia", "Yi", "Bing", "Ding", "Wu", "Ji", "Geng", "Xin", "Ren" , "Gui"}; char b[12][6] = {"zi" 阅读全文
posted @ 2014-04-09 20:38 Jeremy Wu 阅读(181) 评论(0) 推荐(0)
摘要: 解题思路:找规律,不难的,打表坑的地方在于题目限定条件and the seed value for G(1) is a random integer t, (t>=1)虽然都用粗体表示出来了= = 但我还是没注意到 = =#include#include#include#includeusing namespace std;int main(){ int numCase , i ,j ,t ,G; long long b[30]; int array[30]; array[0] = 0; array[1] = 1; for(i = 2 ; i = 1){ ... 阅读全文
posted @ 2014-04-09 19:36 Jeremy Wu 阅读(145) 评论(0) 推荐(0)
摘要: 判断两点:1.任何2点的父节点不能相同->否则会导致2点间有多条通路2.所有点只有1个集合存在一个小坑,就是第一次输入 0 0 的时候,应该输出 Yes , 否则会WAMY AC Code : 1 #include 2 #define NUM 100001 3 int root[NUM], visi... 阅读全文
posted @ 2014-04-08 19:53 Jeremy Wu 阅读(432) 评论(0) 推荐(0)
摘要: 解题思路转自:http://blog.csdn.net/azheng51714/article/details/8500459http://blog.csdn.net/acresume/article/details/7461238有一个体育馆,座位呈环状,想象下,貌似体育馆都是这样的,每一列有30... 阅读全文
posted @ 2014-04-08 15:41 Jeremy Wu 阅读(397) 评论(0) 推荐(0)
摘要: 意思是把一行字符串的长度按照找7位一个字节输出,如果长度能够存在7位里,字节的最高位置0,否则只输出7位并且输出字节的最高位置1,直到全部输出长度.要注意的是有空串要输出00,其他按照16进制输出就可以了,注意要补0. 1 #include 2 #include 3 using namespace std; 4 char a[3000008]; 5 int main(){ 6 int T; 7 scanf("%d", &T); 8 getchar(); 9 while(T--){10 gets(a);11 int len = ... 阅读全文
posted @ 2014-04-07 15:30 Jeremy Wu 阅读(269) 评论(0) 推荐(0)
摘要: 参考自:http://blog.csdn.net/niushuai666/article/details/6973134/*遇到素数需要打表时,先估算素数的个数:num = n / lnx;num为大概数字,越大误差越小(只是估计,用于估算素数表数组大小)这个打表法效率貌似很高,网上说几乎达到了线性时间(不知道是真是假=。=)*/#include#include#include#include#includeusing namespace std;const int MAXSIZE = 10100000;int n;bool visit[MAXSIZE];int prime[MAXSIZE]; 阅读全文
posted @ 2014-04-07 10:22 Jeremy Wu 阅读(202) 评论(0) 推荐(0)
摘要: 首先学习一下lower_bound()函数lower_bound()在first和last中的前闭后开区间进行二分查找,返回大于或等于val的第一个元素位置。如果所有元素都小于val,则返回last的位置举例如下:一个数组number序列为:4,10,11,30,69,70,96,100.设要插入数字3,9,111.pos为要插入的位置的下标则pos = lower_bound( number, number + 8, 3) - number,pos = 0.即number数组的下标为0的位置。pos = lower_bound( number, number + 8, 9) - number 阅读全文
posted @ 2014-04-07 10:17 Jeremy Wu 阅读(270) 评论(0) 推荐(0)
摘要: 题目大意:给你一个有向图,一个起点集合,一个终点,求最短路。。。。解题思路:1.自己多加一个超级源点,把起点集合连接到超级源点上,然后将起点与超级源点的集合的路径长度设为0,这样就称为一个n+1个点的单源最短路算法。 1 #include 2 #include 3 4 int map[1005][1005]; 5 int n; 6 7 int Dijkstra(int s,int e){ 8 bool done[1005]; 9 int d[1005];10 memset(done,0,sizeof(done));11 for(int i = 0;i <... 阅读全文
posted @ 2014-04-05 15:22 Jeremy Wu 阅读(351) 评论(0) 推荐(0)
摘要: 并查集的应用,用来查找被分割的区域个数。即当两个节点值相同时说明已经为了一个圈,否则不可能,此时区域个数加1. 1 #include 2 #include 3 #include 4 using namespace std; 5 const int maxn=1010; 6 int n,m; 7 int root[maxn]; 8 9 int find(int a){10 while(root[a]!=a){11 a=root[a];12 }13 return a;14 }15 16 int main(){17 while(EOF != scan... 阅读全文
posted @ 2014-04-05 14:28 Jeremy Wu 阅读(244) 评论(0) 推荐(0)
摘要: STL__queue_的应用调用的时候要有头文件: #include 或 #include + #include 详细用法:定义一个queue的变量 queue que 查看是否为空范例 que.empty() 是的话返回1,不是返回0;从已有元素后面增加元素(入队) que.push() 现有元素的个数 que.size()显示第一个元素 que.front()显示最后一个元素 que.back()清除第一个元素 (出队) que.pop() 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define ... 阅读全文
posted @ 2014-04-05 11:22 Jeremy Wu 阅读(246) 评论(0) 推荐(0)
摘要: WA了好几次最后找到错因是因为数组开小了! = =string whose length never exceeds 20所以至少要开到21 = = ,我却一直开20 ╮(╯▽╰)╭AC代码: 1 #include 2 #include 3 int main(){ 4 int t,n,i,j,flag; 5 char target[21],name[110][21]; 6 scanf("%d",&t); 7 while(t--){ 8 scanf("%d%s",&n,target); 9 for(i=0;i<n;i++)10 ... 阅读全文
posted @ 2014-04-04 22:34 Jeremy Wu 阅读(250) 评论(0) 推荐(0)
摘要: http://blog.csdn.net/ffq5050139/article/details/7832991http://blog.watashi.ws/1944/the-8th-zjpcpc/http://blog.csdn.net/crescent__moon/article/details/16801097 1 #include 2 #include 3 const int Max=100003; 4 double t[Max],p[Max],lev[Max]; 5 double max(double a,double b){ 6 return a>b?a:b; 7 } 8 i. 阅读全文
posted @ 2014-04-03 20:26 Jeremy Wu 阅读(329) 评论(0) 推荐(0)
摘要: 解题思路:找到公共子串然后升序输出坑的地方就在于输入是存在相同字母的 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define MIN( x, y ) ( (x) < (y) ? (x) : (y) ) 7 #define INF 0x7fffffff 8 #define KIND 26 9 #define MAXN 1210 using namespace std;11 12 char str[MAXN];13 int hash[KIND], ans[KIND];14 15 int main(){16 ... 阅读全文
posted @ 2014-04-03 16:35 Jeremy Wu 阅读(388) 评论(0) 推荐(0)
摘要: Modular InverseTime Limit:2 Seconds Memory Limit:65536 KBThe modular modular multiplicative inverse of an integeramodulomis an integerxsuch thata-1≡x(modm). This is equivalent toax≡1 (modm).InputThere are multiple test cases. The first line of input is an integerT≈ 2000 indicating the number of test 阅读全文
posted @ 2014-04-02 22:52 Jeremy Wu 阅读(301) 评论(0) 推荐(0)
摘要: DaveTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 2768Accepted Submission(s): 926Problem DescriptionRecently, Dave is boring, so he often walks around. He finds that some places are too crowded, for example, the ground. He couldn't... 阅读全文
posted @ 2014-04-01 16:57 Jeremy Wu 阅读(174) 评论(0) 推荐(0)
摘要: The kth great numberTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 6121Accepted Submission(s): 2471Problem DescriptionXiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming can choose to write down a number, or ask Xiao Bao 阅读全文
posted @ 2014-04-01 16:56 Jeremy Wu 阅读(294) 评论(0) 推荐(0)
摘要: 以下资料来自:http://blog.csdn.net/Dinosoft/article/details/6795700http://qianmacao.blog.163.com/blog/static/203397180201222945212647/http://blog.csdn.net/qinmusiyan/article/details/7950642#HDU 1850 Being a Good Boy in Spring Festival下面是一个二人小游戏:桌子上有M堆扑克牌;每堆牌的数量分别为Ni(i=1…M);两人轮流进行;每走一步可以任意选择一堆并取走其中的任意张牌;桌子上 阅读全文
posted @ 2014-03-31 20:09 Jeremy Wu 阅读(429) 评论(0) 推荐(0)
摘要: 以下资料摘自 http://www.cnblogs.com/wally/archive/2012/07/13/hdu1028_1085_1171_.html生成函数是说,构造这么一个多项式函数g(x),使得x的n次方系数为f(n)。对于母函数,看到最多的是这样两句话:1.“把组合问题的加法法则和幂级数的乘幂对应起来。”2.“把离散数列和幂级数一 一对应起来,把离散数列间的相互结合关系对应成为幂级数间的运算关系,最后由幂级数形式来确定离散数列的构造。 “例子:有1克、2克、3克、4克砝码各一枚,问能称出哪几种重量?每种重量各有几种方案?下面是用母函数解决这个问题的思路:首先,我们用X表示砝码,X 阅读全文
posted @ 2014-03-30 20:59 Jeremy Wu 阅读(381) 评论(1) 推荐(0)
摘要: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3324http://blog.csdn.net/xymscau/article/details/6776182 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 const int INF=1000100000; 9 struct node{10 int x,y;11 }n[1010];12 bool cmp(node a,node ... 阅读全文
posted @ 2014-03-26 21:57 Jeremy Wu 阅读(412) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2546http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=3361http://blog.sina.com.cn/s/blog_5123df350100e8p8.htmlhttp://blog.sina.com.cn/s/blog_51cea4040100gvn3.htmlhttp://blog.csdn.net/wukonwukon/article/details/6939050搬寝室Problem Description搬寝室 阅读全文
posted @ 2014-03-24 21:53 Jeremy Wu 阅读(646) 评论(0) 推荐(0)
摘要: 终于开始DP了】HDOJ_1159 Common Subsequence题目链接Sample Inputabcfbc abfcabprogramming contest abcd mnp Sample Output 4 2 0子结构特征:lf(i,j)= f(i-1,j-1)+1 (a[i]==b[j]) max(f(i-1,j),f(i,j-1)) (a[i]!=b[j])由于f(i,j)只和f(i-1,j-1), f(i-1,j)和f(i,j-1)有关, 而在计算f(i,j)时, 只要选择一个合适的顺序, 就可以保证这三项都已经计算出来了, 这样就可以计算出f(i,j).... 阅读全文
posted @ 2014-03-24 11:04 Jeremy Wu 阅读(251) 评论(0) 推荐(0)
摘要: 匈牙利算法样例程序格式说明输入格式:第1行3个整数,V1,V2的节点数目n1,n2,G的边数m第2-m+1行,每行两个整数t1,t2,代表V1中编号为t1的点和V2中编号为t2的点之间有边相连输出格式:1个整数ans,代表最大匹配数//邻接矩阵-C#include #include int n1,n... 阅读全文
posted @ 2014-03-21 22:27 Jeremy Wu 阅读(383) 评论(0) 推荐(0)
上一页 1 ··· 6 7 8 9 10 11 12 下一页