- 博客(48)
- 收藏
- 关注
原创 HDU 2112 hdu today(巨坑的题)
HDU - 2112我感觉这题没什么好说的,就是坑人啊,这数据怎么想都有问题,他给的n条路里面居然可能不包括起点和终点别问我怎么知道的,我这么写的代码wa了得十遍,不包括起点和终点,题干你为什么不告诉我一声呢???然后这道题思路其实不难,如何把字符串转换成数字标记,即把数字与字符串联系起来便于最短路的遍历,不难想到map,如果不是有坑肯定一遍过了。。。#include#i
2018-01-29 19:18:20 373
原创 HDU 2544 最短路(Floyd + Dijkstra + SPFA + 使用链式前向星优化的SPFA + 浅谈最短路)
自己最近状态莫名浮躁,有点急于求成了,鹏哥讲的最短路和最小生成树我都只会写最简单的算法,这么下去题是做多了,水平也不会有什么提高,强迫自己多去练习和掌握更好的方法吧这里写一道最短路水题的多种实现最短路HDU - 2544首先是相当容易实现的Floyd,我估计比赛基本用不到这种简单的算法,这里不多解释直接挂代码#include#include#include#include
2018-01-27 19:30:42 249
原创 POJ 3360 Cow Contest
H - Cow ContestPOJ - 3660感觉鹏哥出的题对我不太友善,水一会别的最短路,看到这道题懵逼好一会没想到和最短路有什么关系,然后敲出来自己认为正确的代码(实际wa):#include#include#include#include#include#include#include#include#includeusing namespace std;
2018-01-26 19:53:30 176
原创 HDU 1874 畅通工程续
畅通工程续:HDU - 1874这道题简单最短路Floyd就能ac,之前做过这类题感觉十分easy,保持好心情#include#include#include#include#include#include#include#include#includeusing namespace std;#define inf 0x3f3f3f3fint mapp[1005][1
2018-01-25 21:03:49 110
原创 POJ 1287 Networking(最小生成树模板)+ HDU 1863 畅通工程
B - Networking POJ - 1287可谓很基础的模板题,问题就是用prim堆优化做一直无法ac,但是kruscal(并查集写法)很好写networking 之 kruscal:#include#include#include#include#include#include#include#include#includeus
2018-01-25 20:19:42 227
转载 最小生成树prim算法之优先队列(链式前向星)
我们首先来看一下什么是前向星.前向星是一种特殊的边集数组,我们把边集数组中的每一条边按照起点从小到大排序,如果起点相同就按照终点从小到大排序,并记录下以某个点为起点的所有边在数组中的起始位置和存储长度,那么前向星就构造好了.用len[i]来记录所有以i为起点的边在数组中的存储长度.用head[i]记录以i为边集在数组中的第一个存储位置.
2018-01-24 16:16:06 1218 2
原创 HDU 3746 Cyclic Nacklace
D - Cyclic Nacklace HDU - 3746做多了KMP感觉这东西其实很简单,核心就是利用好next数组,这道题也是这样,除了理解错题意wa两遍之外还是挺顺利的#include#include#include#include#include#include#include#include#includeusing names
2018-01-22 21:44:47 98
原创 HDU 1686 Oulipo
B - Oulipo HDU - 1686The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member of the Oulipo group. A quote from the book:
2018-01-22 21:15:07 158
原创 POJ 1182食物链(经典并查集算法改进)
E - 食物链 POJ - 1182动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。 现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。 有人用两种说法对这N个动物所构成的食物链关系进行描述: 第一种说法是"1 X Y",表示X和Y是同类。 第二种说法是"2 X Y",
2018-01-21 13:32:49 166
原创 HDU 1358 Period
E - Period HDU - 1358题意 :给定字符串s,把所有长度大于一的前缀看成一个新的的字符串,问是否该字符串中存在循环节,如果存在有几个?输出前缀长度和循环次数 这道题还是考察对next数组的应用,硬生生地做成了一道找规律的题,然后tletletle,队长说这道题可以总结出一个定理,怎么又是定理啊。。。其实思路和答案已经非常接近了,没有多想一步,只是
2018-01-20 10:04:12 130
原创 磊磊的随机数 (简单set)
1209.磊磊的随机数Time Limit: 1000 MS Memory Limit: 32768 KBTotal Submission(s): 138 Accepted Submission(s): 71 Description磊磊想在学校中请一些同学一起做一项问卷调查,为了实验的客观性,他先用计算机生成了N个1到1000
2018-01-19 19:11:20 187
原创 HDU 3336 Count The String
K - Count the string HDU - 3336题意:例如abab这样的字符串的子字符串看为有a,ab,aba,abab四种,就是从第一个开始,每次加一个元素,也就是所有的非空前缀,其中a,ab在原字符串中出现两次,aba,abab各出现一次,所以一共六次,结果要%10007 对,每次都是从0开始更新,很慢分析一下这个a...
2018-01-19 18:37:20 575
转载 KMP next数组详解
http://www.cnblogs.com/yjiyjige/p/3263858.html这位同学用详细的图文模式讲解了KMP算法,非常适合入门。----------------------------------------------------------------------------------------------KMP的next数组求法是很不容易搞清楚的一部分,也是最重要的一
2018-01-19 17:35:46 231
原创 POJ 2752 Seek the Name, Seek the Fame
H - Seek the Name, Seek the Fame POJ - 2752The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to
2018-01-19 17:27:45 108
原创 KMP的创造next数组代码及常用的字符串比较代码
哎,老是忘了next数组应该怎么编号,记下来下次直接方便提醒自己一句话概括next数组作用: kmp思想:对字符串进行预处理,记录与当前位置i前缀相同的“最近”位置,用next[i]记录#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#include&...
2018-01-18 21:02:44 153
原创 POJ 2406 Power Strings
G - Power Strings POJ - 2406Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". I
2018-01-18 20:43:22 120
原创 HDU 2087 剪花布条
C - 剪花布条 HDU - 2087一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案。对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢? Input 输入中含有一些数据,分别是成对出现的花布条和小饰条,其布条都是用可见ASCII字符表示的,可见的ASCII字符有多少个,布条的花纹也有多少种花样。花纹条和小饰条不会
2018-01-18 16:18:44 120
原创 HDU 1711 Number Sequence(KMP入门)
A - Number Sequence HDU - 1711Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 Input The first line of input is a number T which indicat
2018-01-17 21:31:02 172
原创 HDU 1257 最少拦截系统
I - 最少拦截系统HDU - 1257某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹.怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以
2018-01-16 21:01:07 113
原创 HDU 1004 Let The Balloon Rise (简单map)
H - Let the Balloon RiseHDU - 1004Contest 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 ...
2018-01-16 19:29:25 143
原创 HDU 1087 Super Jumping! Jumping! Jumping!
E - Super Jumping! Jumping! Jumping!HDU - 1087Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this
2018-01-15 20:35:42 127
原创 HDU 1029 (dp水题)
B - Ignatius and the Princess IVHDU - 1029"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
2018-01-15 19:08:38 385 2
原创 POJ 1163 The Triangle + HDU 2084 数塔(递推dp)
B - The TrianglePOJ - 116373 88 1 02 7 4 44 5 2 6 5(Figure 1)Figure 1 shows a number triangle. Write a program that calculates the highest sum of numbers passed on a route th...
2018-01-15 18:45:49 175
转载 欧拉函数
转载出处:http://blog.csdn.net/wangjian8006Euler函数欧拉函数是求小于x并且和x互质的数的个数通式:φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)…..(1-1/pn)其中p1, p2……pn为x的所有质因数,x是不为0的整数φ(1)=1(唯一和1互质的数就是1本身)【注意:每种质因数只一个。比如12=2*2*3
2018-01-14 16:19:22 122
原创 POJ 1308 Is It A Tree?
N - Is It A Tree?POJ - 1308A tree is a well-known data structure that is either empty (null, void, nothing) or is a set of one or more nodes connected by directed edges between nodes satisfying
2018-01-09 12:38:20 140
原创 HDU 1272 小希的迷宫
M - 小希的迷宫HDU - 1272上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走。但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就是说如果有一个通道连通了房间A和B,那么既可以通过它从房间A走到房间B,也可以通过它从房间B走到房间A,为了提高难度,小希希望任意两个房间有且仅有一条路径可以相通(除非走了回
2018-01-08 16:50:25 143
转载 算法导论--最小生成树(Kruskal和Prim算法)
转载自:勿在浮沙筑高台http://blog.csdn.net/luoshixian099/article/details/51908175关于图的几个概念定义:连通图:在无向图中,若任意两个顶点vi与vj都有路径相通,则称该无向图为连通图。强连通图:在有向图中,若任意两个顶点vi与vj都有路径相通,则称该有向图为强连通图。连通网:在连通图中,若图的边具有一定的意义,每一条边都对应着一
2018-01-07 17:21:51 193
原创 POJ 1847 Tram(简单最短路之Floyd)
N - TramPOJ - 1847Tram network in Zagreb consists of a number of intersections and rails connecting some of them. In every intersection there is a switch pointing to the one of the rails going o
2018-01-07 17:00:08 643
原创 POJ 2387 Til the Cows Come Home(最短路模板)**
A - Til the Cows Come HomePOJ - 2387 Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the morning milking. Bessie needs he...
2018-01-06 18:56:08 132
原创 Light oj 1259 Goldbach's Conjecture
F - Goldbach`s ConjectureLightOJ - 1259Goldbach's conjecture is one of the oldest unsolved problems in number theory and in all of mathematics. It states:Every even integer, greater than 2, ca
2018-01-06 12:26:23 184
原创 UVA 11827 Maximum GCD
V - Maximum GCDUVA - 11827#include#include#include#include#include#include#include#include#includeusing namespace std;int gcd(int a, int b){// if(b == 0)// return a;//
2018-01-05 23:42:14 192
原创 HDU 2161 Primes (判断素数的水题)
U - PrimesHDU - 2161 Write a program to read in a list of integers and determine whether or not each number is prime. A number, n, is prime if its only divisors are 1 and n. For this problem, the
2018-01-05 20:47:14 659
原创 Light oj 1370 Bi-shoe and Phi-shoe(素数打表 + 欧拉函数)
A - Bi-shoe and Phi-shoeLightOJ - 1370很郁闷的一道数论,用到的欧拉函数,这算是第一次做用到高级知识的数论问题哈哈,做的可以说相当郁闷#include#include#include#include#include#include#include#include#includeusing namespace std;int mai
2018-01-05 20:02:56 190
转载 最短路的四种算法
1、floyd 核心代码只有五行 for(int k=1; kfor(int i=1; ifor(int j=1; j{ if(map1[i][j]>map1[i][k]+map1[k][j]) map1[i][j]=map1[i][k]+map1[k][j]; } 这种算法可以找多源最短路,想知道a点到b点最短路,只能加入中间点来缩短路径,比如a到b 加入中间
2018-01-05 18:42:40 1655 1
原创 POJ 3126 Prime Path
F - Prime PathPOJ - 3126The 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 of
2018-01-04 22:49:33 195
原创 利用数组筛选素数(降低时间复杂度)
#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<vector>#include<set>#include<map>#include<queue>#include&
2018-01-04 21:59:22 605 1
原创 POJ 2236 Wireless Network
A - Wireless NetworkPOJ - 2236An 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 aft
2018-01-03 23:20:45 113
原创 HDU 1241 Oil Deposits(dfs入门级别模板题)
L - Oil DepositsHDU - 1241The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, an
2018-01-03 19:25:04 219
原创 POJ 1611 The Suspects(简单模板题)
B - The SuspectsPOJ - 1611Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to
2018-01-03 12:47:11 226
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人