自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(61)
  • 收藏
  • 关注

原创 substr 函数

1.string  substrsubstr(size_type _Off = 0,size_type _Count = npos) const;功能:从一个字符串复制一个从指定位置开始,并具有指定长度的子字符串。2.参数_Off    所需的子字符串的起始位置。字符串中第一个字符的索引为 0,默认值为0._Count    复制的字符数目

2013-08-19 14:31:24 611

原创 map 函数

Map是c++的一个标准容器,它提供了很好一对一的关系,在一些程序中建立一个map可以起到事半功倍的效果,总结了一些map基本简单实用的操作!头文件:#include1. map构造函数;mapmapstring; mapmapint;mapmapstring; mapmapchar;mapmapchar; mapmapint;2. map添加数据;map mapliv

2013-08-19 11:28:18 1372 1

原创 绝对值排序

1.绝对值排序#include>#include>#include>using namespace std;int cmp(const void *a,const void *b){ if((*(int *)a) return *(int *)b-*(int *)a; }int main(){ int n,i,s[101]; while(cin>

2013-08-19 11:25:47 984

原创 C++常用判断函数

1.isalnum()    如果参数为字母数字,则返回ture 2.isalpha()     如果参数为字母,则返回ture 3.iscntrl()       如果参数为控制字符,则返回ture 4.isdigit()       如果参数为数字(0-9),则返回ture5.isgraph()     如果参数为空格之外的打印字符,则返回ture 6.islower() 

2013-08-19 11:23:27 1805

原创 argc,argv知识点

主函数main中变量(int argc,char *argv[ ])的含义    有些编译器允许将main()的返回类型声明为void,这已不再是合法的C++    main(int argc, char **argv[ ], char **env[ ])才是UNIX和Linux中的标准写法。    argc: 整数,用来统计你运行程序时送给main函数的命令行参数的个数    *

2013-08-19 11:20:58 776

原创 平面分割问题

1.题目大致如:n条直线,最多可以把平面分为多少个区域。        当有n-1条直线时,平面最多被分成了f(n-1)个区域。则第n条直线要是切成的区域数最多,就必须与每条直线相交且不能有同一交点。这样就会得到n-1个交点。这些交点将第n条直线分为2条射线和n-2条线断。而每条射线和线断将以有的区域一分为二。这样就多出了2+(n-2)个区域。         故:f(n)=f(n-1)+

2013-08-19 11:19:20 597

原创 hdu——1078——FatMouse and Cheese:记忆化搜索

Problem DescriptionFatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension n: each grid location is labelled (p,q) where 0 <= p < n and 0 <= q < n. At eac

2013-08-17 20:04:26 774

原创 1022——挂盐水

题目描述挂盐水的时候,如果滴起来有规律,先是滴一滴,停一下;然后滴二滴,停一下;再滴三滴,停一下...,现在有一个问题:这瓶盐水一共有VUL毫升,每一滴是D毫升,每一滴的速度是一秒(假设最后一滴不到D毫升,则花费的时间也算一秒),停一下的时间也是一秒这瓶水什么时候能挂完呢?输入格式输入数据包含多个测试实例,每个实例占一行,由VUL和D组成,其中 0输出对于每

2013-08-17 13:57:40 1274

原创 hdu——2594——Simpsons’ Hidden Talents

Problem DescriptionHomer: Marge, I just figured out a way to discover some of the talents we weren’t aware we had.Marge: Yeah, what is it?Homer: Take me for example. I want to find out if I have

2013-08-16 20:27:07 590

原创 hdu——1711——Number Sequence

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

2013-08-16 19:58:51 600

转载 KMP 算法

在介绍KMP算法之前,先介绍一下BF算法。一.BF算法    BF算法是普通的模式匹配算法,BF算法的思想就是将目标串S的第一个字符与模式串P的第一个字符进行匹配,若相等,则继续比较S的第二个字符和P的第二个字符;若不相等,则比较S的第二个字符和P的第一个字符,依次比较下去,直到得出最后的匹配结果。    举例说明:    S:  ababcababa

2013-08-16 16:13:09 564

原创 hdu——1003——Max Sum

Problem DescriptionGiven a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 +

2013-08-16 11:09:37 547

原创 hdu——1232——畅通工程

