SQL
博客园 | 首页 | 发新随笔 | 发新文章 | 联系 | 订阅 订阅 | 管理

2007年10月25日

PKU2036
     摘要: 对线段排序 对于K不存在的线段的放在一起,对x1进行排序 对于x1相同的对于y1排序对于K存在的直线 对b进行排序 b相同的对于x1进行排序排序复杂度Nlogn 在对于在一条直线上的线段O(n)的计算线段数目总时间复杂度NLOGN这应该是这题最基本的算法#include<stdio.h>#include<string.h>#include<stdlib.h>#i... 阅读全文
posted @ 2007-10-25 13:16 sql172 阅读(96) | 评论 (1) | 编辑
 
ACM/ICPC要求的知识点(转)
 ACM/ICPC要求的知识点

时间复杂度(渐近时间复杂度的严格定义,NP问题,时间复杂度的分析方法,主定理)
排序算法(平方排序算法的应用,Shell排序,快速排序,归并排序,时间复杂度下界,三种线性时间排序,外部排序)
数论(整除,集合论,关系,素数,进位制,辗转相除,扩展的辗转相除,同余运算,解线性同余方程,中国剩余定理)
指针(链表,搜索判重,邻接表,开散列,二叉树的表示,多叉树的表示)
按位运算(and,or,xor,shl,shr,一些应用)
图论(图论模型的建立,平面图,欧拉公式与五色定理,求强连通分量,求割点和桥,欧拉回路,AOV问题,AOE问题,最小生成树的三种算法,最短路的三种算法,标号法,差分约束系统,验证二分图,Konig定理,匈牙利算法,KM算法,稳定婚姻系统,最大流算法,最小割最大流定理,最小费用最大流算法)
计算几何(平面解几及其应用,向量,点积及其应用,叉积及其应用,半平面相交,求点集的凸包,最近点对问题,凸多边形的交,离散化与扫描)
数据结构(广度优先搜索,验证括号匹配,表达式计算,递归的编译,Hash表,分段Hash,并查集,Tarjan算法,二叉堆,左偏树,斜堆,二项堆,二叉查找树,AVL,Treap,Splay,静态二叉查找树,2-d树,线段树,二维线段树,矩形树,Trie树,块状链表)
组合数学(排列与组合,鸽笼原理,容斥原理,递推,Fibonacci数列,Catalan数列,Stirling数,差分序列,生成函数,置换,Polya原理)
概率论(简单概率,条件概率,Bayes定理,期望值)
矩阵(矩阵的概念和运算,二分求解线性递推方程,多米诺骨牌棋盘覆盖方案数,高斯消元)
字符串处理(KMP,后缀树,有限状态自动机,Huffman编码,简单密码学)
动态规划(单调队列,凸完全单调性,树型动规,多叉转二叉,状态压缩类动规,四边形不等式)
博奕论(Nim取子游戏,博弈树,Shannon开关游戏)
搜索(A*,ID,IDA*,随机调整,遗传算法)
微积分初步(极限思想,导数,积分,定积分,立体解析几何)
 

