自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(69)
  • 问答 (1)
  • 收藏
  • 关注

原创 kmp算法

Given two strings a and b we define ab to be their concatenation. For example, if a = “abc” and b = “def” then ab = “abcdef”. If we think of concatenation as multiplication, exponentiation by a non-negative integer is defined in the normal way: a^0 = “” (t

2020-08-09 15:14:42 162

原创 马拉车算法

给出一个只由小写英文字符a,b,c…y,z组成的字符串S,求S中最长回文串的长度.回文就是正反读都是一样的字符串,如aba, abba等Input输入有多组case,不超过120组,每组输入为一行小写英文字符a,b,c…y,z组成的字符串S两组case之间由空行隔开(该空行不用处理)字符串长度len <= 110000Output每一行一个整数x,对应一组case,表示该组case的字符串中所包含的最长回文长度.Sample InputaaaaababSample Output

2020-08-09 14:09:41 193

原创 哈密顿绕行世界问题

一个规则的实心十二面体,它的 20个顶点标出世界著名的20个城市,你从一个城市出发经过每个城市刚好一次后回到出发的城市。Input前20行的第i行有3个数,表示与第i个城市相邻的3个城市.第20行以后每行有1个数m,m<=20,m>=1.m=0退出.Output输出从第m个城市出发经过每个城市1次又回到m的所有路线,如有多条路线,按字典序输出,每行1条路线.每行首先输出是第几条路线.然后个一个: 后列出经过的城市.参看Sample outputSample Input2 5 201

2020-07-25 21:28:34 156

原创 大学食堂

电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够)。所以大家都希望尽量使卡上的余额最少。某天,食堂中有n种菜出售,每种菜可购买一次。已知每种菜的价格以及卡上的余额,问最少可使卡上的余额为多少。Input多组数据。对于每组数据:第一行为正整数n,表示菜的数量。n<=1000。第二行包括n个正整数,表示每种菜的价格。价格不超过50。第三行包括一个正整数m,

2020-06-10 20:56:58 185

原创 求数列最大和

给定K个整数的序列{ N1, N2, …, NK },其任意连续子序列可表示为{ Ni, Ni+1, …,Nj },其中 1 <= i <= j <= K。最大连续子序列是所有连续子序列中元素和最大的一个,例如给定序列{ -2, 11, -4, 13, -5, -2 },其最大连续子序列为{ 11, -4, 13 },最大和为20。在今年的数据结构考卷中,要求编写程序得到最大和,现在增加一个要求,即还需要输出该子序列的第一个和最后一个元素。Input测试输入包含若干测试用例,

2020-06-10 20:55:36 351

原创 数塔游戏

在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的:有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少?已经告诉你了,这是个DP的题目,你能AC吗?Input输入数据首先包括一个整数C,表示测试实例的个数,每个测试实例的第一行是一个整数N(1 <= N <= 100),表示数塔的高度,接下来用N行数字表示数塔,其中第i行有个i个整数,且所有的整数均在区间[0,99]内。Output对于每个测试实例,输出可能得到的最大和,每

2020-06-10 20:47:57 880

原创 本周总结

判断字符串中是否有别的字符,for循环判断上一个字符串中含有下一个字符串中所有元素,输出yes否则输出no。做了第六周训练题的A题,没做出来,看别人的题解,输入一些单词作为字典,再输入一些单词查找:若某个单词能在字典中找到,则输出correct。若某个单词能通过 变换 或 删除 或 添加一个字符后,在字典中找得到,则输出这些单词,输出顺序根据 输入的字典的字典序。某个单词无论操作与否都无法在字典中找得到,则输出空。明天再做。做了H题求n个字符串的最长公共串枚举第一个字符串的不同长度子串,判断她是否为下

2020-06-07 19:02:14 74

原创 素数筛

Bamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi-shoe is a very popular coach for his success. He needs some bamboos for his students, so he asked his assistant Bi-Shoe to go to the market and buy them. Plenty of Bamboos of all po

2020-06-07 18:56:14 100

原创 数学论

I was trying to solve problem ‘1234 - Harmonic Number’, I wrote the following codelong long H( int n ) {long long res = 0;for( int i = 1; i <= n; i++ )res = res + n / i;return res;}Yes, my error was that I was using the integer divisions only. Ho

2020-06-07 18:54:12 257

原创 剪花布条

一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案。对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢?Input输入中含有一些数据,分别是成对出现的花布条和小饰条,其布条都是用可见ASCII字符表示的,可见的ASCII字符有多少个,布条的花纹也有多少种花样。花纹条和小饰条不会超过1000个字符长。如果遇见#字符,则不再进行工作。Output输出能从花纹布中剪出的最多小饰条个数,如果一块都没有,那就老老实实输出0,每个结果之间应换行。Sample Input

2020-06-07 18:46:38 158 1

原创 割栅栏

Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤ 20,000) planks of wood, each having some integer length Li (1 ≤ Li ≤ 50,000) units. He then purchases a single long board j

2020-06-03 21:53:37 76

原创 All in All

You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever way. Because of pending patent issues we will not discuss in detail how the strings are generated and inserted in

