Author Archives: admin

值得推荐的C/C++框架和库【转载】

Libevent

libev是一个开源的事件驱动库,基于epoll,kqueue等OS提供的基础设施。其以高效出名,它可以将IO事件,定时器,和信号统一起来,统一放在事件处理这一套框架下处理。基于Reactor模式,效率较高,并且代码精简(4.15版本8000多行),是学习事件驱动编程的很好的资源。

下载链接:https://github.com/libevent/libevent
Memcached

Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载。它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提供动态数据库驱动网站的速度。Memcached 基于一个存储键/值对的 hashmap。Memcached-1.4.7的代码量还是可以接受的,只有10K行左右。
下载地址:http://memcached.org/
Redis

Redis 是一个使用 C 语言写成的,开源的 key-value 数据库。Redis支持的操作和数据类型比Memcached要多,现在主要用于缓存,支持主从同步机制,Redis的学习可以参考<>一书。
下载地址:http://redis.io/
Webbench

Webbench是一个在linux下使用的非常简单的网站压测工具。它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的性能,最多可以模拟3万个并发连接去测试网站的负载能力。Webbench使用C语言编写, 代码实在太简洁,源码加起来不到600行。
下载链接:https://github.com/LippiOuYang/WebBenchl

Read more »

DXF库(dxflib)使用指南[转载]

作者: Andrew Mustun
版权: 2004-2005 RibbonSoft公司. 保留所有权利。
日期: 2005年3月
原文: http://www.ribbonsoft.com/dxflib/manual.pdf
源码: http://www.ribbonsoft.com/archives/dxflib/dxflib-2.0.4.8-2.src.tar.gz
翻译: 柴树杉(http://chaishushan.googlepages.com )

第一章 简介
dxflib是一个用来读写DXF文件的C++库。当读DXF文件的时候,dxflib分析文件并且调用用户自己定义的函数来添加实体、层、等。
需要注意的是,dxflib并不保存任何实体或者信息。它只是从DXF文件中分析可以识别的实体以及其他的对象。
使用dxflib库读DXF文件并不需要知道所有的DXF格式信息。当然,像实体、属性、层、段等基本概念还是需要了解的。如果是用dxflib库写DXF文件,则需要知道DXF文件是如何组织的。
dxflib完全基于C/C++标准库实现,不依赖任何其他的库。

第二章 编译dxflib库
Unix/Linux
在Unix/Linux系统中编译dxflib库,需要输入以下命令:

./configure
make

该命令生成一个"./lib/dxflib.a"静态库。如果需要创建一个动态连接库,需要用"make shared"代替前面的"make"命令。这样就生成一个"./lib/libdxf.so.2.0.x.x"文件,然后再创建一个"./lib/libdxf.so"连接到"./lib/libdxf.so.2.0.x.x"。
如果不使用"make install"命令,你也可以直接将头文件和生成的库文件复制到你需要的目录中。

Windows
在windows系统中编译dxflib库可以有多中选择,你可以使用VC、Borland C++、GCC以及其他各种编译器。
在这里我们采用cygwin和gcc编译:

./configure
MinGW32-make

Read more »

位移法解平面桁架

最近稍稍闲下来一点,准备系统的学习一下有限元。
一般认为,矩阵位移法是有限元的雏形,并且矩阵位移法与杆系有限元在操作步骤上几乎完全一样。
这里以下图所示桁架为例简单写一下推导过程,详细的教材上都有。

1

单元编号 单元节点编号 节点局部编号
1 1,3 i,j
2 1,2 i,j
3 3,4 i,j
4 2,4 i,j
5 3,2 i,j

......

Read more »

[转载]横向分布系数取值详细介绍(桥博)

关于横向分布调整系数:
一、进行桥梁的纵向计算时:
a) 汽车荷载
1对于整体箱梁、整体板梁等整体结构
其分布调整系数就是其所承受的汽车总列数,考虑纵横向折减、偏载后的修正值。例如,对于一个跨度为230米的桥面4车道的整体箱梁验算时,其横向分布系数应为4 x 0.67(四车道的横向折减系数) x 1.15(经计算而得的偏载系数)x0.97(大跨径的纵向折减系数) = 2.990。汽车的横向分布系数已经包含了汽车车道数的影响。
2多片梁取一片梁计算时
按桥工书中的几种算法计算即可,也可用程序自带的横向分布计算工具来算。计算时中梁边梁分别建模计算,中梁取横向分布系数最大的那片中梁来建模计算。
b) 人群荷载
1对于整体箱梁、整体板梁等整体结构
人群集度,人行道宽度,公路荷载填所建模型的人行道总宽度,横向分布系数填1 即可。因为在桥博中人群效应= 人群集度x人行道宽度x人群横向分布调整系数。城市荷载填所建模型的单侧人行道宽度,若为双侧人行道且宽度相等,横向分布系数填2,因为城市荷载的人群集度要根据人行道宽度计算。
2多片梁取一片梁计算时

