自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

yun_weiguo的专栏

弱渣的自娱自乐

  • 博客(46)
  • 收藏
  • 关注

原创 Lock的await/singal 和 Object的wait/notify 的区别

在使用Lock之前,我们都使用Object 的wait和notify实现同步的。举例来说,一个producer和consumer,consumer发现没有东西了,等待,produer生成东西了,唤醒。线程consumer线程producersynchronize(obj){     obj.wait();//没东西了,等待}synchro

2016-10-06 20:42:54 527

原创 二叉后序遍历的两种写法

vector postorderTraversal(TreeNode* root) { vector res; if(root==NULL) return res; stack s; s.push(root); while(!s.empty()) {

2016-03-29 17:16:28 357

原创 赋值运算符函数异常安全

要想在赋值运算符函数中实现异常安全,我们有两种做法。        一 先用new分配新内容,再用delete删除已有的内容。这样只在分配内容成功后再释放原来的内容,也就是分配内存失败时,原来的实例不会被修改。        二 先创建一个临时实例,在交换临时实例和原来的实例交换。       CMyStrig &CMyString::operator=(const CMy

2016-03-08 11:18:30 394

原创 pow(x,n)

快速幂算法注意要处理 INT_MIN的情况class Solution {public: double myPow(double x, int n) { if(n<0) { if(n==INT_MIN) return 1.0/ ( myPow(x,INT_MAX)*x); //be ca

2016-02-22 17:50:29 258

原创 编程珠玑第十二章习题

1. rand()一般返回约15个随机位。用该函数实现bigrand(),和randint(l,u) 要求前者至少返回30个随机位,后者返回【l,u】范围内的一个随机整数。int bigrand(){ return RAND_MAX*rand()+rand();}int randint(int l,int u){ return l+bigrand()%(u-l+1);}

2016-02-22 09:19:51 358

原创 查找单链表的中间元素

ListNode* findMid(ListNode* head){ if(head==NULL) return NULL; // if(head->next==NULL) return head; ListNode *fast=head; ListNode *slow=head; while(fast

2016-02-13 10:04:43 383

转载 link 2005/2001 错误

VC++中Link2005/2001是开发人员在开发过程遇到的问题,一直想搞清楚这类错误的原因!总结网上的资料,先总结如下。     编程中经常能遇到LNK2005错误——重复定义错误,其实LNK2005错误并不是一个很难解决的错误。弄清楚原因,就可以轻松解决它了。造成LNK2005错误主要有以下几种情况:1.重复定义全局变量。       A、需要使用全局变量的地方使用定义申明——其

2015-05-20 18:12:16 342

转载 SMTP

事先声明,整个过程以LOGIN认证方式为例,其他认证方式大同小异。按照时间顺序,主要分为22个步骤。1、客户端TCP连接服务器25端口;2、三次握手以后,连接建立成功,服务器主动推送服务就绪信息网易邮箱一般都形如“220 163.com Anti-spam GT for Coremail System (163com[20111010])”;雅虎邮箱形如“220 smtp1

2015-03-26 14:46:19 9891

原创 poj 1125 floyd

#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include int dis[101][101];i

2015-03-11 21:33:45 343

原创 poj 2240 floyd

第一次写floyd  ,核心代码只有5行。不过O(n^3) #include #include #include #include using namespace std;double dis[35][35];char str1[40],str2[40],str[40][40];double rate;int n,m;const int inf=1e8;int fi

2015-03-11 20:11:11 323

原创 zoj 3844 easy task

这道题目没有 Noooo的情况。所以直接过#include #define INF 1e8int num[15];int main(){ int t,n; while(scanf("%d",&t)!=EOF) { int Max; int Min; int Max_id; int Min_i

2015-03-08 09:07:17 446

原创 POJ 3461

#include #include #define N 500010int next[N];char s[N];char t[N];void get_next(char s[] ,int len){ int i,j=0; next[1]=0; for(i=2;i<=len;i++) { while(j>0&&s[j+1]!=s[i]) j=

2015-03-03 22:47:41 292

原创 poj 2406 +poj1961

这两道题目是类似的。是用next 数组来做的。不同的是1961 是求第i位置的最小循环节的 循环次数。aabaabaabaab,长度为12.到第二个a时,a出现2次,输出2.到第二个b时,aab出现了2次,输出2.到第三个b时,aab出现3次,输出3.到第四个b时,aab出现4次,输出4.2406 是求最后位置的最小循环节的 循环次数2406#include #inc

2015-02-28 19:18:10 292

原创 poj 2828(线段树)

//题目的关键就在于查询元素所在的位置int query(int l,int r,int rt,int p){ if(l==r) { sum[rt]=0; return l; } int ret; int m=(l+r)>>1; if(p<sum[rt<<1]) //与2182 相类似,不过这里只有< 不是<=。

2015-02-28 11:58:10 469

原创 2182(线段树)

Lost Cowssegment tree is so  amaing !!!#include #include #define N 8005int T[N<<2];int a[N];int b[N];void push_up(int rt){ T[rt]=T[rt<<1]+T[rt<<1|1] ; }void build(int l,int

2015-02-27 17:48:04 343

原创 树状数组模板+ poj 1195

模板模板int lowbit(int x){ return x & (-x);}void modify(int x,int add)//一维{ while(x<=MAXN) { a[x]+=add; x+=lowbit(x); }}int get_sum(int x){

2015-02-27 09:51:12 365

原创 poj 2823(线段树)

我用的是朴树的线段树。没有经过优化的。用了9K+ms ,第一次看到这么大的时间。不知道lazy 该怎么标记。 本来想试一试zkw线段树的,但是不是很熟,写不出来因为要求最大最小值,一开始我只用了一个query 想同时 得到最大最小,最后发现实现不了。用了两个函数,一个求最大,一个求最小。得出来了。#include #include #include #incl

2015-02-26 19:27:00 431

原创 poj 3468

A Simple Problem with Integers一直在数据类型上出错。终于知道long long 是 “%lld” 来输出输入了。time 1732ms#include #include #define LL long longusing namespace std;const int N=100005;LL add[N<<2];LL sum[N<<2];v

2015-02-25 15:20:19 273

原创 Hdu 1498(线段树)

Just a Hook这是一道延迟标记的题目,刚入门,还不是特别了解。但是 push_down 函数很重要,mark 以后再好好思考思考#include #include using namespace std;const int N=100005;struct node{ int col,sum;}tree[N<<2];void

2015-02-24 22:45:28 279

原创 hdu 1394(线段树)

time 62ms#include #include #include using namespace std;const int N=5005;int sum[N<<2];int a[N];void push_up(int rt){ sum[rt]=sum[rt<<1]+sum[rt<<1|1] ; }void build(int l,int r,int rt){

2015-02-24 20:59:09 318

原创 hdu 1754(线段树)

做了hdu 1166 后,这道题目只要稍稍修改一下就可以了。 不过在一直卡在一个小bug 里面, 花了好长的时间 #include #include using namespace std;const int N=20005;int Max[N<<2];int max(int a,int b){return a>b?a:b ;}void push_up(in

2015-02-24 15:20:29 380

原创 hud 1166

线段树做法#include #include #include using namespace std;const int N=50005;int ans;struct node { int l,r,sum; int mid() { return (l+r)>>1 ; }}tree[N*4];void build(int l,int r,int rt){

2015-02-24 11:53:44 350

原创 poj 3125(模拟队列)

题目大意:让你根据队列中的优先级 ,如果队伍中有 优先级高于队头的,则将队头放到队尾。 若没有,则打印,时间+1. 计算最后打印要完成的任务m时,所需的时间用数组进行模拟,不知道第一次为什么会TLE. 可能是用了struct 。但我觉得应该没影响 。难道是一开始用了cin ?time 16ms#include #include #include using namesp

2015-02-21 21:02:45 409

原创 poj 3096

好久没做字符串的题目了。题目分类是 c++ 模板库的使用。不过我好像没有用到。一开始忘了 怎么求字符串的长度,错用做strlen, sizeof 。 最后发现错误,使用了size()才ac 的#include #include #include #include using namespace std;int main(){ string str;

2015-02-21 15:56:34 377

原创 poj 3122

题意:生日派对时,准备了n个圆柱形的pie,半径比一定相同,但高都为1,邀请了f个朋友,加上自己一共f+1人,需要将n个pie分给f+1个人要求:每个人分得的pie尺寸要一样大,并且同一个人所分的pie要是从同一个pie上得到的,n个pie分完后可以有剩余求:每个人最多可以分多少分析:因为同一个人所分的pie都来自同一个pie,若每个人所分的最大体积为a,那么比a小的pie

2015-02-20 13:02:28 552

原创 poj 3258 +3273 +2456

到现在 二分思想还没完全建立起来,看了别人的代码,才懵懵懂懂。先把代码 留下,留下以后思考这两道题目的方法是相同的。poj 3258#include #include using namespace std;long long rock[50010];long long n,m,l;int cmp(const void* a,const void* b){

2015-02-20 11:24:54 318

原创 2299

这道题目的大意 是求 冒泡排序的交换次数但是 若这道题目 用冒泡排序做的话,肯定会超时  。O(n^2);但这道题目可以转换为求 逆序数 的大小。(线性代数里面学过的)9 1 0 5 4 逆序数=4+1+0+1=6 这正是 答案。我们可以使用  merge_sort() 来求 逆序数 。O(nlogn)  要注意 用int 型的话 ,会wa 的,要用long lon

2015-02-19 11:09:56 315

原创 poj 2632 (模拟)

思路:使用x ,y,dir 数组 分别表示 第i 个robot 的 X,Y,坐标和 方向。一开始,我将x ,y 轴的方向弄错了,wa 了。。一定要注意方向。我将N, E,S, W 方向 0,1,2,3;判断crash 的时候,先判断撞墙 再  循环判断时候碰到 其他robot并且使用一个flag  判断是否撞到。思路清晰的话,代码不难写出来。。不过模拟题目太恶心

2015-02-18 11:28:40 289

原创 poj 1068

简单的一道模拟题理解题目就不难。一次Ap数组表示 第i个右括号前面有几个左括号。w数组表示 第i 个右括号所构成的括号组中 一共有多少个右括号(含第i个右括号)0ms #include #include #include #include #include using namespace std;int p[30];int w[30];char c[50]

2015-02-17 20:59:15 278

原创 poj 2251

这道题目挺崩溃的。以为用 vis 数组判断是否访问过,以及 g数组存地图。没想到竟然会越过地图的边界(数组没越界)。蹦了。最近做了好几道bfs 的题目。终于对bfs 的题目有感觉了!!! #include #include #include #include using namespace std;char g[40][40][40];int vis[40]

2015-02-17 15:49:46 230

原创 poj 3087

简单的模拟题目 一开始理解题目错了,把 拆分后的s1,s2弄反了,答案错误。不过代码的速度太慢了,32ms大神都是0ms的。T~T#include #include #include using namespace std;int n,c,time,i;string no;string s1,s2,s;int shuffle(){ int i,j; string t

2015-02-17 13:00:04 256

原创 poj 3278

这是一道很水的bfs 题目。但是要注意的是 数组要开大点。因为 可能会访问到200000. 注意剪枝。否则会超时的。#include #include #include using namespace std;const int N=200010;int n,k,ans;bool vis[N];int cnt[N];void bfs(in

2015-02-16 23:53:58 386

原创 3414

经过这道题目,加深了对bfs 以及 回溯的理解。对于bfs 而言,重要的结点 node 的构建 ,而结点就代表着一种状态。其中包括了进行的操作,a, b 两个的容量。路径长度,要进行回溯的要就要在node 中添加一个pre 指针。在bfs 中,关键的还是返回条件(其中一个的值与c相等就结束了,记录路程,并返回)#include #include #include #include

2015-02-16 17:11:48 244

转载 回溯

博客地址:Zealot Yin欢迎转载,转载请注明出处[http://creator.cnblogs.com/]理论辅助:回溯算法也叫试探法,它是一种系统地搜索问题的解的方法。回溯算法的基本思想是:从一条路往前走,能进则进,不能进则退回来,换一条路再试。用回溯算法解决问题的一般步骤为:1、定义一个解空间,它包含问题的解。2

2015-02-16 13:52:31 261

原创 poj 1129

题目链接点击打开链接哎,不知道有四色定理。还以为颜色会有很多种,一直想不出来。反思:程序都是可以分割成一部分一部分的。一开始写dfs 函数的时候,想着又要遍历邻接点,又要判断能否染色。好像会有很多循环,一直想不出来看了别人的博客,看到他将 将判断能否染色 分离出来。这样 dfs 就看起来简洁多了。同时在判断能否染色的时候要注意, 要根据情况选择 判断

2015-02-15 21:56:14 289

原创 poj 2503 (trie)

poj 2503  题目链接poj 2503 这道题目套用模板就差不多可以得到答案了。 不过比较蛋疼的是输入。参考答案。 模板 include using namespace std; const int branchNum = 26; //声明常量 int i; struct Trie_node{ bool isStr; //记录此处是否构成一个

2015-02-13 21:43:05 272

转载 ---评微软数据结构+算法面试100题

作者:July。时间:2010年10月-11月。出处:http://blog.csdn.net/v_JULY_v。说明:本文原题为:“横空出世,席卷Csdn [评微软等公司数据结构+算法面试100题]”,但后来此微软100题(加上后续的80道,共计180道面试题)已成一系列,被网络上大量疯狂转载,因此特改为上述题目。---------------------------------

2015-02-13 14:23:35 395

原创 poj 3368(RMQ)

题目链接 http://poj.org/problem?id=3368这道题目是RMQ(Range Minimum/Maximum Query) 问题变形,寻找在区间内出现的最大频次。 用到动态规划 dp[ i] [j] =max(dp [i ] [j-1] ,dp[i +i<<(j-1) ] [j-1] ;这道题的关键是如何构建一个dp数组。 我们可以将读取的数组num 变形。 所有相同

2015-02-13 14:18:18 357

原创 st算法

引用链接   外国人写的博客

2015-02-12 21:56:18 430

原创 poj 3264(RMQ+线段树)

这是一道RMQ 题目。关键是求RMQ dpmax[i][j] 表示从第i个数字起 2^j 长度范围的的最大值。则 dp[ i] [0] 表示第i个数字本身void rmq(int n){ for(int j=1;j<=log2(n);j++) //注意取等号。 { for(int i=0;i<n;i++) {

2015-02-12 21:15:49 550

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除