2020-06-03 21:33:23 86

原创 求中位数

FJ is surveying his herd to find the most average cow. He wants to know how much milk this ‘median’ cow gives: half of the cows give as much or more than the median; half give as much or less.Given an odd number of cows N (1 <= N < 10,000) and their

2020-06-03 21:30:10 143

原创 本周总结

做了十五周训练题的D题,因为N=40,结果为245,N=41时,结果为24541=10045%2009=0了训练题的B题,题目的意思是寻找丑数的约数的个数一共有多少个,不包括自己,所谓丑数,就是约数只包含2,3,5,7设2,3,5,7的指数分别为a, b, c, d,则题目给定一个数n,就会有2^a * 3^b * 5^c * 7^d = n, 然后就可以知道了,这个n是由a个2,b个3,c个5以及d个7乘出来的,接下来就可以组合出n的所有因数了,2最少有0个,最多有a个,同理,3,5,7也一样,这样a个

2020-05-31 21:24:05 72

原创 The number of divisors(约数) about Humble Numbers HDU - 1492 (唯一分解定理)

A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, … shows the first 20 humble numbers.Now given a humble number, please write a program to calcul

2020-05-31 21:21:34 101

原创 求大阶乘

WhereIsHeroFrom: Zty, what are you doing ?Zty: I want to calculate N!..WhereIsHeroFrom: So easy! How big N is ?Zty: 1 <=N <=1000000000000000000000000000

2020-05-31 21:16:33 92

原创 素数筛

We know what a base of a number is and what the properties are. For example, we use decimal number system, where the base is 10 and we use the symbols - {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}. But in different bases we use different symbols. For example in binary

2020-05-31 21:12:55 110

原创 log前三位和快速幂取模求后三位

You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nk.InputInput starts with an integer T (≤ 1000), denoting the number of test cases.Each case starts with a line containing

2020-05-27 21:20:18 178

原创 F - 2^x mod n = 1

Give a number n, find the minimum x(x>0) that satisfies 2^x mod n = 1.InputOne positive integer on each line, the value of n.OutputIf the minimum x exists, print a line with 2^x mod n = 1.Print 2^? mod n = 1 otherwise.You should replace x and n wi

2020-05-27 21:17:45 149

原创 乘法逆元

要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1)。Input数据的第一行是一个T,表示有T组数据。每组数据有两个数n(0 <= n < 9973)和B(1 <= B <= 10^9)。Output对应每组数据输出(A/B)%9973。Sample Input21000 5387 123456789Sample Output79226060问(a/b)%9973 ,n=a%9

2020-05-27 21:13:00 87

原创 本周总结

要求你每次只能变换一位数字,并且变换前后的数字都要满足是素数;求最少变换次数,打好素数表,再进行BFS。做了训练题的K题,一开始没看懂,看看别人写的知道咋弄了从数塔的第一层走到最底层,只能沿对角线走,求路径上的数的和的最大值。用的是DP算法,从最底层向上考虑,路径上的和的大小取决于直接取决于下面两个数的大小。因而采用自顶向上方法,逐步向上走,走到最顶层,每次都选择最大的和,这样最后的结果就保存在了最顶层。早上看了训练题的E题,存储二进制时使用了二叉树结构,每一次的试探都不同,直接用下表2i与2i+1区分

2020-05-24 18:03:51 63

原创 小狗逃亡

The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone was a trap, and he tried desperately to get out of this

2020-05-24 17:56:35 81

原创 dp模板

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 3 8 8 1 0 2 7 4 4 .

2020-05-24 17:24:21 196

原创 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 security to change such things every now and then, to keep.

2020-05-24 17:19:03 83

原创 抓牛

Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a pointN(0 ≤N≤ 100,000) on a number line and the cow is at a pointK(0 ≤K≤ 100,000) on the same number line. Farmer John has two modes o...

2020-05-20 22:15:15 180

原创 国际象棋

BackgroundThe knight is getting bored of seeing the same black and white squares again and again and has decided to make a journeyaround the world. Whenever a knight moves, it is two squares in one direction and one square perpendicular to this. The wo..

2020-05-20 21:52:25 194

原创 千岛湖

相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实现。现在政府决定大力发展百岛湖,发展首先要解决的问题当然是交通问题,政府决定实现百岛湖的全畅通!经过考察小组RPRush对百岛湖的情况充分了解后,决定在符合条件的小岛间建上桥,所谓符合条件,就是2个小岛之间的距离不能小于10米,也不能大于1000米。当然,为了节省资金,只要求实现任意2个小岛之间有路通即可。其中桥的价格为 100元/米。Input输入包括多组数据。输入首先包括一个整数T(T &l

2020-05-17 22:22:16 265

原创 本周总结

做了二分图题,做了I题又是一个二分图,挺裸的二分图,很快就写出来了。看了看啊哈算法关于树问题。 做了训练题的C题,题目大意是就是何处一个图,n个顶点和m条边,每个边都有最大承载量,现在我要从1点运送货物到n点,求能运送货物的最大重量。第一行为t代表测试数据个数,第二行为n和m(意义见上),接着m行,每行三个整数分别是代表一条边的起点,终点及最大承重量。输出能运送货物的最大重量。注意两个换行从点1到点n,很多条路径,每条路径都有一个最小的权值,求这些最小的权值里的最大值。写了

2020-05-17 22:14:59 66

原创 还是畅通工程

省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可)。现得到城镇道路统计表,表中列出了任意两城镇间修建道路的费用,以及该道路是否已经修通的状态。现请你编写程序,计算出全省畅通需要的最低成本。Input测试输入包含若干测试用例。每个测试用例的第1行给出村庄数目N ( 1< N < 100 );随后的 N(N-1)/2 行对应村庄间道路的成本及修建状态,每行给4个正整数,分别是两个村庄的编号(从1编号到N),此两村庄间道路的成本

