09 2012 档案
poj 2352
摘要:线段树,顺序存储实现#include <stdio.h> #include <string.h> const int maxx=32000; const int maxn=15000; int l[3*(maxx+1)],h[3*(maxx+1)],w[3*(maxx+1)]; int N; int ans[maxn]; void Create(int t,int s,int f) { l[t]=s;h[t]=f; if(s<f) { int mid=(s+f)/2; Create(2*t+1,s,mid); Create(2*t+2,mid+1,f); } } 阅读全文
posted @ 2012-09-29 14:22 lishimin_come 阅读(111) 评论(0) 推荐(0)
POJ 1151
摘要:刚看了这道题目完全没思路,在网上找了结题报告,了解到需用离散化+线段树+扫描,但菜鸟一个,发现数据规模并不大,用离散化完全可以,所以只用了离散化,思路还是很清晰的,但还是贡献了5个小时,15次wa,纠结过后发现x,y数组我是从1开始计数的,但sort 的时候却是从0开始sort,结果导致身心煎熬了n小时,粗心惹的祸啊//离散化求解!!!!#include <iostream>#include <algorithm>using namespace std;const int maxn=210;double x[maxn],y[maxn];int vis[maxn][max 阅读全文
posted @ 2012-09-25 15:17 lishimin_come 阅读(149) 评论(0) 推荐(0)
POJ 1161
摘要:第一道并查集,47ms ,还是很慢啊,不过是绞尽脑汁,调试了n次,做出来的,思路还是挺清晰地#include <iostream> using namespace std; const int maxn=30010; int parent[maxn]; int amount[maxn]; int rank[maxn]; int n,m; void init() { for(int i=0;i<n;i++) { parent[i]=i; amount[i]=1; rank[i]=0; } } int find(int t) { if(parent[t]!=t) retur... 阅读全文
posted @ 2012-09-23 20:16 lishimin_come 阅读(118) 评论(0) 推荐(0)
POJ 2318
摘要:二分#include <iostream> using namespace std; const int maxn=5010; int Ui[maxn],Li[maxn],dx[maxn],dy; int amount[maxn]; int m,n,x1,y1,x2,y2; int bsearch(int xj,int yj) { int low=-1,high=m,mid; while(high-low>1) { mid=(high+low)/2; if((dy*(xj-Ui[mid])-dx[mid]*(yj-y1))<0) high=mid; else lo... 阅读全文
posted @ 2012-09-22 16:00 lishimin_come 阅读(113) 评论(0) 推荐(0)
poj 1308
摘要:注意的情况比较多,尤其是空树这一种#include <iostream> #include <stdlib.h> using namespace std; const int maxn=100; struct node { int s,f; node* next; };//在此数据结构采用链表,方便后续遍历算法 int indexNode[maxn];//用于构造索引的数组 int v[maxn]; node *head; int totNode;//节点的总数 void visitNode(int temNode) { node* p=head->next; v 阅读全文
posted @ 2012-09-18 19:00 lishimin_come 阅读(151) 评论(0) 推荐(0)
POJ 2106
摘要:知识点:栈的应用语法经验,主函数外的函数中的指针变量不能付给主函数中的指针,因为函数调用完后就会释放内存,赋值相当于没赋#include<iostream>using namespace std;const int maxn=110;void trans(char *exp,char *atexp);int oc( char *s);int main(){ int t=1,jud; char exp[maxn]; char atexp[maxn]; while(cin.getline(exp,maxn)) { trans(exp,atexp); jud=oc(atexp); cha 阅读全文
posted @ 2012-09-15 20:50 lishimin_come 阅读(198) 评论(0) 推荐(0)