c++
smallacmer
这个作者很懒,什么都没留下…
展开
-
C语言宏定义技巧
写好C语言,漂亮的宏定义很重要,使用宏定义可以防止出错,提高可移植性,可读性,方便性 等等。下面列举一些成熟软件中常用得宏定义。。。。。。 1、防止一个头文件被重复包含 #ifndef COMDEF_H #define COMDEF_H //头文件内容 #endif 2、重新定义一些类型,防止由于各种平台和编译器的不同,而产生的类型字节数差异,方便移原创 2012-11-07 12:53:32 · 1026 阅读 · 0 评论 -
多文件结构和编译预处理命令
预处理指令声明预处理指令的一般形式为:# directive tokens符号“#”必须是该行第一个非空白字符,但前面有空白符或退格符都可以,#与directive之间也可以有多个空白符,如下代码具有完全相同的效果:#define size 100#define size 100# define size 100一般一行声明一条预处理指令,但不排除用多行声明原创 2011-11-20 17:41:13 · 643 阅读 · 0 评论 -
实验五运算符重载
。。。。。。。。。。。。。。。#include#includeusing namespace std;class Rational//定义一个有理数类 {public: Rational (int num=0,int denom=1); // Rational() {} ~ Rational() {} int operator<(Rational &r) cons原创 2011-11-17 20:31:17 · 716 阅读 · 0 评论 -
c++文件小测试。。。
实现的功能是让输出终端(即显示器)输出编译器中的内容。。。。#include#include#includeusing namespace std;struct SalaryInfo{ unsigned id; double salary; };int main(){ SalaryInfo employeel={600001,80000}; ofs原创 2011-11-18 18:47:20 · 539 阅读 · 0 评论 -
KMP算法总结
KMP算法:就是按自左向右的方向进行匹配,在匹配过程中,当模式串P不匹配时,应尽量向右移动最大距离,以避免重复比较。假设目标串T=t0,t1,t2,,,,,,tn模式串P=p0,p1,......pm,在模式串匹配的过程中出现了不匹配位ti!=pj,如果下一步比较的是ti和pk,需要满足什么条件呢,一方面有:ti-k,ti-k+1,,,,ti-1=pj-k,pj-k+1,,,,,pj-1;原创 2011-10-30 11:42:57 · 579 阅读 · 0 评论 -
实验三类与对象
#include#include#includeusing namespace std;class Stock{ public: Stock(){count++;} Stock(int a,int b,int c,int d,int e) { this->num=a; this->todaymax=b;原创 2011-11-19 14:44:59 · 1122 阅读 · 0 评论 -
实验七文件的输入输出
1~2#include#include#includeusing namespace std;typedef struct { string name,num; double Buy,Sell,Deal; }Node;Node node[4];int main(){ //输出该编译器的文件。 /*ifstream fin("D:\原创 2011-11-18 20:05:32 · 791 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=1711
Problem DescriptionGiven two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M <= 10000, 1 <= N <= 1000000). Your task is to find a number K which make a[K] = b原创 2011-10-30 11:10:02 · 939 阅读 · 0 评论 -
实验六—虚函数与多态
#include#include#includeusing namespace std;class animal{ public: animal(){} animal(string s,string s1) {name=s,various=s1;} ~animal(){} voi原创 2011-11-17 18:19:49 · 889 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=1162
最小生成树,水题。。。。。#include#define N 105#define M 9999999.0#define FOR(i,s,t) for(int i=(s);i<=(t);++i)#include#include#includeusing namespace std;double map[N][N];bool visit[N];double dist[N];i原创 2011-10-28 22:00:04 · 579 阅读 · 0 评论 -
http://poj.org/problem?id=2983
DescriptionThe galaxy war between the Empire Draco and the Commonwealth of Zibu broke out 3 years ago. Draco established a line of defense called Grot. Grot is a straight line with N defense stati原创 2011-10-26 21:00:36 · 554 阅读 · 0 评论 -
http://poj.org/problem?id=1486
Sorting SlidesTime Limit: 1000MS Memory Limit: 10000K Total Submissions: 2259 Accepted: 828 DescriptionProfessor Clumsey is going to give an important talk this afternoon. Unfortunately, h原创 2011-11-01 19:42:04 · 708 阅读 · 0 评论 -
http://acm.nyist.net/JudgeOnline/problem.php?pid=211&&有向图传递闭包问题
这一题是有向图的传递闭包问题,,,而这提的要求就是输出有多少牛可以确定名次的。算法思想:求出每个牛的出度和入度之和看是否等于n-1(n为牛的个数),我这里是用floyd算法写的,,,#include#include#include#include#define N 105#define FOR(i,s,t) for(int i=(s);i<=(t);++i)using原创 2011-11-02 12:15:11 · 497 阅读 · 0 评论 -
http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?pid=1004&ojid=2&cid=963&hide=0
#include#include#define N 101#define M 99999999.0#define FOR(i,s,t) for(int i=(s);i<=(t);++i)#includeusing namespace std;double map[N][N];double dist[N];bool visit[N];struct point{ double原创 2011-11-03 19:45:33 · 1313 阅读 · 0 评论 -
流迭代器的应用
使用istream_iterator对象从标准输入读一些列的整数,使用ostream—iterator对象将其中的奇数写入到一个文件中,并在给个写入的值后面加上一个空格,同时用另一个ostream—iterator对象将偶数写到第二个文件中,每个写入的值都存放单独的行中。#include#include#include#include#include#include#i原创 2012-09-18 16:32:33 · 576 阅读 · 0 评论 -
使用copy算法将一个文件中的写到标准输出中
#include#include#include#include#include#include#include#include#include#include#include#include#include#define N 1005using namespace std;bool cmp(const int& a,const int&原创 2012-09-18 16:04:17 · 899 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=3790&&最短路径问题
Problem Description给你n个点,m条无向边,每条边都有长度d和花费p,给你起点s终点t,要求输出起点到终点的最短距离及其花费,如果最短距离有多条路线,则输出花费最少的。Input输入n,m,点的编号是1~n,然后是m行,每行4个数 a,b,d,p,表示a和b之间有一条边,且其长度为d,花费为p。最后一行是两个数 s,t;起点s,终点。n和m为0时输入结束。原创 2011-10-20 16:52:08 · 756 阅读 · 0 评论 -
Enumerate the Triangles&&http://cdn.ac.nbutoj.com/Contest/view/id/14/problem/E.xhtml
问题描述 Little E is doing geometry works. After drawing a lot of points on a plane, he want to enumerate all the triangles which the vertexes are three of the points to find out the one with minimum原创 2012-07-14 11:10:27 · 981 阅读 · 0 评论 -
http://acm.nyist.net/JudgeOnline/problem.php?pid=301
http://www.matrix67.com/blog/archives/276原来线性代数中的矩阵有这般用处真是神奇啊,,,递推求值问题=矩阵运算+二分。。代码:#include#includeusing namespace std;typedef long long LL;LL c[3][3];void f(LL a[3][3],LL b[3][3]){ c[原创 2011-11-12 12:25:57 · 1287 阅读 · 2 评论 -
Max Sum &&http://acm.hdu.edu.cn/showproblem.php?pid=1003
这一题和我们oj上的求连续最大子串方法一样,不一样的就是这里需要记录连续子串和的初末位置。。。#include#define N 100001using namespace std;int a[N];int main(){ int n; cin>>n; for(int k=1;k<=n;++k) { int m,i; cin>>m; memset(a,0,原创 2012-01-05 15:14:17 · 1126 阅读 · 0 评论 -
2011百校联动“菜鸟杯”程序设计公开赛&&Cover The Enemy
今天下午又重新温习了菜鸟杯题,,发现好多题就是用枚举方法A掉的,,里面并没有夹杂太多方面的高级算法,,没想到就这题在比赛竟然好些做不出来,,看来自己做的题还是少啊!!!!!思路:这一题求最小半径平方和,先把第一个塔离敌军的营地排一下序(升序,降序都可以),然后枚举所有到第一个塔的距离,通过找第一个塔不能覆盖的敌军阵营离第二个塔最大的距离得出第二个塔的半径,,还有一点要注意就是最找离第二个塔最大原创 2012-01-02 17:15:56 · 952 阅读 · 0 评论 -
c++课程设计
//学生类:#ifndef H_STUDENT_H_NNN#define H_STUDENT_H_NNN#include#include#includeusing namespace std;class Student{ protected: string name; string sex;原创 2011-12-20 16:21:49 · 759 阅读 · 0 评论 -
实验四
#includeusing namespace std;//基类 class MyArray{ public : MyArray(int leng); MyArray() {} ~MyArray() ; void input(); void display();protected: int *alist; int length;};MyArray::MyArray(原创 2011-11-04 16:30:18 · 519 阅读 · 0 评论 -
http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?&&次小生成树
这是个次小生成树的题,首先介绍一下什么事次小生成树,,,就是存在有两个及以上的最小生成树,,,,这一题用krusal TLE。。。因此选用了prim算法,,,,思想就是:如果存在一个点i它的dist【i】可以由两个或两个以上的其他点更新得到,那么最小生成树肯定不唯一了,,,,法一:#include#include#define N 101#define M 99999999usin原创 2011-11-05 11:11:20 · 1175 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=3371
这是今天xd弄的一个专题,,,,很是坑爹,,,c++过了,但是g++就是过不了,,,让我纠结了半个多小时,,,悲催,,,prim算法:#include#include#define N 505#define M 99999999#define FOR(i,s,t) for(int i=(s);i<=(t);++i)using namespace std;int n,m原创 2011-11-03 18:44:26 · 790 阅读 · 0 评论 -
初始化测试,memset,for,fill
#include #include #include #include #include #include #include #include #include using namespace std;class Time{ public: void Start() //开始计时 { start_time=cl原创 2011-10-26 10:53:46 · 570 阅读 · 0 评论 -
运算符重载
#includeusing namespace std;class Clock{ int hour,minute,second; public: Clock(int hour=0,int minute=0,int second=0) ; void showtime()const; Clock& operator++()原创 2011-10-25 17:19:05 · 421 阅读 · 0 评论 -
http://poj.org/problem?id=2965
DescriptionThe game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open a refrigerator.The原创 2011-10-14 18:47:10 · 612 阅读 · 0 评论 -
poj&&1753
http://poj.org/problem?id=1753DescriptionFlip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16原创 2011-10-13 11:40:31 · 508 阅读 · 0 评论 -
氢气球
描述 Ten mathematicians are flying on a balloon over the Pacific ocean. When they are crossing the equator they decide to celebrate this eve原创 2011-09-27 09:59:44 · 811 阅读 · 0 评论 -
Number Sequence
http://poj.org/problem?id=1019DescriptionA single positive integer i is given. Write a program to find the digit located in the positi原创 2011-09-27 17:58:23 · 505 阅读 · 0 评论 -
树状数组&&Color the ball
http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?pid=1003&ojid=0&cid=601&hide=0N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a Input原创 2011-09-25 12:56:35 · 637 阅读 · 0 评论 -
扩展欧几里得&&青蛙的约会
http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?cid=601&pid=1010&ojid=1两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面。它们很高兴地发现它们住在同一条纬度线上,于是它原创 2011-09-25 11:31:37 · 826 阅读 · 0 评论 -
c++&&map函数
c++ Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时候,在编程上提供快速通道。这里说下map内部数据的组织,map内原创 2011-09-22 18:15:40 · 469 阅读 · 0 评论 -
The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest &&Dave
Problem DescriptionRecently, Dave is boring, so he often walks around. He finds that some places are too crowded, for example, the ground.原创 2011-09-23 19:25:11 · 716 阅读 · 0 评论 -
欧拉函数的应用&&Relatives
http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?cid=601&pid=1009&ojid=1Problem DescriptionGiven n, a positive integer, how ma原创 2011-09-24 09:33:08 · 599 阅读 · 0 评论 -
The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest &&To Miss Our Children Time
http://acm.hdu.edu.cn/showproblem.php?pid=4001Problem DescriptionDo you remember our children time? When we are children, we are interes原创 2011-09-22 19:37:05 · 864 阅读 · 0 评论 -
The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest &&The Frog's Games
http://acm.hdu.edu.cn/showproblem.php?pid=4004Problem DescriptionThe annual Games in frogs' kingdom started again. The most famous g原创 2011-09-22 18:01:10 · 530 阅读 · 0 评论 -
亲和串
http://acm.hdu.edu.cn/showproblem.php?pid=2203Problem Description人随着岁数的增长是越大越聪明还是越大越笨,这是一个值得全世界科学家思考的问题,同样的问题Eddy也一直在思考,因为他在很小的时候就知道原创 2011-09-21 13:25:49 · 582 阅读 · 0 评论 -
dijkstra 求最短路径算法
Dijkstra(迪杰斯特拉)算法是典型的最短路径路由算法,用于计算一个节点到其他所有节点的最短路径。主要特点是以起始点为中心向外层层扩展,直到扩展到终点为止。Dijkstra算法能得出最短路径的最优解,但由于它遍历计算的节点很多,所以效率低。Dijkstra算法是很有代原创 2011-10-18 18:12:22 · 976 阅读 · 0 评论