自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(56)
  • 资源 (1)
  • 收藏
  • 关注

原创 10044-Erdos number Time limit exceeded

以下是我的代码,但是在通过uva测试是time limit exceeded, 不知道是什么原因,而且我自己测试了几个数据都是对的。#include#include#include#include#include#includeusing namespace std;string Erdos="Erdos, P.";string Scenario="Scenario ";

2013-05-03 15:59:23 1047

原创 Sequential Stack

#ifndef STRUCT_STACK_H#define STRUCT_STACK_Htemplate class structstrack{public: virtual void Push(const T&x)=0; virtual bool Pop(T&x)

2011-07-19 21:13:20 669

原创 sequential list(template,virtual)

<br />#ifndef LINEARLIST_H#define LINEARLIST_H//enum bool{true,false};template<class T>class LinearList{public: LinearList(); //constructor; ~LinearList(); //destructor; virtual int Size()const=0; //get the size of a list; vi

2011-03-15 14:26:00 1031

转载 引入虚函数

<br /><br />C++中实现多态通过函数重载(静态多态)和虚函数(动态多态)两种方式实现,通过将基类中函数定义为虚函数并在派生类中重新定义,从而实现成员函数的动态重载,另外,很多情况下基类不需要生成具体对象,这时通过将基类中成员函数定义为纯虚函数即可实现。具体方法如下:<br />virtual return_type member_function(parameters list)=0;<br />此时含此函数的积累称为抽象类,其派生类中必须对该函数进行重新定义。多态的关键之处就是一切用指向基类的

2011-03-14 16:13:00 706

转载 类的继承

<br />一个私有的或保护的派生类不是子类,因为非公共的派生类不能做基类能做的所有的事,就是指在公开场合,但是在类内部可以的一、引言<br />在C++中,类是提供封装的逻辑单位,类的每一个对象都包含有描述其自身状态的数据集合,并且通过接收特定的消息来处理这个数据集合。如果程序设计人员能够通过增加、修改或替换指定类的部分内容的方法对该类进行剪裁,就可以适应不同的应用,从而在很大程度上增强了数据封装的价值,而接下来要讨论的继承就完全可以实现这种操作。二、与继承有关的基本概念<br />继承是一个进程,通

2011-03-14 15:51:00 807

转载 友元

<br /><br />友元函数和友元类<br /><br /><br />        采用类的机制后实现了数据的隐藏与封装,类的数据成员一般定义为私有成员,成员函数一般定义为公有的,依此提供类与外界间的通信接口。但是,有时需要定义一些函数,这些函数不是类的一部分,但又需要频繁地访问类的数据成员,这时可以将这些函数定义为该函数的友元函数。除了友元函数外,还有友元类,两者统称为友元。友元的作用是提高了程序的运行效率(即减少了类型检查和安全性检查等都需要时间开销),但它破坏了类的封装性和隐藏性,使得非成员函

2011-03-14 15:30:00 577

转载 const 的用法

<br /><br />1.      const常量,如const int max = 100; <br />优点:const常量有数据类型,而宏常量没有数据类型。编译器可以对前者进行类型安全检查,而对后者只进行字符替换,没有类型安全检查,并且在字符替换时可能会产生意料不到的错误。<br />2.      const 修饰类的数据成员。                                                                const数据成员只在某个对象生存期内是常

2011-03-14 15:12:00 505

转载 拷贝构造函数

<br /><br />       为了说明复制构造函数作用,我先说说我们在编程时会遇到的一些问题。对于C++中的函数,我们应该很熟悉了,因为平常经常使用;对于类的对象,我们也很熟悉,因为我们也经常写各种各样的类,使用各种各样的对象;对于指针的操作,我们也不陌生吧?嗯,如果你还不了解上面三个概念的话,我想这篇文章不太适合你,不过看看也无碍^_^。我们经常使用函数,传递过各种各样的参数给函数,不过把对象(注意是对象,而不是对象的指针或对象的引用)当作参数传给函数的情况我们应该比较少遇见吧,而且这个对象的构造

2011-03-14 14:13:00 521

转载 何时生成默认构造函数

