自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

我要一步一步往上爬

Stay hungry,stay foolish.

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

原创 回射客户端服务器UDP(echo client&&server based on UDP)

Tips : The feature of UDP 1、connectionless 2、the information transmission based on massage3、unreliable transmission 4、for the most times , UDP is more efficient.Some points of UDP to be mentioned: 1、the message of UDP may lose , repeat 2、sometimes

2015-11-12 00:35:14 557

原创 回射客户端服务器epoll( echo client && server improved by epoll function )

select :1.The file descriptors that one process open is limited.2.FD_SETSIZE poll : The file descriptors that one process open is limited.ulimit -n number The file descriptors that the system run is limited with the memory.the common points :The k

2015-11-11 00:41:46 539

原创 通过poll修改最大并发数(the maximum concurrent connection improved by poll )

When we use select function to realise concurrent server , the times of concurrent connection is limited by two sides.(1) One is that the max count of a process can open is limited , but we can fix

2015-11-10 12:07:35 625

原创 超时设置方法( the way to set timeout )

In the connection between the server and the client. Sometimes there may have some timeout. Today , we used our own method to realise a series of timeout function , including read_timeout , write_time

2015-11-09 02:28:50 1733

原创 回射客户端服务器shutdown修改版( echo client && server improved by select shutdown )

Tips :When the client closed initially , how can we guarantee that the information that the client send can be totally received by the server.This passage mainly discuss this problem with close() and shutdown(). With the comparison , we learned that close

2015-11-07 11:20:56 351

原创 回射客户端服务器select 修改版[2]( echo client && server improved by select function)