2020-05-17 20:59:39 112

原创 畅通工程

某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离。省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可),并要求铺设的公路总长度为最小。请计算最小的公路总长度。Input测试输入包含若干测试用例。每个测试用例的第1行给出村庄数目N ( < 100 );随后的N(N-1)/2行对应村庄间的距离,每行给出一对正整数,分别是两个村庄的编号,以及此两村庄间的距离。为简单起见,村庄从1到N编号。当N为0时,输入结束,该用例不被处

2020-05-17 20:51:23 259 1

原创 Floyd 算法

某省自从实行了很多年的畅通工程计划后,终于修建了很多路。不过路多了也不好,每次要从一个城镇到另一个城镇时,都有许多种道路方案可以选择,而某些方案要比另一些方案行走的距离要短很多。这让行人很困扰。现在,已知起点和终点,请你计算出要从起点到终点,最短需要行走多少距离。Input本题目包含多组数据,请处理到文件结束。每组数据第一行包含两个正整数N和M(0<N<200,0<M<1000),分别代表现有城镇的数目和已修建的道路的数目。城镇分别以0~N-1编号。接下来是M行道路信息。每

2020-05-13 20:42:09 206

原创 二分图最大分配

Adam and Eve play a card game using a regular deck of 52 cards. The rules are simple. The players sit on opposite sides of a table, facing each other. Each player gets k cards from the deck and, after looking at them, places the cards face down in a row on

2020-05-12 21:47:31 226

转载 二分图最大分配

RPG girls今天和大家一起去游乐场玩,终于可以坐上梦寐以求的过山车了。可是,过山车的每一排只有两个座位,而且还有条不成文的规矩,就是每个女生必须找个个男生做partner和她同坐。但是,每个女孩都有各自的想法,举个例子把,Rabbit只愿意和XHD或PQK做partner,Grass只愿意和linle或LL做partner,PrincessSnow愿意和水域浪子或伪酷儿做partner。考虑到经费问题,boss刘决定只让找到partner的人去坐过山车,其他的人,嘿嘿,就站在下面看着吧。聪明的Acme

2020-05-12 21:20:06 164

原创 Prime Time

Euler is a well-known matematician, and, among many other things, he discovered that the formula n 2 + n + 41 produces a prime for 0 ≤ n < 40. For n = 40, the formula produces 1681, which is 41 ∗ 4...

2020-04-30 20:28:06 82

原创 求后序

Little Valentine liked playing with binary trees very much. Her favorite game was constructing randomly looking binary trees with capital letters in the nodes.This is an example of one of her creati...

2020-04-30 20:20:29 94

原创 求后序

A binary tree is a finite set of vertices that is either empty or consists of a root r and two disjoint binary trees called the left and right subtrees. There are three most important ways in which th...

2020-04-30 20:11:31 57

原创 本周总结

最近学了树和stl算法做了D,求后序,如果存在左子树或右子树就直接输出,如果不存在左子树或右子树就返回上一层,找到根节点,即为前序序列的第一个。哈弗曼树假设有n个权值,则构造出的哈夫曼树有n个叶子结点。 n个权值分别设为 w1、w2、…、wn,则哈夫曼树的构造规则为:(1) 将w1、w2、…,wn看成是有n 棵树的森林(每棵树仅有一个结点);(2) 在森林中选出两个根结点的...

2020-04-26 23:07:47 66

原创 出现次数最多的单词

Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will cou...

2020-04-26 23:03:50 253

原创 统计单词数

lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数。下面你的任务是帮助xiaoou333解决这个问题。Input有多组数据,每组一行,每组就是一篇小文章。每篇小文章都是由小写字母和空格组成,没有标点符号,遇到#时表示输入结束。Output每组只输出一个整数,其单独成行,该整数代表一篇文章里不同单词的总数。Sample In...

2020-04-26 22:28:11 122

原创 N皇后问题

在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上。你的任务是,对于给定的N,求出有多少种合法的放置方法。Input共有若干行,每行一个正整数N≤10,表示棋盘和皇后的数量;如果N=0,表示结束。Output共有若干行,每行一个正整数,表示对应输入行的皇后的不同放置数量。Sample Inp...

2020-04-26 22:07:41 220

空空如也

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

TA关注的人

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