假期间闲来无事,就下载了某大师的VC++视频资料。在讲到C++时,说是如果程序员没有自己定义默认构造函数,那么编译器会自动为我们产生一个默认的构造函数。 本来这个错误的认识很多程序员都有,不足为奇。但有这么多年编程经验的高手也有这样的错误认识就不禁让我哑然了。        其实编程语言和我们所用的任何软件没有区别,例如Photoshop、AutoCAD之类。其唯一不同的是我们用的编程语言是基于编译器的,而应用软件是基于我们的编程语言的。        既然我们所用的软件是基于编译器的,那么理解编译器在背后

2011-03-14 10:32:00 1069

原创 typedef用法(c++)转发

<br />[C++语法] 关键字typedef用法(转)<br />C/C++语言中的typedef相信大家已经不陌生,本文对C/C++语言关键字typedef的各种用法作一个介绍。<br />typedef,顾名思义,为“类型定义”,可以解释为:将一种数据类型定义为某一个标识符,在程序中使用该标识符来实现相应数据类型变量的定义。例如:<br /> <br />typedef unsigned int UINT;<br />int main (int argc, char *argv[])<br />{<

2011-03-11 11:25:00 669

原创 summation of four primes

<br />// Summation of Four Primes.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>#include <vector>#include <math.h>using namespace std;bool IsPrime(int x){ int y=(int)sqrt(x*1.0); for(int

2011-03-10 18:42:00 755

原创 Self-describing Sequence ACM

<br />这道题改用数组做的话,效率会更高。我用的是向量。解题思路很简单,就是按照顺序将f(n)列出来,输出你要的那个值。<br />// Self-describing Sequence.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <vector>#include <iostream>using namespace std;int _tmain(in

2011-03-10 15:16:00 1039

原创 Counting-ACM

<br />解题思路:因为Gustavo只会1,2,3,4.但是她总是将4看成是1.所以她实际在做加法是只加了1,2,3三个数字。一个数n最多可以拆成全部由1组成的数,也就是说相加的数最多有n.这样设给出的数(也就是要相加得到的数字)为n, 一共有几个m个数字相加得到n.且m>=1且m<=n.设这m个数字当中有x个1,y个2,z个3.列出方程:x+2*y+3*z=n,x+y+z=m.因为x,y,z都大于等于0.得出z=(n-m-y)/2,x=(3*m-n-y),y<=n-m,y<=3*m-n.这样遍历y的所

2011-03-09 17:06:00 872

原创 A Multiplication Game

<br />这道题目用的是博奕算法。<br />// A Multiplication Game.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>using namespace std;bool Multiplication(long n){ if(n>1&&n<=9)return true; else if(n>9&&n<=18)r

2011-03-09 10:59:00 925

原创 File Fragmentation-ACM

<br />// File Fragmentation.cpp : Defines the entry point for the console application.//#include "stdafx.h"using namespace std;void getBigSmallSize(vector<string> v,int *bigsize,int *smallsize){ *bigsize=v[0].length(); *smallsize=v[0].length();

2011-03-08 10:00:00 892

原创 循环队列

<br />数学之于编程,真可谓是密不可分的啊。今天写了循环队列之后,发现利用求模来得到队首与队尾的编号是一种常用的方法。<br />#ifndef CIRCULARQUEUE_H#define CIRCULARQUEUE_Hconst static int INIT_SIZE=5;template<typename T>class CircularQueue{ T CQueue[INIT_SIZE]; int front; int rear;public: Cir

2011-01-01 12:21:00 515

原创 队列(链表实现)

<br />#ifndef QUEUE_H#define QUEUE_H#include<iostream>template<typename T>struct Node{ T data; struct Node *next;};template<typename T>class Queue{ Node<T> *head; Node<T> *tail; int length;public: Queue(); ~Queue(); bool

2010-12-31 11:17:00 607

原创

<br />#ifndef STACK_H#define STACK_H#include<stdlib.h>const static int INIT_SIZE=100;const static int EXTRA_SIZE=10;template <typename T>class Stack{ T *top; T *base; T *stackarray; int length; int arraySize;public: Stack(); ~

2010-12-30 15:02:00 507

原创 双向链表

<br />每次写数据结构都有不同的收获:动态分配的内存空间,删除动态指针后内存也会消失。 如果两个指针同时指向一个动态分配的内存空间。只需要删除其中一个指针就可以了。<br /> <br />#ifndef DOUBLYLINKEDLIST_H#define DOUBLYLINKEDLIST_H#include "stdafx.h"#include <iostream>using namespace std;/*--definition of data type--*/templa

2010-12-29 11:51:00 635

原创 单链表(动态生成结点)

<br />#ifndef LINKEDLIST_H#define LINKEDLIST_H#include "stdafx.h"#include <iostream>using namespace std;/* ---data definition---*/template <typename T>struct Node /* a node in a list*/{ T data; struct Node *next;};/*---functions dec

2010-12-27 17:11:00 745

原创 How big is it?-ACM

<br />这道题的算法是将大小不同的圆环交叉放置,最大与最小的放在一起,也就是说体积差异最大放在一起。<br />// How Big Is It.cpp : Defines the entry point for the console application.//#include "stdafx.h"using namespace std;int _tmain(int argc, _TCHAR* argv[]){ double CalLength(double r1,doubl

2010-11-22 17:18:00 732

原创 Calculator-Android

最近在学习android,写了一个小calculator,与大家分享。

2010-11-22 14:03:00 651

原创 Birthday Cake

// Birthday Cake.cpp : Defines the entry point for the console application.//#include "stdafx.h"using namespace std;int _tmain(int argc, _TCHAR* argv[]){ int N=0; while(cin>>N) { if(N==0)break; int A,B; int upTwo=0; int downTwo=

2010-11-22 09:59:00 861

原创 The Knights of the Round Table

// The Knights of the Round Table.cpp : Defines the entry point for the console application.//#include "stdafx.h"using namespace std;int _tmain(int argc, _TCHAR* argv[]){ double a, b,c; while(cin>>a>>b>>c) { if(a==EOF)break; double A=

2010-11-04 16:37:00 662

原创 Rope Crisis in Ropeland

// Rope Crisis in Ropeland.cpp : Defines the entry point for the console application.//#include "stdafx.h"using namespace std;const double PI=3.14159265;int _tmain(int argc, _TCHAR* argv[]){ double SolveToL(double x1,double y1,double x2,doubl

2010-11-04 16:02:00 593

原创 Dog and Gopher

// Dog and Gopher.cpp : Defines the entry point for the console application.//#include "stdafx.h"using namespace std;int _tmain(int argc, _TCHAR* argv[]){ bool JudgeEscape(double **H,double gx,double gy,double dx,double dy,int *v,int n); int

2010-11-04 11:35:00 610

原创 Bicoloring

这个是我在一个人的博客上看到的算法,用的是图和深度遍历算法。我自己照他的想法写了程序,发现是可以的。// Bicoloring.cpp : Defines the entry point for the console application.//#include "stdafx.h"const int MAX=200;using namespace std;int graph[MAX][MAX];int colored[MAX];bool visited[MAX];int

2010-10-29 14:22:00 694

原创 Servicing Stations

题目的大概是有n个小站,它们彼此之间一共有m条路,要在这样小站中选出一些建服务站。使得与服务站相连的小站也可以得到服务。问最少可建几个服务站。我的算法是先选出连接最多的那个小站,在这个小站上设服务站,与之相连的就不用设服务站了。去除这个小站以及与它相连的小站。现找剩下最多。以此类推,但是这发现这种算法,有一种情况是不对的,就是剩下中有一个只与与最多小站相连的小站相连。如果有人可以帮忙改进,感谢不尽。// Servicing Stations.cpp : Defines the entry point for

2010-10-27 10:55:00 573

原创 marbles-ACM

<br />算法:设A为弹珠的总数,x,y分别为两种盒子的数目。Z为买这些盒子的花销。那么就有下面的等式:n1*x+n2*y=A,c1*x+c2*y=Z. 如果先救y的话,就要先求出n1与c1的最小公倍数。求最小公倍数的公式有lcm(x,y)=x*y/gcd(x,y),因为x*y可能会超出范围,还有一个公式是(x/gcd(x,y))*y. 利用第二个公式可以求出n1与c1的最小公倍数。设lcm(c1,n1)=a*n1=b*c1. 两式相减得,y=(b*Z-a*A)/(b*c2-a*n2). 因为y>=0,

2010-10-22 14:35:00 733

原创 Factovisors-ACM

<br />算法:(a*b)mod n=((a mod n)*(b mod n))mod n.<br />// Factovisors.cpp : Defines the entry point for the console application.//#include "stdafx.h"using namespace std;int _tmain(int argc, _TCHAR* argv[]){ int Mod(int n,int m); unsigned int n=

2010-10-21 15:55:00 610

原创 Euclid Problem-ACM

<br />算法:假设a>b, ax1+by1=gcd(a,b), 那么bx2+(a-a/b*b)y2=gcd(b,a%b). 根据欧几里德定律可知,gcd(a,b)=gcd(b,a%b), 所以ax1+by1=bx2+(a-a/b*b)y2 =>ay2+bx2-a/b*by2. 又因为相应的项的系数是相等的,所以x1=y2, y1=x2-a/by2, 以些类推,运用递归方法,直到b的系数为0为止。<br />// Euclid Problem.cpp : Defines the entry point f

2010-10-21 15:27:00 603

原创 Light,More Light

<br />// Light More Light.cpp : Defines the entry point for the console application.//#include "stdafx.h"using namespace std;int _tmain(int argc, _TCHAR* argv[]){ int light=0; while(cin>>light) { if(light==0)break; else { int a

2010-10-20 10:45:00 542

原创 Steps-ACM

<br />算法:假设人从1走到n,则有n-1个以单位1的步,如果保证最后一步必需是1的话,那么从迈出最多的那步开始到最后一步要降序。所以关键在于找到最多的那一步是多少。最多的那一步两边应都是降序的,但可重复。原则是尽量以最大的步来走这段路,这样用的步骤才是最少的。<br />所以 (n-1)/2=1+2+3+4....,如果两边以上式一样列出的话,可能会有余数。如果两边的余数相加小于最大步的话,那么其中就会有一步是重复的,如果大于最大步的话,就有两步是重复的。<br /> <br />// Steps.c

2010-10-19 15:14:00 592

原创 How many pieces of land?

<br />这道题目的算法是c(n,4)+c(n,2)+1=(n^4-6*n^3+23*n^2-18*n+24)/24, 如何得出的,我还没有证明出来,如有人知道,可访赐教。谢谢。<br />// How Many Pieces of Land.cpp : Defines the entry point for the console application.//#include "stdafx.h"using namespace std;int _tmain(int argc, _TCHA

2010-10-15 16:01:00 833

原创 How many fibs

<br />// How Many Fibs.cpp : Defines the entry point for the console application.//#include "stdafx.h"using namespace std;int _tmain(int argc, _TCHAR* argv[]){ long a,b; while(cin>>a>>b) { if(a==0&&b==0)break; else { long p=1;

2010-10-15 11:19:00 515

原创 Ones

<br />这道题目,可以用反向思维的方法解决:例如输入是3的话,1111..../3,其实按照除法的运算原则来看,就是先用最高位的1去除3,然后将余数乘以10,再加上下一位的1,现除以3. 以此类推,直到最后一位正好除尽为止。那么我们就可以用这种方法来完成这道题目。<br />// Ones.cpp : Defines the entry point for the console application.//#include "stdafx.h"using namespace std;i

2010-10-11 10:38:00 545

原创 The Archeologist's Dilemma

<br />算法:设x为要求的指数的幂,i为位数,n为给出的数,则n*10^i<2^x<(n+1)*10^i. 对小于号两边取对数,得<br />log2(n)+i*log2(10)<x<log2(n+1)+i*log2(10), 所以只要求出这个范围内的最小正整数就是答案了。<br /> <br />// The Archeologist's Dilemma.cpp : Defines the entry point for the console application.//#include

2010-10-08 14:34:00 585

原创 Primary Arithmetic

<br />// Primary Arithmetic.cpp : Defines the entry point for the console application.//#include "stdafx.h"using namespace std;int _tmain(int argc, _TCHAR* argv[]){ char Data[20]={'/0'}; while(cin.getline(Data,20)) { if(Data[0]=='0'&&Dat

2010-09-29 10:31:00 614

原创 Shoemaker's Problem

<br />// Shoemaker's Problem.cpp : Defines the entry point for the console application.//#include "stdafx.h"using namespace std;int _tmain(int argc, _TCHAR* argv[]){ int testround=0; cin>>testround; cout<<"/n"; while(testround>0) {

2010-09-27 15:55:00 567

原创 Longest Nap

<br />// Longest Nap.cpp : Defines the entry point for the console application.//#include "stdafx.h"using namespace std;int _tmain(int argc, _TCHAR* argv[]){ void CalTime(char **a,int *b,int c,int d); int testround=0;// save the test data tim

2010-09-27 10:03:00 687

android monkey原码

android 测试工具monkey的原码,解压即可。

2010-12-24

空空如也

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

TA关注的人

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