Read more »

SPOJ Number Steps 解题报告

1112. Number Steps

Time Limit: 2s Source limit: 50000B

Description

Starting from point (0,0) on a plane, we have written all non-negative integers 0, 1, 2,... as shown in the figure. For example, 1, 2, and 3 has been written at points (1,1), (2,0), and (3, 1) respectively and this pattern has continued.

You are to write a program that reads the coordinates of a point (x, y), and writes the number (if any) that has been written at that point. (x, y) coordinates in the input are in the range 0...10000.

Input

The first line of the input is N, the number of test cases for this problem. In each of the N following lines, there is x, and y representing the coordinates (x, y) of a point.

Output

For each point in the input, write the number written at that point or write No Number if there is none.

Sample Input

3
4 2
6 6
3 4

Sample Output

6
12
No Number

继续水题,而且是以前做过的,找规律即可。

Read more »

SPOJ Adding Reversed Numbers 解题报告

42. Adding Reversed Numbers

Time Limit: 5s Source limit: 50000B

Description

The Antique Comedians of Malidinesia prefer comedies to tragedies. Unfortunately, most of the ancient plays are tragedies. Therefore the dramatic advisor of ACM has decided to transfigure some tragedies into comedies. Obviously, this work is very hard because the basic sense of the play must be kept intact, although all the things change to their opposites. For example the numbers: if any number appears in the tragedy, it must be converted to its reversed form before being accepted into the comedy play.

Reversed number is a number written in arabic numerals but the order of digits is reversed. The first digit becomes last and vice versa. For example, if the main hero had 1245 strawberries in the tragedy, he has 5421 of them now. Note that all the leading zeros are omitted. That means if the number ends with a zero, the zero is lost by reversing (e.g. 1200 gives 21). Also note that the reversed number never has any trailing zeros.

ACM needs to calculate with reversed numbers. Your task is to add two reversed numbers and output their reversed sum. Of course, the result is not unique because any particular number is a reversed form of several numbers (e.g. 21 could be 12, 120 or 1200 before reversing). Thus we must assume that no zeros were lost by reversing (e.g. assume that the original number was 12).

Input

The input consists of N cases (equal to about 10000). The first line of the input contains only positive integer N. Then follow the cases. Each case consists of exactly one line with two positive integers separated by space. These are the reversed numbers you are to add.

Output

For each case, print exactly one line containing only one integer - the reversed sum of two reversed numbers. Omit any leading zeros in the output.

Sample Input

5 5
3
24 1
4358 754
305 794

Sample Output

34
1998
1

水题,把数字翻转过来,相加以后再翻转过去就可以了。一个函数解决。
......

Read more »

SPOJ Prime Generator 解题报告

2. Prime Generator

Time Limit: 6s Source limit: 50000B

Description

Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers!

Input

The input begins with the number t of test cases in a single line (t<=10). In each of the next t lines there are two numbers m and n (1 <= m <= n <= 1000000000, n-m<=100000) separated by a space.

Output

For every test case print all prime numbers p such that m <= p <= n, one number per line, test cases separated by an empty line.

Sample Input

5 5
2
1 10
3 5

Sample Output

2
3
5
7
 
3
5

最近在看一些有限元方面的书,前人所写的程序几乎清一色的都是用Fortran,所以不得不复习一下Fortran了。据说同样的算法用Fortran实现的会比C/C++实现的快25%(当然我没测试过)。不过要找一个支持Fortran的OJ还真是不容易,因为Poj的Fortran编译器不知道出了什么问题,怎么都编译不了,所以只好选择SPOJ了,不过SPOJ支持的语言还真是多,简直可以说是无所不包。

Read more »