1. ACM/lCPC要求的数据结构知识点
(1) 单双链表及循环链表;
(2) 树的表示与存储,二叉树(概念,遍历);
(3) 二叉树的应用(二叉排序树,判定树,博弈树,解答树等);
(4) 文件操作(从文本文件中读人数据,并输出到文本文件中;
(5) 图 (基本概念,存储结构,图的运算);
ACM/ICPC要求学生对这些知识点非常熟悉。
2. ACM/ICPC要求的基础数学知识点
离散数学知识的应用(如排列组合、简单图论、数理逻辑)、数论知识、线性代数、组合数学、计算几何。
3. ACM/ICPC要求的算法设计知识点
排序算法 (冒泡法、插人排序、合并排序、快速排序、堆排序)、查找(顺序查找、二分法)、回溯算法、递归算法、分治思想、模拟法、贪心法、简单搜索算法(深度优先,广度优先)、搜索中的剪枝、A*算法、动态规划的思想及基本算法、高精度运算。
posted @ 2007-10-25 10:27 sql172 阅读(328) | 评论 (0) | 编辑
 

2007年10月23日

PKU1151线段树解法
     摘要: 模仿别人的代码写的这题不用线段树也可以过#include<stdio.h>#include<string.h>#include<stdlib.h>structline{doublex,y1,y2;intin;};structnode{node*pl,*pr;intiL,iR;doubleleft,right;doubley_len;intin;}mem[404]... 阅读全文
posted @ 2007-10-23 16:10 sql172 阅读(292) | 评论 (1) | 编辑
 

2007年10月22日

PKU2074
#include <stdio.h>
#include 
<string.h>

struct line
{
    
double x1, x2, y;
    
bool ex;
}
;

line l1, l;
int n;
double len;

int lineCnt;
line l2[
30];

void CNT()
{
    
int i;
    
for(i = 0; i < lineCnt; i++)
    
{
        
if(l2[i].ex && len<l2[i].x2-l2[i].x1)
            len
=l2[i].x2-l2[i].x1;
    }

}


void cut(line l1, int i)
{
     
if(l1.x1 <= l2[i].x1)
    
{
        
if(l1.x2<l2[i].x2 && l1.x2>l2[i].x1)
            l2[i].x1
=l1.x2;
        
if(l1.x2 >= l2[i].x2)
            l2[i].ex
=0;
    }
else
        
if(l1.x2 >= l2[i].x2)
        
{
            
if(l1.x1 <= l2[i].x2)
                l2[i].x2
=l1.x1;
        }
else
        
{
            l2[lineCnt].x1
=l1.x2, l2[lineCnt].x2=l2[i].x2, l2[lineCnt].ex=1;
            l2[i].x2
=l1.x1;
            lineCnt
++;
        }

    
}


void func()
{
    
int i;
    line shadow;
    
double r=(l1.y-l.y)/(l1.y-l2[0].y);
    shadow.x1
=l1.x2-(l1.x2-l.x1)/r;
    shadow.x2
=l1.x1+(l.x2-l1.x1)/r;
    shadow.y
=l2[0].y;

    
for(i = 0; i < lineCnt; i++)
    
{
        
if(l2[i].ex)
            cut(shadow, i);
    }

}



int main(){
    
while(scanf("%lf%lf%lf", &l1.x1, &l1.x2, &l1.y)==3)
    
{
        
if(l1.x1==0 && l1.x2==0 && l1.y==0)
            
break;
        len
=0;
        scanf(
"%lf%lf%lf", &l2[0].x1, &l2[0].x2, &l2[0].y);
        l2[
0].ex=1;
        lineCnt
=1;
        scanf(
"%d", &n);
        
        
int i;
        
for(i = 0; i < n; i++)
        
{
            scanf(
"%lf%lf%lf", &l.x1, &l.x2, &l.y);
            
if(l.y<l1.y && l.y>=l2[0].y)
            func();
        }

        CNT();
        
if(len>0)
            printf(
"%.2f\n", len);
        
else
            printf(
"No View\n");
    }

    
return 0;
}
posted @ 2007-10-22 18:56 sql172 阅读(49) | 评论 (0) | 编辑
 

2007年10月21日

PKU3264线段树解法
#include<stdio.h>
#include
<string.h>


struct node
{
    node 
* pl, * pr;
    
int left, right;
    
int mxa, min;
}
mem[100000];

int memCount;
int n, q;
int mxa, min;

node 
* newNode()
{
    node 
* pt=&mem[memCount++];
    pt
->mxa=-1, pt->min=1000001;
    
return pt;
}


node 
* buildTree(int l, int r)
{
    node 
* root=newNode();
    root
->left=l;
    root
->right=r;
    
if(r-l>=1)
    
{
        
int mid=(l+r)/2;
        root
->pl=buildTree(l,mid);
        root
->pr=buildTree(mid+1,r);
    }

    
return root;
}


void update(node * root, int i, int a)
{
    
if(root->left==i && root->right==i)
    
{
        root
->mxa=a, root->min=a;
        
return ;
    }

    
if(root->min>a)
        root
->min=a;
    
if(root->mxa<a)
        root
->mxa=a;

    
if(root->pl->right>=i)
    
{
        update(root
->pl,i,a);
    }
else
    
{
        update(root
->pr,i,a);
    }

}


void que(node * root, int i, int j)
{
    
if(root->min>min && root->mxa<mxa)
        
return;
    
if(root->left==i && root->right==j)
    
{
        
if(mxa<root->mxa)
            mxa
=root->mxa;
        
if(min>root->min)
            min
=root->min;
        
return;
    }

    
if(root->pl->right>=i)
    
{
        
if(root->pl->right>=j)
            que(root
->pl, i, j);
        
else
        
{
            
int mid=(root->left+root->right)/2;
            que(root
->pl,i,mid);
            que(root
->pr,mid+1,j);
        }

    }
else
    
{
        que(root
->pr,i,j);
    }

}


int main()
{

    
while(scanf("%d%d", &n, &q)==2)
    
{
        memCount
=0;
        node 
* root=buildTree(1, n);
        
int i, a;
        
for(i=0;i<n;i++)
        
{
            scanf(
"%d",&a);
            update(root,i
+1,a);
        }

        
int x, y;
        
for(i=0;i<q;i++)
        
{
            scanf(
"%d%d", &x, &y);
            mxa
=-1, min=1000001;
            que(root,x, y);
            printf(
"%d\n",mxa-min);
        }

    }

    
return  0;
}
posted @ 2007-10-21 21:23 sql172 阅读(136) | 评论 (1) | 编辑
 
PKU2029
#include <stdio.h>
#include 
<string.h>

int n, W, H, w, h;
int m[101][101];
int cnt;

void DP()
{
    
int i, j;
    
int c=0;

    
for(i=w;i<=W;i++)
        
for(j=h;j<=H;j++)
        
{
            
if(j==h)
            
{
                c
=0;
                
int ii, jj;
                
for(ii=i-w+1;ii<=i;ii++)
                    
for(jj=1;jj<=h;jj++)
                        
if(m[ii][jj]==1)
                            c
++;
                
if(cnt<c)
                    cnt
=c;
            }

            
else
            
{
                
int k;
                
for(k=i-w+1;k<=i;k++)
                
{
                    
if(m[k][j-h]==1)
                        c
--;
                    
if(m[k][j]==1)
                        c
++;
                }

                
if(cnt<c)
                    cnt
=c;
            }

        }


}


int main()
{
    
while(scanf("%d", &n)==1 && n)
    
{
        cnt
=0;
        memset(m,
0,sizeof(m));
        scanf(
"%d%d", &W, &H);
        
int i;
        
int x, y;
        
for(i=0;i<n;i++)
        
{
            scanf(
"%d%d", &x, &y);
            m[x][y]
=1;
        }

        scanf(
"%d%d", &w, &h);
        DP();
        printf(
"%d\n", cnt);
    }

    
return 0;
}
posted @ 2007-10-21 20:06 sql172 阅读(43) | 评论 (0) | 编辑
 

2007年10月18日

PKU1940
#include<stdio.h>
#include
<string.h>

int n;
__int64 x1, y1;
__int64 x[
1024], y[1024];
__int64 sum_x, sum_y;

int main()
{
    
while(scanf("%d", &n)==1)
    
{
        printf(
"%d", n);
        
int i;

        sum_x 
= sum_y = 0;

        
for(i = 1; i <= n; i++)
        
{
            scanf(
"%I64d%I64d", &x[i], &y[i]);
            sum_x 
+= x[i], sum_y += y[i];
        }


        
for(i = 2; i <= n ; i+=2)
            sum_x 
-= 2*x[i], sum_y -= 2*y[i];
        
        x[
0]=sum_x, y[0]=sum_y;

        printf(
" %I64d.000000 %I64d.000000", x[0], y[0]);

        
for(i = 1; i < n; i++)
        
{
            x[i]
=2*x[i]-x[i-1];
            y[i]
=2*y[i]-y[i-1];

            printf(
" %I64d.000000 %I64d.000000", x[i], y[i]);
        }


        printf(
"\n");
    }

    
return 0;
}
posted @ 2007-10-18 11:11 sql172 阅读(51) | 评论 (0) | 编辑
 

2007年10月16日

线段树521
     摘要: 最近线段树狂写中 争取以后啥都不看就能写出来#include<stdio.h>#include<string.h>structnode{node*pl,*pr;intleft,right;intcolor;intcolCount;intcl,cr;}mem[200020];intmemCount;intCol[31];intColCnt;intresult;node*new... 阅读全文
posted @ 2007-10-16 21:58 sql172 阅读(59) | 评论 (0) | 编辑
 

2007年10月15日

今天农夫布置的DP题
水了