Tips:Today , we mainly improved the code of the server , removing the  fork() and let select to response the different events of readable information and connection of the client. Server(modif

2015-11-07 00:37:34 377

原创 回射客户端服务器select 修改版[1]( echo client && server improved by select function)

Function : Compared with the former edition , we add select function to realise I/O multiplexing which let client can monitor the standard input and readable event from the socket. We mainly changed

2015-11-06 00:09:53 303

原创 回射客户端服务器中僵尸进程的处理( the solution of zombie process in the echo client && server )

Tips :In the passage , we discuss how to clean up zombie processes with a better solution. We attempted signal ( SIGCHLD , SIG_IGN ), but it can't manage many son processes. The same things happened

2015-11-05 01:20:44 504

原创 TCP 粘包问题处理[2] ( the solution of sticky package problem of TCP )

Function : In this passage , we offer another method  to set out the sticky package. The method is that we encapsulate deadline function to realise  to read by line. We set '\n' as the boundary of t

2015-11-04 16:52:44 336

原创 TCP 粘包问题处理[1] ( the solution of sticky package problem of TCP )

Because TCP is a stream protocol, so in the translation , there may have lots of sticky bags.The passage offer two method to solve this problem.1.We use the fixed length package to solve it. 2. We designed the protocol by ourselves , a struct wiht the h

2015-11-04 00:49:33 758

原创 点对点-客户端服务器 ( peer to peer Client & Server )

Function : 1.The client can write to the server and also the server can write to the client. 2. Client and server both of them can response to the each other's off line. (with signal designed by yourself SIGUSR1 ) Server :/*****

2015-10-31 01:48:38 1057

原创 回射-客户服务器 ( echo client-server ) [ Edition 2]

Function : This edition add the some features:1.The REUSEADDR of the server2.We use the child process to handle the muti-connection of the clients.3.When the client off the connection , the se

2015-10-30 22:57:36 396

原创 回射-客户服务器 ( echo client-server ) [ Edition 1]

The simplest ech client-server model. Function : The client write something on the STDIN , and the server print them on the screen and write them back to the client.

2015-10-30 21:53:38 324

转载 TCP三次握手和四次挥手协议

TCP链接协议概述建立TCP需要三次握手才能建立,而断开连接则需要四次握手。整个过程如下图所示:建立连接的过程首先Client端发送连接请求报文,Server段接受连接后回复ACK报文,并为这次连接分配资源。Client端接收到ACK报文后也向Server段发生ACK报文,并分配资源,这样TCP连接就建立了。断开连接的

2015-10-30 21:21:07 334

原创 操作格子(线段树)

问题描述有n个格子,从左到右放成一排,编号为1-n。共有m次操作,有3种操作类型:1.修改一个格子的权值,2.求连续一段格子权值和,3.求连续一段格子的最大值。对于每个2、3操作输出你所求出的结果。输入格式第一行2个整数n,m。接下来一行n个整数表示n个格子的初始权值。接下来m行,每行3个整数p,x,y,p

2014-04-12 18:25:34 348

转载 刘汝佳黑书 pku等oj题目

一.动态规划参考资料:刘汝佳《算法艺术与信息学竞赛》《算法导论》 推荐题目:http://acm.pku.edu.cn/JudgeOnline/problem?id=1141简单 http://acm.pku.edu.cn/JudgeOnline/problem?id=2288中等,经典TSP问题 http://acm.pku.edu.cn/Judg

2014-02-07 01:24:27 912

原创 POJ 1185 炮兵阵地 ( dp[状态压缩] )

题意是汉语.解析:可以发现,对于每一行放大炮的状态,只与它上面一行和上上一行的状态有关,每一行用状态压缩的表示方法,0表示不放大炮,1表示放大炮,同样的,先要满足硬件条件,即有的地方不能放大炮,然后就是每一行中不能有两个1的距离小于2(保证横着不互相攻击),这些要预先处理一下。然后就是状态表示和转移的问题了,因为是和前两行的状态有关,所以要开个三维的数组来表示状态,当前行的状态可由前两行的状态

2014-01-28 18:09:22 440

原创 POJ 3049 Invitation Cards ( 快排+深搜)

题意:在一堆字母中找一段字母,使其中至少含有1个原音,2个辅音字母,且按字典序从小到大排列思路:字母也就是char 类型(小整形),将字符传按一定规则排序,ch - 'a' , (ch 为char类型),即 ‘a' 对应 0 , 'b' 对应1...'z' 对应25...再对字符对应的数字(0...25)排序,然后进行深搜。#include #define N 30char str[N

2014-01-27 00:32:25 548

转载 阮一峰:字符串匹配的KMP算法

字符串匹配是计算机的基本任务之一。举例来说,有一个字符串"BBC ABCDAB ABCDABCDABDE",我想知道,里面是否包含另一个字符串"ABCDABD"?许多算法可以完成这个任务,Knuth-Morris-Pratt 算法(简称 KMP)是最常用的之一。它以三个发明者命名,起头的那个K就是著名科学家 Donald Knuth。这种算法不太

2013-10-28 21:24:31 483

原创 POJ 3461 Oulipo ( KMP )

题意:给你一个子串(模式串)和一个母串(文本),问子串在母串中出现的次数。分析:基础的KMP#include #include #include #include #define SUB_MAX 10005#define STR_MAX 1000005char str[STR_MAX] ;char sub[SUB_MAX] ;int next[SUB_MAX]

2013-10-28 20:31:32 405

原创 POJ 1157 LITTLE SHOP OF FLOWERS ( DP )

题意:输入两个整数 F 和 V,分别表示花的数量和花瓶的数量,接下来输入F行V列的表格如下;value[i][j]表示花i放在瓶j里面的价值;规定把F束花放在V个花瓶里,使花的相对顺序不能变,即1在2前面,2在3前面......。  求怎样放能使价值总和最大,输出最大值。思路:dp[i][j] 表示     表示前i束花放在前j个花瓶中审美的最大值状态转换方程: dp[i][j

2013-10-24 15:46:12 440

原创 POJ 3273 Monthly Expense(二分)

题意:给出农夫在n天中每天的花费,要求把这n天分作m组,每组的天数必然是连续的,要求分得各组的花费之和应该尽可能地小,最后输出各组花费之和中的最大值分析:二分搜索的经典题目。。。#include #include #include #define N 100050using namespace std ;int n , m ; //n 代表天数,m代表要分成的区间

2013-10-19 20:53:57 605

原创 POJ 3414 Pots ( BFS , 打印路径 )

题意:给你两个空瓶子,只有三种操作一、把一个瓶子灌满二、把一个瓶子清空三、把一个瓶子里面的水灌到另一个瓶子里面去(倒满之后要是还存在水那就依然在那个瓶子里面,或者被灌的瓶子有可能没满)思路:BFS,打印路径时需技巧。//G++ 840K 0MS#include #include #include #include #include #

2013-10-08 23:18:37 701

原创 POJ 1141 Brackets Sequence ( 区间DP )

题意:给一组小括号与中括号的序列,添加最少的字符,使该序列变为合法序列,输出该合法序列。 分析:设dp[i,j]为从位置i到位置j需要加入字符的最小次数,有dp[i,j]=min(dp[i,k]+dp[k+1,j]),其中i。特别的当s[i]='[' s[j]=']'或者s[i]='(' s[j]=')'时,dp[i,j]=dp[i+1,j-1]。初始条件为dp[i,i]=1,其中

2013-10-07 21:04:09 504

原创 POJ 1703 Find them, Catch them

题意 :有两个不同的帮派,每个帮派至少有一个人。 判断两个人是否属于同一个帮派。有 T 组测试数据,给你 N 个人,编号从 1 到 N,操作 M 次。每次操作输入一个字符和两个数 x ,y ,如果字符为 A 则判断 x 和 y 是否属于同一个帮派,并且输出结果。 如果字符为 D 则明确告诉你 x 和 y 是属于不同帮派的。分析:并查集,以前接触的并查集都是让我们判断是否属于同一个连通分量,

2013-10-07 17:10:51 445

原创 POJ 1465 Multiple (广搜,哈希判重)

题意:给定一个数n,以及几个数字,求仅包含给定数字的n的最小倍数.分析:宽搜+hash判重,但在搜索过程中有可能出现大数,具体怎么处理的,祥看我的代码。//428K 672MS#include#include#include#include#include#include#include#include#include#include#define N

2013-10-05 20:22:05 599

原创 POJ 2777 Count Color (线段树、lazy思想)

题意:有一个区间,最多有30种颜色。有两种操作,一种是对某一个区间段染上某一种颜色,一种是询问该区间有多少种不同的颜色。思路:线段树的好题,线段树 + lazy思想的经典应用。而且和位运算结合到了一起。因为颜色数量很少,而且父结点的颜色正好是两个子结点颜色的按位或,因此可以用位运算。最后1的个数就是不同颜色的个数。// 4276K 297MS#include #

2013-10-05 20:04:50 562

原创 POJ 2001 Shortest Prefixes ( 字典树 )

题意:给出n个单词(1分析:字典树的基础应用。Trie树(字典树),又称单词查找树或键树,是一种树形结构,是一种哈希树的变种。典型应用是用于统计和排序大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计。它的优点是:最大限度地减少无谓的字符串比较,查询效率比哈希表高。它有3个基本特性:1)根节点不包含字符,除根节点外每一个节点都只包含

2013-10-04 22:36:16 602

原创 POJ 1384 Piggy-Bank

题意:题目的意思是有一个储蓄罐,里面放了硬币,只知道储蓄罐装了硬币和没装硬币时的重量,并且知道每种面值硬币的重量。现在要求储蓄罐中可能的最小金额。若储蓄罐中硬币的重量和每种面值硬币的重量不能匹配,则输出impossible。分析:典型的完全背包,注意初始化。。//216K 79MS#include #include #include #define MIN(A,

2013-10-02 01:17:16 452

原创 POJ 1047 Round and Round We Go

题意:判断循环数,因为数据较大,需要用到大数乘法分析:大叔乘法不难,关键是在判断时怎么对每种数的个数统计,如果用Int数组存,再比较,太费事。。。祥看我的代码。。 ps,这题discuss说有循环数的规律。。有时间再写下。。 //164K 16MS#include #include #include #include #define N 80using n

2013-10-02 01:06:24 844

原创 POJ 1321 棋盘问题 ( 深搜)

汉语题意,题目类似八皇后问题,深搜即可。。。貌似可以用状态压缩过,有空再研究研究。。 // 172K 63MS#include #include #include #define N 9using namespace std ;bool graph[N][N] ;bool flag[N][N] ;bool column[N] ;int ans ;voidInit

2013-09-30 01:06:00 605

原创 POJ 1118 Lining Up

题意:给出n个点的整数坐标(n思路:简单几何题。采用几何中三个点是否在一条直线判定定理。//180K 500MS#include #include #include #define N 705using namespace std ;struct node{ int x , y ;}node[N];void Solve

2013-09-24 23:43:12 495

原创 POJ 1011 Sticks ( 深搜、剪枝)

经典搜索题,黑书上的剪枝例题。剪枝的空间很大,剪枝前写下朴素的搜索框架(黑字部分),枚举原始木棍的长度及由那些小木棍组合。原始木棍长度一定是小木棍总长度的约数,因此可以减少枚举量。    越长的木棍对后面木棍的约束力越大,因此要把小木棍排序,按木棍长度从大到小搜索,这样就能在尽可能靠近根的地方剪枝。(剪枝一)    如果当前木棍能恰好填满一根原始木棍,但因剩余的木棍无法组合出合法解

2013-09-24 01:19:22 700

原创 POJ 3264 Balanced Lineup

题意:给出初始化的区间值,m次查询。每次查询区间[a,b]的最大值-最小值分析:线段树 更新: 无更新  查询:区间查询, 建立线段树的时候,每个结点存储左右子树的最大值和最小值,  查询时直接访问区间最大值和最小值,不需要查找到最低,查询时间复杂度O(logN)//2384K 1594MS#include #include #include #

2013-09-21 00:02:01 395

原创 POJ 3618 Exploration

简单题。。。 但要注意理解题意,每次都从都选离原点最近的未访问过的点走。。 思路: 将-100,000 ≤ xi ≤ 100,000范围 转换成 0 ~ 200,000   OFFSET(偏移量) 100000 ,由于我是用bool visit[N]。。。虽然代码有点长。。但跑出来的效率比较高。。//376K 63MS#include #include #inclu

2013-09-15 16:58:12 761

原创 POJ 2034 Anti-prime Sequences

题意:输入m, n, d。求出m,m+1,m+2,````m+n的一个排列。使得任意的连续k个数之和都为合数,2思路:素数打表,然后深搜。。//196K 782MS#include #include #include #include #define N 1005#define MAX N*10#define BUG puts("Hi") ;bool pri

2013-09-15 16:14:05 503

原创 POJ 2299 Ultra-QuickSort

题意:给出长度为n的序列,每次只能交换相邻的两个元素,问至少要交换几次才使得该序列为递增序列。题目本质就是求逆序对了,简单介绍一下。逆序对是指在序列{a0,a1,a2...an}中,若aij),则(ai,aj)上一对逆序对。而逆序数顾名思义就是序列中逆序对的个数。例如: 1 2 3是顺序,则逆序数是0;1 3 2中(2,3)满足逆序对的条件,所以逆序数只有1; 3 2 1中(1,2)(1,3)

2013-09-11 22:32:38 488

原创 POJ 1861 Network (最短路)

题意:给出n个点和m条边,求出最小生成树,输出最小生成树权值最大的第一条边,然后再输出最小生成树的边数,以及每一条边//AC//356K 94MS#include #include #define DEBUG puts("Here") ;#define N 1005 // N 定点数上限#define M 15005 // M 边数上限int father[N]

2013-09-11 00:27:35 412

原创 POJ 1251 Jungle Roads ( Prim , Kruscal )

基础的最短路,只是初始化麻烦一些。。不过刚开始老 TEL。。看了discuss 。。才知道数据有问题。。呃。。 改成cin 和cout 就过了。。不过。。。是有空该好好学学C++了= = //252K 0MS#include #include #include #define MAX_COST 105#define N 28#define DEBUG puts("deb

2013-09-08 22:23:58 404

原创 POJ 3979 分数加减法

简单模拟。。。细心就好了。。至于约分问题,我用的是欧几里得算法,两个数的最大公倍数为1即不能再约分,还有就是注意卡精度。。//192K 0MS#include #include #define DEBUG "HERE"#define bool char#define true 1#define false 0#define MIN(X,Y) ((X<Y)?(X):(Y))

2013-09-07 21:40:17 500

空空如也

空空如也

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

TA关注的人

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