文章列表
 
您正在查看 "北大acm程序设计" 分类下的文章

2009-11-25 14:59

//最小生成树的最大边,居然狂WA几次,原来是在排序的时候把m写成了n,唉。

#include<iostream>
using namespace std;
#define size 10001
#define MAX 2001
int n, m;
struct node
{
long val;
int a, b;
}edge[size];
int father[MAX];
int getfather( int r )
{
while (father[r] != r)
{
   r = father[r];
}
return r;
}

 
2009-11-23 14:47

#include <iostream>
#include <vector>
using namespace std;
const int MAXN = 10010;
vector<int>adj[MAXN], radj[MAXN];
int n, m;
int nscc;
bool flag[MAXN]; //访问标志数组
int belg[MAXN]; //存储强连通分量,其中belg[i]表示顶点i属于第belg[i]个强连通分量
int endtime[MAXN]; //结束时间标记,其中numb[i]表示离开时间为i的顶点
int in[MAXN], size[MAXN];
int s = 0;
//用于第一次深搜,求得numb[1..n]的

 
2009-11-17 15:22

//最小比率树,用prim返回的不能是生成的最小树的权值和。而应该返回的是比率

#include<stdio.h>
#include<math.h>
typedef struct
{
int x, y;
double z;
}POINT;
const int maxsize = 1005;
POINT point[maxsize];
typedef double Graph[maxsize][maxsize];
int n;
Graph g, g1;
double dis( POINT p0, POINT p1)
{
return sqrt( (double)((p0.x-p1.x)*(p0.x-

 
2009-11-16 22:13

#include<iostream>
using namespace std;
const int max_vertexs=1000;
int n, m;
int total, mlen;
struct
{
int x, y;
}Point[1001];
typedef int Graph[max_vertexs][max_vertexs];
void prim( Graph G, int vcount )
{
int i, j, k;
int lowcost[max_vertexs], used[max_vertexs], closeset[max_vertexs];
int father[max_vertexs];
for (i=0; i < vcount; i++)
{
   lowcost[i] =

 
2009-11-15 23:19

//这道题和思路和生物链那道一样

#include<stdio.h>
int T;
int n, k;
struct NODE
{
int father;
int rank;
}Bug[2005];

void init( )
{
for (int i = 1; i <= n; i++)
{
   Bug[i].father = i;
   Bug[i].rank = 0;
}
}
int find( int r )
{
if (Bug[r].father == r)

 
2009-11-15 21:42

#include<stdio.h>
struct NODE
{
int parent;
}student[50001];

int n, m;
int total;
int find(int a)
{
if(student[a].parent == a)
   return a;
student[a].parent = find( student[a].parent );
return student[a].parent;
}
void union_set(int a, int b)
{
int i = find(a), j = find(b);
if (i != j)//有相同的根
{
 

 
2009-08-13 11:20

根据题意就是求最长上升序列的长度用二分查找复杂度(O(n^2))

#include<stdio.h>
#include<stdlib.h>
typedef struct blocks{
int l,m;
}block;
block b[10000];
int stack[10000];
int top;
int cmp(const void *a,const void *b)//刚开始这里写错了。害我wa好多次
{
     block *aa=(block *)a;
block *bb=(block *)b;
if(aa->m!=bb->

 
2009-08-12 17:59

根据题意其实就是求最长升序子序列

刚开始用动规,结果时间超出。唉O(n^2)的复杂度怎么会不超出。然后想到匈牙利二分匹配算法,申请的数组肯定会内存超出,怎么办?最后用了一种方法,代码如下。

#include<stdio.h>
int stack[40000];
int top;
int dsearch(int num)
{
int p=top;
    while(stack[p]>num)p--;
p++;
retur

 
2009-08-12 12:32

#include<stdio.h>
#include<string.h>
int a[1001];
int b[1001];
int main()
{
int n,i,j;
freopen("in.txt","r",stdin);
while(scanf("%d",&n)==1)
{
   for(i=0;i<n;i++)
    scanf("%d",a+i);
   /*for(i=0;i<n;i++)
    b[i]=1;*/
for(i=0;i<n;i++)

 
2009-08-08 21:37

http://acm.pku.edu.cn/JudgeOnline/problem?id=2955

#include<stdio.h>
#include<string.h>
int map[101][101];
char s1[101];
int main()
{
int len,i,j,k,longest;
//freopen("in.txt","r",stdin);
while(scanf("%s",s1)>0&&strcmp(s1,"end"))
{

 
2009-08-08 14:01

http://acm.pku.edu.cn/JudgeOnline/problem?id=1191

#include<stdio.h>
#include<string.h>
#include<math.h>
int k;
double aver;
double flag[15][9][9][9][9];
double qipan[9][9],total;
double min(double a,double b)
{
return a>b?b:a;
}
double s(int x1,int y1,int x2,int y2)
{

 
2009-07-24 1:06

#include <stdio.h>
#include<string.h>
int a[3000000];
int b[500000]={0};
int main()
{
int i,j,n;
memset(a,0,sizeof(a));
for(i=1;i<=500000;i++)
{
   if(b[i-1]-i>0&&a[b[i-1]-i]==0)
    b[i]=b[i-1]-i;
   else
    b[i]=b[i-1]+i;
   a[b[i]]=1;

}
while(scanf(

 
2009-07-23 23:46

#include <stdio.h>
int main()
{
int a[6000],i,j,max;
int n;
while(scanf("%d",&n)>0)
{
int k=0;
for(i=1;i<=n*(1+n)/2;i++)
   scanf("%d",&a[i]);
for(i=2;i<=n;i++)
{
   for(j=1;j<=i;j++)
   {
    if(j==1)
    {
     a[i*(i-1)/2+1]+=a[(i-1)*(i-2)/2+1];

 
2009-07-23 17:41

#include<stdio.h>
#include<string.h>
#define MAX 1000000
int main()
{
int matrix[100][100],i,j,used[100];
int num,lowcost[100],Maxlen,k,min;

   while(scanf("%d",&num)>0)
   {
      for(i=0;i<num;i++)
    for(j=0;j<num;j++)
    {
     scanf("%d",&matri

 
2009-07-20 2:12

#include<stdio.h>
#include<string.h>
#include<math.h>
#define N 101
typedef struct point{
double x,y;
}Point;
int useif[N];   //记录y中节点是否使用
int link[N];   //记录当前与y节点相连的x的节点
int mat[N][N]; //记录连接x和y的边,如果i和j之间有边则为1,否则为0
int gn,gm;    //二分图中x和y中点的数目
int can(int t)
{
    int i;

 
   
 
 
文章存档
 
     
 
最新文章评论
  

条理很清晰
 

什么是多重队列?跪求!!!
 

orz ...
 

请问这个代码,错在什么地方了?一直是 running time error 我是不是少考虑了什么条
 

#include<iostream> #include<algorithm> #include<string.h> using namespace std;
   
帮助中心 | 空间客服 | 投诉中心 | 空间协议
©2012 Baidu