摘要: #include <stdio.h>main(){ int n; for(n=2000;n<=2500;n++) if(n%4==0&&n%100!=0||n%400==0) printf("%d是闰年\n",n); else printf("%d不是闰年\n",n);}#include <stdio.h>main(){ int m,n; for(m=1,n=2;n<=5;n++) { m*=n; } printf("%d\n",m); 阅读全文
posted @ 2011-08-11 17:24 bcy 阅读(176) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>#include<math.h>#define L 10void conversion(int N,int r){ int s[L],top; int x; top=-1; while(N) { s[++top]=N%r; N=N/r; } while(top!=-1) { x=s[top--]; printf("%d\n",x); } printf("\n");}main(){ int N,r; scanf("%d%d",&N,&r);conversion(N 阅读全文
posted @ 2011-08-11 17:19 bcy 阅读(154) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>#include<string.h>#include<stdlib.h>int N, M, set[1010];int find ( int x ) { return x==set[x]?x:set[x]= find ( set[x] ); }void Union ( int x, int y ) { int a = find (x), b = find(y); if ( a != b ) { set[a] = b; } }int main () { int a, b, x, y, sum; while ( scanf ( 阅读全文
posted @ 2011-08-11 17:17 bcy 阅读(130) 评论(0) 推荐(0) 编辑
摘要: void Swap(int& x,int& y){int temp = x;x = y;y = temp;}void quicksort(int array[], int left, int right) {//快速排序的函数(以中间的数为标准) int i, j, s; if(left < right) { s = array[(left+right)/2]; i = left - 1; j = right + 1; while(1) { while(array[++i] < s) ; while(array[--j] > s) ; if(i >= j 阅读全文
posted @ 2011-08-11 17:16 bcy 阅读(198) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>#include<string.h>#include<stdlib.h>int N, M, map[1010][1010], dis[1010], hash[1010], cnt, dp[1010];const int inf = 0x7fffffff;void Dijsktra () { dis[2] = 0; for ( int i = 1; i <= N; i++ ) { int pos, t = inf; for ( int j = 1; j <= N; j++ ) { if ( hash[j] == 0 阅读全文
posted @ 2011-08-11 17:16 bcy 阅读(136) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>#include <stdlib.h>#include <string.h>const int inf = 0x7fffffff;int st[110], rank[110], N, M, x, y, val, maxN, map[110][110];struct Edge { int x, y, val;}e[10000];int cmp ( const void *a, const void *b ) { return (( Edge * )a)->val - ( ( Edge * )b )->val; } 阅读全文
posted @ 2011-08-11 17:15 bcy 阅读(173) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>#include <string.h>#include <stdlib.h>struct T { T * ch[26]; int n, flag;}rt;char in[15];void init ( T * t ) { for ( int i = 0; i < 26; ++ i ) t->ch[i] = NULL; t->n = t->flag = 0;}void insert ( T *t, char *in ) { if ( *in ) { if ( t->ch[ *in - ' 阅读全文
posted @ 2011-08-11 17:14 bcy 阅读(118) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>int n,m,map[124][124];int inf = 0x7fffffff;void floyd( ){ for( int i = 1; i <= n; ++i ) for( int j = 1; j <= n; ++j ) for( int k = 1; k <= n; ++k ) if( map[i][j] != inf && map[i][k] != inf ) if( map[i][j] + map[i][k] < map[j][k] ) map[j][k] = map[i][j] + ma 阅读全文
posted @ 2011-08-11 17:14 bcy 阅读(122) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>#include<stdlib.h>int set[100000],b[100000];int find(int x){return (x==set[x])?x:set[x]=find(set[x]);}int main(){ int n,x,y,max,X,Y; while(scanf("%d",&n)!=EOF){ for(int i=0;i<100000;i++) { set[i]=i;b[i]=1; } for( int i=0;i<n;i++){ scanf("%d%d&quo 阅读全文
posted @ 2011-08-11 17:13 bcy 阅读(150) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>#include<stdlib.h>#include<string.h>int n,m,num[100024];int cmp( const void *a,const void *b ){ return *( int * )b - *( int * )a;}int main( ){ while( scanf( "%d%d",&n,&m ) , n | m ) { for( int i = 0; i < n; ++i ) scanf( "%d",&num[ 阅读全文
posted @ 2011-08-11 17:12 bcy 阅读(135) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>#include<stdlib.h>#include<string.h>char s1[15], s2[15];long long int abc ( char *s ) {long long int sum;int length = strlen ( s );for ( int i = 0; i < length; i++ ) { if ( s[i] == ',' ) {for ( int j = i; j < length-1 ; j++ ) { s[j] = s[j+1];} s[lengt 阅读全文
posted @ 2011-08-11 17:11 bcy 阅读(158) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>#include<stdlib.h>#define MAXSIZE 100000typedef int DataType;typedef struct{DataType data[MAXSIZE];int last;}Seqlist;Seqlist *L;void init_Seqlist(){L=(Seqlist *)malloc(sizeof(Seqlist));L->last=-1;}void va(){ int t; for(int i=0;i<=L->last/2;i++){t= L->data[i]; 阅读全文
posted @ 2011-08-11 17:10 bcy 阅读(175) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>#include<iostream.h>#define MAXSIZE 1024typedef char DataType;typedef struct{ DataType data[MAXSIZE]; int top;}SeqStack;SeqStack *s;SeqStack *Init_SeqStack(){ SeqStack *s; s=new SeqStack; if(!s) { printf("空间不足\n");return NULL; } else { s->top=-1;return s; }} 阅读全文
posted @ 2011-08-11 17:09 bcy 阅读(170) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>#include<iostream.h>#define MAX 1000typedef int DataTypetypedef struct{ DataType data[MAX];int last;}SeqList;int Delete_SeqList(SeqList * L){ int i,j,k; DataType temp; for(i=1;i<=L->last;i++) { temp=L->last; for(j=2;j<=L->last;j++) { if(temp=L->last[j]) 阅读全文
posted @ 2011-08-11 17:08 bcy 阅读(302) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h >#include<malloc.h>#define OK 1#define ERROR 0typedef struct BiTNode{char data;struct BiTNode *lChild,*rChild;}BiTNode,*BiTree;//二叉树的初始化函数int Initiate(BiTree bt)//二叉树的头结点 { bt = (BiTree )malloc(sizeof(BiTNode)); if(bt==NULL) return 0; bt->lChild=NULL; bt->rChild=NU 阅读全文
posted @ 2011-08-11 17:07 bcy 阅读(760) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>#include<stdlib.h>typedef struct tree{ int num; struct tree *lchild,*rchild;}tree;tree *creatree(){ int num; tree *T; scanf("%d",&num); if(num==0) T=NULL; else { T=(tree*)malloc(sizeof(tree)); T->num=num; T->lchild=creatree(); T->rchild=creatree(); 阅读全文
posted @ 2011-08-11 17:06 bcy 阅读(210) 评论(0) 推荐(1) 编辑
摘要: #include <cstdio>#include <cmath>int N;bool isp(int n){ if( n <= 1 ) return 0; if( n == 2 ) return 1; int i , t = sqrt(n); for(i = 2 ; i <= t ; i++) if(n%i == 0) return 0; return 1;}void dfs(int n, int len){ if(len == N) { printf("%d\n",n); return; } else { int i ; for(i 阅读全文
posted @ 2011-08-11 17:05 bcy 阅读(151) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>#include<string.h>int n,num[10000],dis[10000];int cal( ){ int Max = 0; for( int i = 1; i <= n;++i ) { int max = 0,pos = 0; for( int j = 0; j <= i; ++j )//找前面已经存在且符合条件的最优解 if( dis[j] > max && num[j] < num[i] ) max = dis[j]; dis[i] += num[i] + max;//找到后 阅读全文
posted @ 2011-08-11 16:59 bcy 阅读(170) 评论(0) 推荐(0) 编辑
摘要: #include"stdio.h"#include"stdlib.h"#include"string.h"#include"math.h"int sushu(int x){ int t=(int)sqrt(x+1); for(int j=2;j<=t;j++) { if(x%j!=0) return 1; else { break; return 0; } }}int main(){ int N,k,cnt,max; while(scanf("%d",&N)!=EOF) { whi 阅读全文
posted @ 2011-08-11 16:56 bcy 阅读(176) 评论(0) 推荐(0) 编辑
摘要: #include"stdio.h"#include"stdlib.h"#include"math.h"#include"string.h"double diss(int x1,int x2,int y1,int y2){ int dis=0; return (sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))); }int main(){ int x,y,n,map[1010][1010]; double sum[1010]={0},dis[1010]={0}; while(scanf(&q 阅读全文
posted @ 2011-08-11 16:51 bcy 阅读(118) 评论(0) 推荐(0) 编辑