上一页 1 ··· 4 5 6 7 8 9 10 下一页
摘要: 杭电1874View Code 1 //1874畅通工程续 2 #include<stdio.h> 3 #include<string.h> 4 #define Max 10005 5 int f[Max][Max]; 6 int main() 7 { 8 int n,m,i,j,k,min,x,y,z,a,b; 9 while(scanf("%d%d",&n,&m)!=-1)10 {11 for(i=0;i<n;i++)12 for(j=0;j<n;j++)13 f[i][j]=Max;14 ... 阅读全文
posted @ 2012-07-18 14:26 zlyblog 阅读(99) 评论(0) 推荐(0)
摘要: 北大oj1182rank[x]=0 表示节点x与father[x]为同类1 表示节点x吃father[x]2表示x被father[x]吃向量的思考模式AB=rank[a],CB=rank[c];BC=-rank[c];a与c的关系为rank[a]-rank[c];判断两个节点点a, b的关系. (1)如果ra != rb,说明a, b暂时没有关系,那么关于他们的判断都是正确的,然后合并这两个子树。这里是关键,如何合并两个子树使得合并后的新树能保证正确呢?( 将a所在的子树合并到b上)s表示 a与b的关系 s=rank[a]+rank[f1]-rank[b] rank[f1]= s-rank[a 阅读全文
posted @ 2012-07-17 20:23 zlyblog 阅读(204) 评论(0) 推荐(0)
摘要: 杭电1233本题首先要判断两个村庄距离是否最短,其次,两村庄是否联通,即其根结点是否相同;方法是将有联系的村庄编号存为数组,将其距离存为对应值,找出不同根结点之间的最小距离,然后相加,得出需建的最短公路;View Code 1 //杭电1233 2 //C++提交 3 #include<stdio.h> 4 #include<string.h> 5 #define Max 65535 6 int n; 7 int f[101][101],set[101]; 8 void power() 9 {10 int i,j,min=f[1][1],k=0,x=1,y=1,totl 阅读全文
posted @ 2012-07-17 10:42 zlyblog 阅读(310) 评论(0) 推荐(0)
摘要: 小希的迷宫View Code 1 //杭电1272 2 #include <stdio.h> 3 #include <string.h> 4 5 #define N 100005 6 int father[N],leftt[N],rightt[N]; 7 int find(int x) 8 { 9 if(father[x]==-1)10 return x;11 else12 return find(father[x]);13 }14 void unionset(int x,int y)15 {16 father[y]=x;17 }18 int main(... 阅读全文
posted @ 2012-07-16 20:25 zlyblog 阅读(184) 评论(0) 推荐(0)
摘要: 从字符串中找出数字,并排序输出View Code 1 //1106排序 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 int cmp(const void *a,const void *b) 6 { 7 return *(int *)a-*(int *)b; 8 } 9 int main()10 {11 int a[1001],i,j,k,l,w;12 char s1[1001],s2[1001];13 while(gets(s1))14 {15 l=strlen... 阅读全文
posted @ 2012-07-16 10:57 zlyblog 阅读(239) 评论(0) 推荐(0)
摘要: f(x)=5*x^13+13*x^5+k*a*x=x(5*x^12+13*x^4+k*a),这个函数的形式直接就是费马小定理的形式费马小定理是数论中的一个重要定理,其内容为: 假如p是质数,且(a,p)=1,那么 a^(p-1) ≡1(mod p) 假如p是质数,且a,p互质,那么 a的(p-1)次方除以p的余数恒等于1对f(x)=x(5*x^12+13*x^4+k*a)用此定理分析:(1)如果x是65的倍数,那么已经符合65整除f(x)(2)如果x是5的倍数,只要5*x^12+13*x^4+k*a被13整除即可,去掉13的倍数13*x^4,也即5*x^12+k*a被13整除,由费马小定理,5 阅读全文
posted @ 2012-07-14 15:07 zlyblog 阅读(890) 评论(0) 推荐(2)
摘要: (转载)觉得很不错View Code 1 /*优先队列*/ 2 3 //Memory Time 4 //376K 516MS 5 6 #include<iostream> 7 using namespace std; 8 9 int cmp(const void* a,const void* b)10 {11 return *(int*)a-*(int*)b;12 }13 14 int main(void)15 {16 int n;17 while(cin>>n)18 {19 __int64 * w=new __int64[n+1... 阅读全文
posted @ 2012-07-14 09:48 zlyblog 阅读(149) 评论(0) 推荐(0)
摘要: View Code 1 //杭电1028Ignatius and the Princess III 2 /* 3 4 = 4; 4 4 = 3 + 1; 5 4 = 2 + 2; 6 4 = 2 + 1 + 1; 7 4 = 1 + 1 + 1 + 1; 8 9 Sample Input10 411 1012 2013 14 15 Sample Output16 517 4218 62719 */20 #include<stdio.h>21 int num[121][121] = {0};22 int q(int m,int n)23 {24 if(m == 0)m =... 阅读全文
posted @ 2012-07-13 19:21 zlyblog 阅读(203) 评论(0) 推荐(0)
摘要: View Code 1 //杭电1297Children’s Queue 2 //关于大整数加法 3 #include<stdio.h> 4 #include<string.h> 5 6 char* add(char* s1,char* s2)//用指针定义变量 7 { 8 int len1,len2,i,j,k,p; 9 int a[1009],b[1009];10 int max;11 char s3[1009];12 len1=strlen(s1);13 len2=strlen(s2);14 max=len1;15 if... 阅读全文
posted @ 2012-07-11 11:36 zlyblog 阅读(274) 评论(0) 推荐(0)
摘要: View Code 1 //1284钱币兑换问题 2 //用1分 2分 3分 3 #include<stdio.h> 4 int main() 5 { 6 int n,j; 7 __int64 sum; 8 while(scanf("%d",&n)!=-1) 9 { sum=0;10 for(j=0;j<=n/3;j++)11 sum+=(n-j*3)/2+1;12 printf("%I64d\n",sum);13 }14 return 0;15 } 阅读全文
posted @ 2012-07-11 11:08 zlyblog 阅读(186) 评论(0) 推荐(0)
上一页 1 ··· 4 5 6 7 8 9 10 下一页