自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 ACM算法设计---BFS、DFS

点击打开链接

2018-06-02 10:59:54 397

原创 A - 棋盘问题 搜索

在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。Input输入含有多组测试数据。 每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目。 n <= 8 , k <= n 当为-1...

2018-06-01 17:42:21 199

原创 F - Prime Path --BFS广搜

The ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-digit room numbers on their offices. — It is a matter of sec...

2018-05-21 21:40:11 176

原创 筛选法求素数表----埃拉托斯特尼筛法

适用于题目的数据规模较大,常规地逐个判断素数的方法行不通,可以使用筛选法进行预处理,将所有素数一次性求出并存入数组中。分析:从2开始,将每个素数的各个倍数,标记成合数。一个素数的各个倍数,是一个差为此素数本身的等差数列。实现:建立一个bool类型的数组,一个int类型的数组prime储存素数,初始化为0(都是素数),从第一个素数2开始,把2的倍数都标记为非素数(1),直到大于n;然后进行下一趟,找...

2018-05-19 17:31:43 967

原创 Shuffle'm Up ----bfs

A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of poker chips, S1 and S2, each stack containing C chips. Ea...

2018-05-19 15:59:14 183

原创 Prime Ring Problem

A ring is compose of n circles as shown in diagram. Put natural number 1, 2, …, n into each circle separately, and the sum of numbers in two adjacent circles should be a prime. Note: the number o

2018-05-19 15:49:05 277

原创 Prime Ring Problem

A ring is compose of n circles as shown in diagram. Put natural number 1, 2, …, n into each circle separately, and the sum of numbers in two adjacent circles should be a prime. Note: the number o

2018-05-09 20:54:15 117

原创 Wireless Network

Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all compu

2018-05-04 16:56:43 147

原创 u Calculate e

A simple mathematical formula for e is where n is allowed to go to infinity. This can actually yield very accurate approximations of e using relatively small values of n. Output ...

2018-04-23 19:27:08 328

原创 大明A+B

话说,经过了漫长的一个多月,小明已经成长了许多,所以他改了一个名字叫“大明”。 这时他已经不是那个只会做100以内加法的那个“小明”了,现在他甚至会任意长度的正小数的加法。 现在,给你两个正的小数A和B,你的任务是代表大明计算出A+B的值。 Input 本题目包含多组测试数据,请处理到文件结束。 每一组测试数据在一行里面包含两个长度不大于400的正小数A和B。

2018-04-16 21:05:43 159

原创 Children’s Queue

There are many students in PHT School. One day, the headmaster whose name is PigHeader wanted all students stand in a line. He prescribed that girl can not be in single. In other words, either no girl

2018-04-16 20:39:43 721

原创 Hat's Fibonacci

A Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1. F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n>4) = F(n - 1) + F(n-2) + F(n-

2018-04-16 19:59:29 259

原创 大菲波数

Fibonacci数列,定义如下: f(1)=f(2)=1 f(n)=f(n-1)+f(n-2) n>=3。 计算第n项Fibonacci数值。 Input 输入第一行为一个整数N,接下来N行为整数Pi(1<=Pi<=1000)。 Output 输出为N行,每行为对应的f(Pi)。 Sample Input 5 1 2 3 4

2018-04-16 19:32:22 280

原创 N!

Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in one line, process to the end of file. Output For each N, output N! in one line. Sample Input 1 2 3Sample O

2018-04-14 11:27:16 148

原创 A + B Problem II

I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B. Input The first line of the input contains an integer T(1<=T<=20) which means the number

2018-04-14 10:43:25 147

原创 Ignatius and the Princess IV

"OK, you are not too bad, em... But you can never pass the next test." feng5166 says. "I will tell you an odd number N, and then N integers. There will be a special integer among them, you have to tel...

2018-04-13 17:04:48 117

原创 poj 1742coins(优化的多重背包)。。

People in Silverland use coins.They have coins of value A1,A2,A3…An Silverland dollar.One day Tony opened his money-box and found there were some coins.He decided to buy a very nice watch in a nearby s

2018-04-13 16:44:34 187

原创 Sumsets

Farmer John commanded his cows to search for different sets of numbers that sum to a given number. The cows use only numbers that are an integer power of 2. Here are the possible sets of numbers th...

2018-04-11 20:26:11 575

原创 Cow Bowling

The cows don't use actual bowling balls when they go bowling. They each take a number (in the range 0..99), though, and line up in a standard bowling-pin-like triangle like this:  7 ...

2018-04-07 16:57:59 469

原创 天梯 L1-027. 出租

下面是新浪微博上曾经很火的一张图: 一时间网上一片求救声,急问这个怎么破。其实这段代码很简单,index数组就是arr数组的下标,index[0]=2 对应 arr[2]=1,index[1]=0 对应 arr[0]=8,index[2]=3 对应 arr[3]=0,以此类推…… 很容易得到电话号码是18013820100。 本题要求你编写一个程序,为任何一个电话号码生成这段代码 ——

2018-03-30 17:32:25 155

原创 天梯 L1-008. 求整数段和

给定两个整数A和B,输出从A到B的所有整数以及这些数的和。输入格式: 输入在一行中给出2个整数A和B,其中-100<=A<=B<=100,其间以空格分隔。输出格式: 首先顺序输出从A到B的所有整数,每5个数字占一行,每个数字占5个字符宽度,向右对齐。最后在一行中输出全部数字的和。输入样例: -3 8输出样例: -3 -2 -1 0 1 2

2018-03-30 16:18:43 154

原创 天梯 L1-003. 个位数统计

题目 给定一个k位整数N = dk-1*10k-1 + … + d1*101 + d0 (0<=di<=9, i=0,…,k-1, dk-1>0),请编写程序统计每种不同的个位数字出现的次数。例如:给定N = 100311,则有2个0,3个1,和1个3。输入格式: 每个输入包含1个测试用例,即一个不超过1000位的正整数N。输出格式: 对N中每一种不同的个位数字,以D:M的格式在一行

2018-03-30 15:43:15 161

原创 天梯 L1-002. 打印沙漏

题目 本题要求你写个程序把给定的符号打印成沙漏的形状。例如给定17个“*”,要求按下列格式打印***** *** * ******** 所谓“沙漏形状”,是指每行输出奇数个符号;各行符号中心对齐;相邻两行符号数差2;符号数先从大到小顺序递减到1,再从小到大顺序递增;首尾符号数相等。 给定任意N个符号,不一定能正好组成一个沙漏。要求打印出的沙漏能用掉尽可能多的符号。输入

2018-03-30 15:27:03 107

原创 2013年第四届蓝桥杯 黄金连分数

题目 黄金分割数0.61803… 是个无理数,这个常数十分重要,在许多工程问题中会出现。有时需要把这个数字求得很精确。 对于某些精密工程,常数的精度很重要。也许你听说过哈勃太空望远镜,它首次升空后就发现了一处人工加工错误,对那样一个庞然大物,其实只是镜面加工时有比头发丝还细许多倍的一处错误而已,却使它成了“近视眼”!! 言归正传,我们如何求得黄金分割数的尽可能精确的值呢?有许多方法。

2018-03-28 21:42:37 207 1

原创 2012年第三届蓝桥杯C/C++程序设计本科B组 放棋子

题目今有 6 x 6 的棋盘格。其中某些格子已经预先放好了棋子。现在要再放上去一些,使得:每行每列都正好有3颗棋子。我们希望推算出所有可能的放法。下面的代码就实现了这个功能。 初始数组中,“1”表示放有棋子,“0”表示空白。代码int N = 0;bool CheckStoneNum(int x[][6]){ for(int k=0; k<6; k++) { in

2018-03-27 21:21:40 173

原创 C++ vector用法

vector是一个能够存放任意类型的动态数组,能够增加个压缩数据用法1.头文件#include<vector>2.声明及初始化vector<int>vec; //创建vector对象vec.size(); //向量大小vec.max_size(); //向量最大容量vec.resize(

2018-03-16 15:21:48 130

原创 插入,希尔,堆排,归并(mooc选)

插入排序void InsertionSort( ElementType A[], int N ){ /* 插入排序 */ int P, i; ElementType Tmp; for ( P=1; P<N; P++ ) { Tmp = A[P]; /* 取出未排序序列中的第一个元素*/ for ( i=P; i>0 &&

2018-01-22 19:05:42 365

原创 6-4 线性探测法的查找函数

试实现线性探测法的查找函数。函数接口定义: Position Find( HashTable H, ElementType Key );其中HashTable是开放地址散列表,定义如下:#define MAXTABLESIZE 100000 /* 允许开辟的最大散列表长度 */typedef int ElementType; /* 关键词类型用整型 */ty

2017-12-15 15:46:05 4342 2

原创 邻接矩阵存储 - Prim最小生成树算法

Vertex FindMinDist( MGraph Graph, WeightType dist[] ){ /* 返回未被收录顶点中dist最小者 */ Vertex MinV, V; WeightType MinDist = INFINITY; for (V=0; V<Graph->Nv; V++) { if ( dist[V]!=0 && dist[V]

2017-12-04 09:30:13 1131

原创 邻接表存储 - Kruskal最小生成树算法

/*-------------------- 顶点并查集定义 --------------------*/typedef Vertex ElementType; /* 默认元素可以用非负整数表示 */typedef Vertex SetName; /* 默认用根结点的下标作为集合名称 */typedef ElementType SetType[MaxVertexNum]; /* 假设集

2017-12-04 09:29:06 1273

原创 2012年蓝桥杯C/C++题目海盗比酒量

题目 有一群海盗(不多于20人),在船上比拼酒量。过程如下:打开一瓶酒,所有在场的人平分喝下,有几个人倒下了。 再打开一瓶酒平分,又有倒下的,再次重复…… 直到开了第4瓶酒,坐着的已经所剩无几,海盗船长也在其中。 当第4瓶酒平分喝下后,大家都倒下了。 等船长醒来,发现海盗船搁浅了。他在航海日志中写到: “……昨天,我正好喝了一瓶…….奉劝大家,开船不喝酒,喝酒别开

2017-11-17 17:23:00 544

原创 2012年蓝桥杯题目微生物增殖

题目 假设有两种微生物 X 和 Y X出生后每隔3分钟分裂一次(数目加倍),Y出生后每隔2分钟分裂一次(数目加倍)。 一个新出生的X,半分钟之后吃掉1个Y,并且,从此开始,每隔1分钟吃1个Y。 现在已知有新出生的 X=10, Y=89,求60分钟后Y的数目。 如果X=10,Y=90呢? 本题的要求就是写出这两种初始条件下,60分钟后Y的数目。 题目的结果令你震

2017-11-17 15:59:47 225

原创 位运算符

按位与运算符(&) 参加运算的两个数据,按二进制位进行“与”运算。 运算规则:0&0=0; 0&1=0; 1&0=0; 1&1=1; 即:当且仅当同时为1时,结果为1,;否则,为0;(全1为1) 例如:3&5 即 0000 0011 & 0000 0101 = 0000 0001 因此,3&5的值得1。 注:负数按补码形式参加按位与

2017-11-05 15:21:09 245

原创 (PTA)7-1 整数分解为若干项之和

题目 将一个正整数N分解成几个正整数相加,可以有多种分解方法,例如7=6+1,7=5+2,7=5+1+1,…。编程求出正整数N的所有整数分解式子。输入格式: 每个输入包含一个测试用例,即正整数N (0输出格式: 按递增顺序输出N的所有整数分解式子。递增顺序是指:对于两个分解序列N​1={n1,n2,⋯}和N​2={m1,m2,⋯},若存在i使得n1=m1,⋯,n​i=m​i,但是n​i

2017-11-03 17:01:01 2558

原创 2013年第四届蓝桥杯C/C++程序设计本科B组省赛 第39级台阶

小明刚刚看完电影《第39级台阶》,离开电影院的时候,他数了数礼堂前的台阶数,恰好是39级! 站在台阶前,他突然又想着一个问题: 如果我每一步只能迈上1个或2个台阶。先迈左脚,然后左右交替,最后一步是迈右脚,也就是说一共要走偶数步。那么,上完39级台阶,有多少种不同的上法呢? 请你利用计算机的优势,帮助小明寻找答案。代码#includeusing namespace std;i

2017-11-03 16:01:34 346

原创 杭电——find your present (2)

question In the new year party, everybody will get a “special present”.Now it’s your turn to get your special present, a lot of presents now putting on the desk, and only one of them will be yours

2017-09-11 19:08:23 226

空空如也

空空如也

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

TA关注的人

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