Problem Description某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇。省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只要互相间接通过道路可达即可)。问最少还需要建设多少条道路?  Input测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数,分别是城镇数目N (

2013-08-16 10:07:25 546

原创 hdu——1856—— More is better

Problem DescriptionMr Wang wants some boys to help him with a project. Because the project is rather complex, the more boys come, the better it will be. Of course there are certain requirements.

2013-08-16 09:35:36 581

原创 hdu——1671——Phone List

Problem DescriptionGiven a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Let’s say the phone catalogue listed these numbers:1. Emergenc

2013-08-14 20:14:06 731

原创 hdu——1251—— 统计难题

Problem DescriptionIgnatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀). Input输入数据的第一部分是一张单词表,每行一个单词,单词的长度不超过10,它们代表的是老师交给Ignatius统计的单词,一个空行代表单词表的结束.第二部分是一连

2013-08-14 17:33:53 592

原创 贴瓷砖1

题目描述有一块大小是 2 * n 的墙面,现在需要用2种规格的瓷砖铺满,瓷砖规格分别是 2 * 1 和 2 * 2,请计算一共有多少种铺设的方法。输入格式输入的第一行包含一个正整数T(T输出输出一共有多少种铺设的方法,每组数据的输出占一行。样例输入32812样例输出31712731#includ

2013-08-14 11:45:15 1651

原创 普利姆(Prim)算法

一.普利姆(Prim)算法思想设:N =(V , E)是个连通网,另设U为最小生成树的顶点集,TE为最小生成树的边集。普利姆(Prim)算法步骤:(1)初始状态: U ={u0 },( u0 ∈V ),TE= φ,(2)在u∈U ,v∈(V-U)所有的边(u,v)∈E中,找一条代价最小的边(u0,v0),并将边(u0,v0)并入集合TE,同时v0并入U。(3)重复(2),直到U

2013-08-14 10:39:01 1626

原创 克鲁斯卡尔(Kruskal)算法

一.克鲁斯卡尔(Kruskal)算法思想考虑问题的出发点:为使生成树上边的权值之和达到最小,则应使生成树中每一条边的权值尽可能的小。克鲁斯卡尔(Kruskal)算法思想:设连通网N=(V,E),令最小生成树初始状态为只有n个顶点而无边的非连通图T=(V,{F}),每个顶点自成一个连通分量在E中选取代价最小的边,若该边依附的顶点落在T中两个不同的连通分量上,则将此边加入到T中;否则,舍去此边

2013-08-14 10:37:33 1367

原创 最小生成树问题

1.概念    http://www.tyut.edu.cn/kecheng1/site01/suanfayanshi/minispantree.asp    根据权值递增的顺序连接两个点2.概述在一给定的无向图G = (V, E) 中,(u, v) 代表连接顶点 u 与顶点 v 的边(即),而 w(u, v) 代表此边的权重,若存在 T 为 E 的子集(即)且为无

2013-08-14 10:32:41 935

原创 hdu ——寒冰王座——完全背包问题

Problem Description不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票(记住,只有一张钞票),为了防止自己在战斗中频繁的死掉,他决定给自己买一些道具,于是他来到了地精商店前.死亡骑士:"我要买道具!"地精商人:"我们这里有三种道具,血瓶150块一个,魔法药200块一个,无敌药水350块一个."死亡骑士:"好的,给我一个血瓶."说完他掏出那张N元的大钞递给地

2013-08-12 20:10:45 580

原创 hdu——2602——Bone Collector 01背包问题

Problem DescriptionMany years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave

2013-08-12 20:01:31 505

原创 hdu——1881——毕业bg 01背包问题

Problem Description每年毕业的季节都会有大量毕业生发起狂欢,好朋友们相约吃散伙饭,网络上称为“bg”。参加不同团体的bg会有不同的感觉,我们可以用一个非负整数为每个bg定义一个“快乐度”。现给定一个bg列表,上面列出每个bg的快乐度、持续长度、bg发起人的离校时间,请你安排一系列bg的时间使得自己可以获得最大的快乐度。例如有4场bg:第1场快乐度为5,持续1小时,

2013-08-12 16:56:07 587

原创 背包问题解析

一.最简单的背包问题----01背包      1.题:有N件物品和一个容量为V的背包。第i件物品的体积是c[i],价值是w[i]。求解将哪些物品装入背包可使这些物品的体积总和不超过背包容量,且价值总和最大。      2.思路:每一个物品可以放也可以不放,因此比较放的时候的价值和不放的时候的价值,用max函数比较      3.方程:  即f[i][v]表示前i件物品恰放入一个容

2013-08-12 16:13:29 595

原创 hdu——Rotten Ropes

Problem DescriptionSuppose we have n ropes of equal length and we want to use them to lift some heavy object. A tear-off weight t is associated to each rope, that is, if we try to lift an object, he

2013-08-11 16:52:11 872

转载 A New Growth Industry

A biologist experimenting with DNA modification of bacteria has found a way to make bacterial colonies sensitive to the surrounding population density. By changing the DNA, he is able to "program" t

2013-08-11 16:27:49 690

原创 hdu——Symmetric Order

Problem DescriptionIn your job at Albatross Circus Management (yes, it's run by a bunch of clowns), you have just finished writing a program whose output is a list of names in nondescending order by

2013-08-11 16:14:06 590

原创 hdu——poj2470—— Ambiguous permutations

Problem DescriptionSome programming contest problems are really tricky: not only do they require a different output format from what you might have expected, but also the sample output does not show

2013-08-11 15:45:46 744

原创 hdu——Error Correction

Problem DescriptionA boolean matrix has the parity property when each row and each column has an even sum, i.e. contains an even number of bits which are set. Here's a 4 x 4 matrix which has the par

2013-08-11 14:47:05 921

原创 hdu——An Easy Problem

As we known, data stored in the computers is in binary form. The problem we discuss now is about the positive integers and its binary form.Given a positive integer I, you task is to find out an

2013-08-11 14:44:57 607

原创 hdu ——Quick Change

J.P. Flathead’s Grocery Store hires cheap labor to man the checkout stations. The people he hires (usually high school kids) often make mistakes making change for the customers. Flathead, who’s a bit

2013-08-11 14:43:36 678

原创 hdu——Knight Moves

Problem DescriptionA friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the shortest closed tour of knight moves that visits each square of a given set of n

2013-08-11 14:42:08 671

原创 HDU——Queuing

Problem DescriptionQueues and Priority Queues are data structures which are known to most computer scientists. The Queue occurs often in our daily life. There are many people lined up at the lunch t

2013-08-06 19:01:23 701

原创 hdu——War

Problem Description      War is the reciprical and violent application of force between hostile political entities aimed at bringing about a desired political end-state via armed conflict. War is an

2013-08-06 14:41:25 705

原创 poj 2393 —— Yogurt factory (贪心)

题意:任务规定,一个酸奶制造厂,在n个星期内,分别要向外提供y[i]unit的酸奶。已知这个制造厂第i周制造每unit酸奶的费用为c[i],储存室储存每1unit酸奶1星期的费用为s。问要完成这个任务的最小费用是多少。#include#includeusing namespace std;int main(){ int n, s, minc = 9999; while(

2013-08-04 17:11:36 655

原创 铁轨

某城市有一个铁轨,有n节车厢从A方向驶入车站,你可以借助一个中转站C,驶入C中的车厢必须按照相反的顺序驶出C,在任意时刻只有两种选择:A->C  ,C->B。#include using namespace std;const int MAX=1000+10;int main(){ int n; while(cin>>n) { if(n==1)

2013-08-04 15:36:33 659

原创 逃离迷宫

Problem Description  给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可以穿越,有些地方是障碍,她必须绕行,从迷宫的一个位置,只能走到与它相邻的4个位置中,当然在行走过程中,gloria不能走到迷宫外面去。令人头痛的是,gloria是个没什么方向感的人,因此,她在行走过程中,

2013-08-03 20:51:55 728

原创 卡片游戏

有一副牌,从第一张牌开始从上往下以此编号1~n,当至少还剩下两张牌的时候:把第一张牌扔掉,然后把新的第一张放到整叠牌的最后,输入n,输出每次扔掉的牌,以及最后剩下的牌#include #include using namespace std;int main(){ int n; queueq; scanf("%d",&n); for(int i=0;i<

2013-08-03 20:42:40 671 1

原创 STL

STL简介:头文件:在C++标准中,STL被组织为下面的13个头文件:algorithm>、deque>、functional>、iterator>、vector>、list>、map>、memory>、numeric>、queue>、set>、stack>和utility>。组成部分:STL可分为容器(containers)、迭代器(iterators)、空间配置器(allo

2013-08-03 20:32:08 566

原创 因子和阶乘

把阶乘n!=1*2*3*4......*n 分解例如 825=3*5*5*11,应表示为(0,1,2,0,1);#include #include using namespace std;int is_prime(int n){ for(int i=2;i*i<=n;i++) { if(n%i==0) return 0;

2013-08-03 20:02:19 562

空空如也

空空如也

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

TA关注的人

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