传送门:Arbitrage
Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose that 1 US Dollar buys 0.5 British pound, 1 British pound buys 10.0 French francs, and 1 French franc buys 0.21 US dollar. Then, by converting currencies, a clever trader can start with 1 US dollar and buy 0.5 10.0 0.21 = 1.05 US dollars, making a profit of 5 percent.
Your job is to write a program that takes a list of currency exchange rates as input and then determines whether arbitrage is possible or not.
The input will contain one or more test cases. Om the first line of each test case there is an integer n (1<=n<=30), representing the number of different currencies. The next n lines each contain the name of one currency. Within a name no spaces will appear. The next line contains one integer m, representing the length of the table to follow. The last m lines each contain the name ci of a source currency, a real number rij which represents the exchange rate from ci to cj and a name cj of the destination currency. Exchanges which do not appear in the table are impossible.
Test cases are separated from each other by a blank line. Input is terminated by a value of zero (0) for n.
For each test case, print one line telling whether arbitrage is possible or not in the format “Case case: Yes” respectively “Case case: No”.
1 | 3 |
1 | Case 1: Yes |
判断是否存在使得汇率增多的环,任意一个点的汇率增多都可以。
跟POJ-1860差不多,懒得写了。
1 |
|
Several currency exchange points are working in our city. Let us suppose that each point specializes in two particular currencies and performs exchange operations only with these currencies. There can be several points specializing in the same pair of currencies. Each point has its own exchange rates, exchange rate of A to B is the quantity of B you get for 1A. Also each exchange point has some commission, the sum you have to pay for your exchange operation. Commission is always collected in source currency.
For example, if you want to exchange 100 US Dollars into Russian Rubles at the exchange point, where the exchange rate is 29.75, and the commission is 0.39 you will get (100 - 0.39) * 29.75 = 2963.3975RUR.
You surely know that there are N different currencies you can deal with in our city. Let us assign unique integer number from 1 to N to each currency. Then each exchange point can be described with 6 numbers: integer A and B - numbers of currencies it exchanges, and real RAB, CAB, RBA and CBA - exchange rates and commissions when exchanging A to B and B to A respectively.
Nick has some money in currency S and wonders if he can somehow, after some exchange operations, increase his capital. Of course, he wants to have his money in currency S in the end. Help him to answer this difficult question. Nick must always have non-negative sum of money while making his operations.
The first line of the input contains four numbers: N - the number of currencies, M - the number of exchange points, S - the number of currency Nick has and V - the quantity of currency units he has. The following M lines contain 6 numbers each - the description of the corresponding exchange point - in specified above order. Numbers are separated by one or more spaces. 1<=S<=N<=100, 1<=M<=100, V is real number, 0<=V<=103.
For each point exchange rates and commissions are real, given with at most two digits after the decimal point, 10-2<=rate<=102, 0<=commission<=102.
Let us call some sequence of the exchange operations simple if no exchange point is used more than once in this sequence. You may assume that ratio of the numeric values of the sums at the end and at the beginning of any simple sequence of the exchange operations will be less than 104.
If Nick can increase his wealth, output YES, in other case output NO to the output file.
1 | 3 2 1 20.0 |
1 | YES |
某城市有M(1<=M<=100)个货币兑换站,可以兑换N(1<=N<=100)种货币,每个兑换站只能互换两种货币,且汇率与手续费各不相同。某人初始时手中有V元货币S,问他是否有可能通过货币兑换,在最后换回货币S时实现盈利,有可能则输出YES,否则输出NO。
抽象成图模型,兑换途径即为路径.
问题转换为判断图中是否存在一个正环.
1 |
|
ACM国际大学生程序设计竞赛(英语:ACM International Collegiate Programming Contest, ICPC)是由美国计算机协会(ACM)主办的,一项旨在展示大学生创新能力、团队精神和在压力下编写程序、分析和解决问题能力的年度竞赛。经过30多年的发展,ACM国际大学生程序设计竞赛已经发展成为最具影响力的大学生计算机竞赛。
不管在什么时候,算法都是计算机科学领域最重要的基石之一。ACMer扎实的算法基础和编程能力更受企业青睐。
软件ACM集训队是我校竞争力最强的工作室之一,每年软件ACM集训队都会派出队伍参加ACM亚洲区域赛,国赛,省赛以及各种程序设计竞赛,并多次取得不俗的成绩。
软件ACM集训队提供了一个良好的学习环境,学习,其实最重要的是环境。
与全国各大高校同台竞技,开阔视野,让你见识到这个领域内最牛逼的那一批同龄人是怎样的水准,自己距离他们有多大的差距。
很多往届学长在 BAT 等知名公司就职,会有很多内推机会。
ACM竞赛成绩对考研有很大加成。
公费旅游
我们主要参加以下几类竞赛:
ACM-ICPC World Final (雾ACM-ICPC国际大学生程序设计竞赛亚洲区域赛ACM-ICPC国际大学生程序设计竞赛各省省赛以及邀请赛CCPC中国大学生程序设计竞赛"蓝桥杯"竞赛CCCC“中国高校计算机大赛-团体程序设计天梯赛”以及其他类型的编程竞赛
虽然不同比赛规则大相径庭,但最为广泛通用是以ACM-ICPC竞赛为基础的规则。
ACM-ICPC以团队的形式代表各学校参赛,每队由3名队员组成。
比赛期间,每队使用1台计算机需要在5个小时内使用C、C++或Java中的一种编写程序解决8到13个问题。程序完成之后提交裁判运行,运行的结果会判定为”AC(正确)/WA(错误)/TLE(超时)/MLE(超出内存限制)/RE(运行错误)/PE(格式错误)”中的一种并及时通知参赛队。每队在正确完成一题后,组织者将在其位置上升起一只代表该题颜色的气球。最后的获胜者为正确解答题目最多且总用时最少的队伍。每道试题用时将从竞赛开始到试题解答被判定为正确为止,其间每一次提交运行结果被判错误的话将被加罚20分钟时间,未正确解答的试题不记时。
与其它计算机程序竞赛(例如国际信息学奥林匹克,IOI)相比,ACM-ICPC赛制的特点在于其为3人团队作战且题量大,每队需要5小时内完成11道题目,甚至更多。除此之外,一支队伍有3名队员却只有1台计算机,使得时间显得更为紧张。因此除了扎实的编程能力,良好的团队协作和心理素质同样是获胜的关键。
我们会在军训结束后进行简单的C语言培训,国庆期间也会组织有关C语言和简单算法的集训,所有人都可以报名参加。不要担心零基础的问题,我们保证讲到你们听懂为止。我们会在集训后举办一系列的招选拔赛和月赛,根据名次来决定具体的人选,具体请加入2018软件ACM迎新群:839634547
特别感谢计科ACM工作室,尤其要感谢hpc大佬
我们采用在线评测系统(online judge)进行训练
本校oj地址:
www.nswoj.com (软院搭建 仅内网登录)fzhai.xin (软院搭建)nyoj.top (计科搭建)acm.nyist.edu.cn (老OJ)
不论是学习,生活还是什么方面的问题都会有学长学姐耐心解答。
如果高中有信息学竞赛(NOIP)的经历,可以直接联系我们
最终解释权归南阳理工学院软件学院ACM集训队所有
]]>传送门:自杀游戏
Alice和Bob产生了不可调节的矛盾,于是他们相约一起玩一个自杀游戏,输的人就会从这个世界上消失。
游戏开始时,Alice手上拿着一个定时炸弹,炸弹有个倒计时t。炸弹在t=0时刻会爆炸,此时手上拿着炸弹的人会从这个世界上消失。为了增加游戏乐趣,他们约定每个人拿到炸弹后可以选择将炸弹的时间调快d秒(d ∈ [a,b]),或者不调。每次交换炸弹会消耗1秒(假设调节炸弹时间不需要消耗时间)。
问题来了,如果双方都足够聪明,谁会活下去呢?
第一行有三个整数t,a,b,分别表示炸弹初始时刻的倒计时,可调节时间的范围。(0 ≤ t ≤ 10^5,1 ≤ a ≤ b ≤ 10)
若Alice存活则输出”Alice”,若Bob存活则输出”Bob”。
1 | 6 3 4 |
1 | Alice |
Alice只需要将炸弹调快3秒后再给Bob,Bob就会拿到一个2秒后爆炸的炸弹。
友好的中文题面
所以我们可以假定一个状态state[t]表示炸弹时间为t的存活状态,
state[t]==1表示Alice在t时刻存活,Bob死亡,
state[t]==0表示在t时刻Alice死亡, Bob存活.
然后每次可以调控[a,b]的时间,同时传递炸弹需要1秒,
所以,我们的状态可以这样转移:
当state[t-(b+1)]...state[t-(a+1)]存在一个state[x]==0时 state[t] = 1 或者 当 state[t-1]==0时 state[t] = 1
可以理解为: 如果时间为炸弹[t-1]或者[t-(b+1)]~[t-(a+1)]的游戏的结果都是最优解了,而现在炸弹的时间增加了,所以如果在过去的一段区间出现Alice死亡的结局,那么现在就可以翻转这个结局了.
1 |
|
传送门:CSL分苹果
CSL手上有n个苹果,第i个苹果的质量是wi,现在他想把这些苹果分给他的好朋友wavator和tokitsukaze。但是CSL为了不让他们打架,根据质量决定尽量地均分成两堆分给他们。现在CSL想知道到底给每个人分多少质量的苹果。
注意:苹果不能劈开来,并且如果不能正好均分,tokitsukaze小姐姐会拿到重的那一堆。
第一行输入一个整数n(2 ≤ n ≤ 100),第二行n个整数,表示每个苹果的质量wi(1 ≤ wi≤ 100)。
输出两个整数,分别表示wavator和tokitsukaze得到的苹果的质量。
1 | 3 |
1 | 2 4 |
又是友好的中文题面
一道比较经典的01背包问题。
因为,它要两个人的质量差尽量小,同时苹果不能分割,所以把总质量的一半作为01背包的最大容量,然后尽可能的取最大质量。
把总质量除以二作为最大容量,每一个苹果的花费和收益都是它的重量,然后就是一个裸的01背包。
1 |
|
传送门:谁是神射手
有一天,MWH突然来了兴致,想和CSL比比谁枪法好。于是他们找来了一个瓶子,比比看谁先打中这个瓶子。 给定MWH的命中率和CSL的命中率。 两人轮流射击,MWH先手,问谁获胜的概率大?
输入两个整数a和b,表示MWH和CSL的命中率。
若MWH获胜的概率大,则输出”MWH”。 若CSL获胜的概率大,则输出”CSL”,否则输出”equal”。
1 | 100 100 |
1 | MWH |
中文题面
先手获胜的概率是:先手和后手均失败了n 次后先手成功。即
$ a\sum ^{\infty }_{i=0}\left( 1-a\right) ^{i}\left( 1-b\right) ^{i}=\dfrac {a}{1-\left( 1-a\right) \left( 1-b\right) } $
同理,后手获胜的概率为
$ a\sum ^{\infty }_{i=0}\left( 1-a\right) ^{i+1}\left( 1-b\right) ^{i}=\dfrac {b\left( 1-a\right) }{1-\left( 1-a\right) \left( 1-b\right) } $
1 |
|
传送门:Photo of The Sky
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x,y), such that x1≤x≤x2 and y1≤y≤y2, where (x1,y1) and (x2,y2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it’s impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
The first line of the input contains an only integer n (1≤n≤100000), the number of points in Pavel’s records.
The second line contains 2⋅n integers a1, a2, …, a2⋅n (1≤ai≤109), coordinates, written by Pavel in some order.
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel’s records.
1 | 4 |
1 | 1 |
给你2n个数,任意组合得到n个坐标点,求最小矩形面积能够框住这n个点。
我们先将这2n个数排序得到a1,a2…a2n,然后考虑一下问题的转化:我们应该如何计算矩形的面积?
因为矩形是要求把这n个点框住的,所以稍微想一下不难得到:S=(max(x)−min(x))∗(max(y)−min(y))
于是我们将原问题这样转化:给你2n个数,把这2n个数放在两个集合当中,每个集合的元素个数为n,设这两个集合分别为X,Y, 求min((Xmax−Xmin)∗(Ymax−Ymin))
接下来我们来讨论,如何分放集合。
考虑如果最大数a2n与最小数a1如果在同一个集合X,那么现在我们要求min(Ymax−Ymin)。
考虑一下怎样的情况才会有min(Ymax−Ymin)的情况出现。假设Ymin在a中为ai,那么Ymax在a中一定为ai+n−1,为什么呢?
如果Ymax在ai+1−>ai+n−2之间,那么Y集合里面的元素个数就没有要求的n个了,不满足。
如果Ymax在ai+n−>a2n−1之间,那么显然可以在满足元素个数为n的情况下使Ymax最小。
所以在最大数a2n与最小数a1如果在同一个集合X时,答案的值为:
Ans=min(a[2n]−a[1])∗(a[i+n−1]−a[i])2≤i≤n
那么还有一种情况就是最大数a2n与最小数a1不在同一个集合当中,与上面类似的讨论不难得到最后的结果唯一:
Ans=(a[2n]−a[n+1])∗(a[n]−a[1])
所以我们最后的结果在上面两者之间取最小即可。
简单方法就排序后,选其中连续的n个数作为x,剩下的按序作为y, 然后用xmax-xmin乘ymax-ymin 取最小解即可
1 |
|
Ivan has n songs on his phone. The size of the i-th song is ai bytes. Ivan also has a flash drive which can hold at most m bytes in total. Initially, his flash drive is empty.
Ivan wants to copy all n songs to the flash drive. He can compress the songs. If he compresses the i-th song, the size of the i-th song reduces from ai to bi bytes (bi<ai).
Ivan can compress any subset of the songs (possibly empty) and copy all the songs to his flash drive if the sum of their sizes is at most m. He can compress any subset of the songs (not necessarily contiguous).
Ivan wants to find the minimum number of songs he needs to compress in such a way that all his songs fit on the drive (i.e. the sum of their sizes is less than or equal to m).
If it is impossible to copy all the songs (even if Ivan compresses all the songs), print “-1”. Otherwise print the minimum number of songs Ivan needs to compress.
The first line of the input contains two integers n and m (1≤n≤105,1≤m≤109) — the number of the songs on Ivan’s phone and the capacity of Ivan’s flash drive.
The next n lines contain two integers each: the i-th line contains two integers ai and bi (1≤ai,bi≤109, ai>bi) — the initial size of the i-th song and the size of the i-th song after compression.
If it is impossible to compress a subset of the songs in such a way that all songs fit on the flash drive, print “-1”. Otherwise print the minimum number of the songs to compress.
1 | 4 21 |
1 | 2 |
In the first example Ivan can compress the first and the third songs so after these moves the sum of sizes will be equal to 8+7+1+5=21≤21. Also Ivan can compress the first and the second songs, then the sum of sizes will be equal 8+4+3+5=20≤21. Note that compressing any single song is not sufficient to copy all the songs on the flash drive (for example, after compressing the second song the sum of sizes will be equal to 10+4+3+5=22>21).
In the second example even if Ivan compresses all the songs the sum of sizes will be equal 8+4+1+4=17>16.
给出 n 首歌曲压缩前与压缩后的大小,以及优盘的空间 m,求最少压缩几首歌能将所有歌放入优盘,如果放不进去输出 -1
贪心,先判断所有歌曲压缩后的大小是否小于m,如果大于,则说明放不进去,输出 -1,然后再将所有歌曲按照可压缩空间的大小排序,不断计算压缩值统计压缩数量即可。
1 |
|
传送门:The Phone Number
Mrs. Smith is trying to contact her husband, John Smith, but she forgot the secret phone number!
The only thing Mrs. Smith remembered was that any permutation of n can be a secret phone number. Only those permutations that minimize secret value might be the phone of her husband.
The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.
The secret value of a phone number is defined as the sum of the length of the longest increasing subsequence (LIS) and length of the longest decreasing subsequence (LDS).
A subsequence ai1,ai2,…,aik where 1≤i1<i2<…<ik≤n is called increasing if ai1<ai2<ai3<…<aik. If ai1>ai2>ai3>…>aik, a subsequence is called decreasing. An increasing/decreasing subsequence is called longest if it has maximum length among all increasing/decreasing subsequences.
For example, if there is a permutation [6,4,1,7,2,3,5], LIS of this permutation will be [1,2,3,5], so the length of LIS is equal to 4. LDS can be [6,4,1], [6,4,2], or [6,4,3], so the length of LDS is 3.
Note, the lengths of LIS and LDS can be different.
So please help Mrs. Smith to find a permutation that gives a minimum sum of lengths of LIS and LDS.
The only line contains one integer n (1≤n≤105) — the length of permutation that you need to build.
Print a permutation that gives a minimum sum of lengths of LIS and LDS.
If there are multiple answers, print any.
1 | 4 |
1 | 3 4 1 2 |
In the first sample, you can build a permutation [3,4,1,2]. LIS is [3,4] (or [1,2]), so the length of LIS is equal to 2. LDS can be ony of [3,1], [4,2], [3,2], or [4,1]. The length of LDS is also equal to 2. The sum is equal to 4. Note that [3,4,1,2] is not the only permutation that is valid.
In the second sample, you can build a permutation [2,1]. LIS is [1] (or [2]), so the length of LIS is equal to 1. LDS is [2,1], so the length of LDS is equal to 2. The sum is equal to 3. Note that permutation [1,2] is also valid.
给定一个数n,构造一个1-n的序列使得其中的最长上升子序列和最长下降子序列的和最短
将 n 分成 m 块, 其中每一块中的数字是递增的,各个块之间是递减的,则最长上升子序列的长度和最长下降子序列的长度和最小,为m+(n/m),由基本不等式可知,当 m 为 √n 时 m+(n/m) 的值最小。
1 |
|
On Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules are somewhat different from ours. The game is played on an ice game board on which a square mesh is marked. They use only a single stone. The purpose of the game is to lead the stone from the start to the goal with the minimum number of moves.
Fig. 1 shows an example of a game board. Some squares may be occupied with blocks. There are two special squares namely the start and the goal, which are not occupied with blocks. (These two squares are distinct.) Once the stone begins to move, it will proceed until it hits a block. In order to bring the stone to the goal, you may have to stop the stone by hitting it against a block, and throw again.
Fig. 1: Example of board (S: start, G: goal)The movement of the stone obeys the following rules:
At the beginning, the stone stands still at the start square.
The movements of the stone are restricted to x and y directions. Diagonal moves are prohibited.
When the stone stands still, you can make it moving by throwing it. You may throw it to any direction unless it is blocked immediately(Fig. 2(a)).
Once thrown, the stone keeps moving to the same direction until one of the following occurs:
The stone hits a block (Fig. 2(b), (c)).
The stone stops at the square next to the block it hit.
The block disappears.
The stone gets out of the board.
The game ends in failure.
The stone reaches the goal square.
The stone stops there and the game ends in success.
You cannot throw the stone more than 10 times in a game. If the stone does not reach the goal in 10 moves, the game ends in failure.
Fig. 2: Stone movementsUnder the rules, we would like to know whether the stone at the start can reach the goal and, if yes, the minimum number of moves required.
With the initial configuration shown in Fig. 1, 4 moves are required to bring the stone from the start to the goal. The route is shown in Fig. 3(a). Notice when the stone reaches the goal, the board configuration has changed as in Fig. 3(b).
Fig. 3: The solution for Fig. D-1 and the final board configuration
The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. The number of datasets never exceeds 100.
Each dataset is formatted as follows.
the width(=w) and the height(=h) of the board
First row of the board
…
h-th row of the boardThe width and the height of the board satisfy: 2 <= w <= 20, 1 <= h <= 20.
Each line consists of w decimal numbers delimited by a space. The number describes the status of the corresponding square.
0 vacant square
1 block
2 start position
3 goal position
The dataset for Fig. D-1 is as follows:6 6
1 0 0 2 1 0
1 1 0 0 0 0
0 0 0 0 0 3
0 0 0 0 0 0
1 0 0 0 0 1
0 1 1 1 1 1
For each dataset, print a line having a decimal integer indicating the minimum number of moves along a route from the start to the goal. If there are no such routes, print -1 instead. Each line should not have any character other than this number.
1 | 2 1 |
1 | 1 |
每一次碰到障碍则在障碍的旁边停下来,并且障碍被击碎。此时可以重新值掷一次冰球。当掷球次数超过 10 次则输出 -1。
最短路的变型,直接暴力怼就好。
BFS也可以做,但这题涉及到地图的变化,更适合用DFS回溯。注意减枝。
1 |
|
Given a number of distinct decimal digits, you can form one integer by choosing a non-empty subset of these digits and writing them in some order. The remaining digits can be written down in some order to form a second integer. Unless the resulting integer is 0, the integer may not start with the digit 0.
For example, if you are given the digits 0, 1, 2, 4, 6 and 7, you can write the pair of integers 10 and 2467. Of course, there are many ways to form such pairs of integers: 210 and 764, 204 and 176, etc. The absolute value of the difference between the integers in the last pair is 28, and it turns out that no other pair formed by the rules above can achieve a smaller difference.
The first line of input contains the number of cases to follow. For each case, there is one line of input containing at least two but no more than 10 decimal digits. (The decimal digits are 0, 1, …, 9.) No digit appears more than once in one line of the input. The digits will appear in increasing order, separated by exactly one blank space.
For each test case, write on a single line the smallest absolute difference of two integers that can be written from the given digits as described by the rules above.
1 | 1 |
1 | 28 |
给定若干位十进制数,你可以通过选择一个非空子集并以某种顺序构建一个数。剩余元素可以用相同规则构建第二个数。除非构造的数恰好为0,否则不能以0打头。
若总数字数是偶数,组出来的两个数字的长度必相等,若是奇数,长度必差一
对所有数字排列,求 data[:N//2], data[N//2:] 的差及可 AC
注意须排除有前导 0 的情况。
1 |
|
7 パズルは 8 つの正方形のカードとこれらのカードがぴたりと収まる枠で構成されています。それぞれのカードには、互いに区別できるように 0, 1, 2, …, 7 と番号がつけられています。枠には、縦に 2 個、横に 4 個のカードを並べることができます。
7 パズルを始めるときには、まず枠にすべてのカードを入れます。枠のなかで 0 のカードだけは、上下左右に隣接するカードと位置を交換することができます。たとえば、枠の状態が図(a) のときに、0 のカードの右に隣接した、7 のカードと位置を交換すれば、図(b) の状態になります。あるいは、図(a) の状態から 0 のカードの下に隣接した 2 のカードと位置を交換すれば図(c) の状態になります。図(a) の状態で 0 のカードと上下左右に隣接するカードは 7 と 2 のカードだけなので、これ以外の位置の入れ替えは許されません。
ゲームの目的は、カードをきれいに整列して図(d) の状態にすることです。最初の状態を入力とし、カードをきれいに整列するまでに、必要な最小手数を出力するプログラムを作成してください。ただし、入力されたカードの状態からは図(d) の状態に移ることは可能であるとします。
入力データは、1 行に 8 つの数字が空白区切りで与えられます。これらは、最初の状態のカードの並びを表します。例えば、図(a) の数字表現は0 7 3 4 2 5 1 6 に、図(c) は 2 7 3 4 0 5 1 6 となります。(a) 0 7 3 4 2 5 1 6 の場合
(b) 7 0 3 4 2 5 1 6 の場合
(c) 2 7 3 4 0 5 1 6 の場合
(d) 0 1 2 3 4 5 6 7 (最終状態)
上記形式で複数のパズルが与えられます。入力の最後まで処理してください。 与えられるパズルの数は 1,000 以下です。
各パズルについて、最終状態へ移行する最小手数を1行に出力してください。
1 | 0 1 2 3 4 5 6 7 |
1 | 0 |
只有牌0才能和四周的牌交换,给定一个状态,求到图d状态最少需要多少步
bfs反向处理打表,用map存入每个状态。
1 |
|
传送门:Aizu-055 Cheese
今年も JOI 町のチーズ工場がチーズの生産を始め,ねずみが巣から顔を出した.JOI 町は東西南北に区画整理されていて,各区画は巣,チーズ工場,障害物,空き地のいずれかである.ねずみは巣から出発して全てのチーズ工場を訪れチーズを 1 個ずつ食べる.
この町には,N 個のチーズ工場があり,どの工場も1種類のチーズだけを生産している.チーズの硬さは工場によって異なっており,硬さ 1 から N までのチーズを生産するチーズ工場がちょうど 1 つずつある.
ねずみの最初の体力は 1 であり,チーズを 1 個食べるごとに体力が 1 増える.ただし,ねずみは自分の体力よりも硬いチーズを食べることはできない.
ねずみは,東西南北に隣り合う区画に 1 分で移動することができるが,障害物の区画には入ることができない.チーズ工場をチーズを食べずに通り過ぎることもできる.すべてのチーズを食べ終えるまでにかかる最短時間を求めるプログラムを書け.ただし,ねずみがチーズを食べるのにかかる時間は無視できる.
入力は H+1 行ある.1 行目には 3 つの整数 H,W,N (1 ≤ H ≤ 1000,1 ≤ W ≤ 1000,1 ≤ N ≤ 9) がこの順に空白で区切られて書かれている.2 行目から H+1 行目までの各行には,’S’,’1’, ‘2’, …, ‘9’,’X’,’.’ からなる W 文字の文字列が書かれており,各々が各区画の状態を表している.北から i 番目,西から j 番目の区画を (i,j) と記述することにすると (1 ≤ i ≤ H, 1 ≤ j ≤ W),第 i+1 行目の j 番目の文字は,区画 (i,j) が巣である場合は ‘S’ となり,障害物である場合は ‘X’ となり,空き地である場合は ‘.’ となり,硬さ 1, 2, …, 9 のチーズを生産する工場である場合はそれぞれ ‘1’, ‘2’, …, ‘9’ となる.入力には巣と硬さ 1, 2, …, N のチーズを生産する工場がそれぞれ 1 つずつある.他のマスは障害物または空き地であることが保証されている.ねずみは全てのチーズを食べられることが保証されている.
すべてのチーズを食べ終えるまでにかかる最短時間(分)を表す整数を 1 行で出力せよ.
1 | 3 3 1 |
1 | 4 |
在H * W的地图上有N个奶酪工厂,每个工厂分别生产硬度为1-N的奶酪。有一只老鼠准备从出发点吃遍每一个工厂的奶酪。老鼠有一个体力值,初始时为1,每吃一个工厂的奶酪体力值增加1(每个工厂只能吃一次),且老鼠只能吃硬度不大于当前体力值的奶酪。 老鼠从当前格到上下左右相邻的无障碍物的格需要时间1单位,有障碍物的格不能走。走到工厂上时即可吃到该工厂的奶酪,吃奶酪时间不计。问吃遍所有奶酪最少用时。 输入:第一行三个整数H(1 <= H <= 1000)、W(1 <= W <=1000)、N(1 <= N <= 9),之后H行W列为地图, “.“为空地, ”X“为障碍物,”S“为老鼠洞, 1-N代表硬度为1-N的奶酪的工厂。输出最少用时。
分段处理区间最小路径,最后累加即可。
1 |
|
FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual”Farmer of the Year” competition. In this contest every farmer arranges his cows in a line and herds them past the judges.
The contest organizers adopted a new registration scheme this year: simply register the initial letter of every cow in the order they will appear (i.e., If FJ takes Bessie, Sylvia, and Dora in that order he just registers BSD). After the registration phase ends, every group is judged in increasing lexicographic order according to the string of the initials of the cows’ names.
FJ is very busy this year and has to hurry back to his farm, so he wants to be judged as early as possible. He decides to rearrange his cows, who have already lined up, before registering them.
FJ marks a location for a new line of the competing cows. He then proceeds to marshal the cows from the old line to the new one by repeatedly sending either the first or last cow in the (remainder of the) original line to the end of the new line. When he’s finished, FJ takes his cows for registration in this new order.
Given the initial order of his cows, determine the least lexicographic string of initials he can make this way.
- Line 1: A single integer: N
- Lines 2..N+1: Line i+1 contains a single initial (‘A’..’Z’) of the cow in the ith position in the original line
The least lexicographic string he can make. Every line (except perhaps the last one) contains the initials of 80 cows (‘A’..’Z’) in the new line.
1 | 6 |
1 | ABCBCD |
给定一个长度为N的字符串S,T是一个空串,每次从头部或尾部删除一个字符加到T的尾部,构造字典序最小的字符串T。
不断取开头或末尾中较小的一个字符到T中,注意两边相等的情况,还有坑点是输出格式是80行换行。
1 |
|
Saruman the White must lead his army along a straight path from Isengard to Helm’s Deep. To keep track of his forces, Saruman distributes seeing stones, known as palantirs, among the troops. Each palantir has a maximum effective range of R units, and must be carried by some troop in the army (i.e., palantirs are not allowed to “free float” in mid-air). Help Saruman take control of Middle Earth by determining the minimum number of palantirs needed for Saruman to ensure that each of his minions is within R units of some palantir.
The input test file will contain multiple cases. Each test case begins with a single line containing an integer R, the maximum effective range of all palantirs (where 0 ≤ R ≤ 1000), and an integer n, the number of troops in Saruman’s army (where 1 ≤ n ≤ 1000). The next line contains n integers, indicating the positions x1, …, xn of each troop (where 0 ≤ xi ≤ 1000). The end-of-file is marked by a test case with R = n = −1.
For each test case, print a single integer indicating the minimum number of palantirs needed.
1 | 0 3 |
1 | 2 |
In the first test case, Saruman may place a palantir at positions 10 and 20. Here, note that a single palantir with range 0 can cover both of the troops at position 20.
In the second test case, Saruman can place palantirs at position 7 (covering troops at 1, 7, and 15), position 20 (covering positions 20 and 30), position 50, and position 70. Here, note that palantirs must be distributed among troops and are not allowed to “free float.” Thus, Saruman cannot place a palantir at position 60 to cover the troops at positions 50 and 70.
从n个点中选择若干个进行标记,对于每一个点,其距离为R的区域以内必须有带标记的点,问最少有多少点被标记。
标记从最左边的点开始,距离为R以内的最远的点。对于添加了符号的点右侧,相距超过R的下一个点,采用同样的方法找到其右侧R距离以内最远的点添加标记。
1 |
|
传送门:A-Fruit Ninja
Fruit Ninja is a juicy action game enjoyed by millions of players around the world, with squishy,
splat and satisfying fruit carnage! Become the ultimate bringer of sweet, tasty destruction with every slash.
Fruit Ninja is a very popular game on cell phones where people can enjoy cutting the fruit by touching the screen.
In this problem, the screen is rectangular, and all the fruits can be considered as a point. A touch is a straight line cutting
thought the whole screen, all the fruits in the line will be cut.
A touch is EXCELLENT if $ \dfrac {M}{N} $ ≥ x, (N is total number of fruits in the screen, M is the number of fruits that cut by the touch, x is a real number.)
Now you are given N fruits position in the screen, you want to know if exist a EXCELLENT touch.
The first line of the input is T(1≤ T ≤ 100), which stands for the number of test cases you need to solve.
The first line of each case contains an integer N (1 ≤ N ≤ 104) and a real number x (0 < x < 1), as mentioned above.
The real number will have only 1 digit after the decimal point.
The next N lines, each lines contains two integers xi and yi (-109 ≤ xi,yi ≤ 109), denotes the coordinates of a fruit.
For each test case, output “Yes” if there are at least one EXCELLENT touch. Otherwise, output “No”.
1 | 2 |
1 | Yes |
给你n个点,再给你一个p(数据保证0 < p < 1,且p只有1位小数),问是否满足图中有n*p个点在一条直线上
随机两个点,然后再看其它所有点 是否在这条直线上即可,随机1000+AC没问题
1 |
|
In order to become a magical girl, Thinking-Bear are learning magic circle.
He first drew a regular polygon of N sides, and the length of each side is a.
He want to get a regular polygon of N sides, and the polygon area is no more than L.
He doesn’t want to draw a new regular polygon as it takes too much effort.
So he think a good idea, connect the midpoint of each edge and get a new regular polygon of N sides.
How many operations does it need to get the polygon he want?
The first line of the input is T(1≤ T ≤ 100), which stands for the number of test cases you need to solve.
The first line of each case contains three space-separated integers N, a and L (3 ≤ N ≤ 10, 1 ≤ a ≤ 100, 1 ≤ L ≤ 1000).
For each test case, output a single integer.
1 | 1 |
1 | 1 |
给出一个正多边形和多边形的每一条边的边长,然后给出一个面积,求每次在正多边形的的边取中点,然后连接各个中点,形成一个新的正多边形,问经过几次这次这样的操作后能使面积小于L。
计算几何,关键是操作后的面积与原面积比为 $ \cos ^{2}\left( 180^{\circ }\div n\right) $ ,坑点是double的精度问题。
内角:正n边形的内角和度数为: (n-2)×180°;正n边形的一个内角是 (n-2)×180°÷n.
外角:正n边形外角和等于n·180°-(n-2)·180°=360°,所以正n边形的一个 外角为: 360°÷n.
所以正n边形的一个 内角也可以用这个公式: 180°-360°÷n.中心角:任何一个正多边形,都可作一个 外接圆,多边形的中心就是所作外接圆的圆心,
就是这条边所对的弧的圆心角,因此这个角就是360度÷边数。正多边形 中心角:360°÷n
因此可证明,正n边形中, 外角= 中心角= 360°÷n对角线:在一个正多边形中,所有的顶点可以与除了他相邻的两个顶点的其他顶点连线,就
成了相邻的点)个三角形。三角形 内角和:180度,所以把边数减2乘上180度,就是这个正多
边形的内角和 。面积:设正n边形的半径为R,边长为an,中心角为αn,边心距为rn,则αn=360°÷n,
an=2Rsin(180°÷n),rn=Rcos(180°÷n),R^2=r n^2+(an÷2)^2, 周长pn=n×an,面积
Sn=pn×rn÷2。
1 |
|
In mathematics, matrix multiplication or matrix product is a binary operation that produces a matrix from two matrices with entries in a field, or, more generally, in a ring or even a semiring. The matrix product is designed for representing the composition of linear maps that are represented by matrices. Matrix multiplication is thus a basic tool of linear algebra, and as such has numerous applications in many areas of mathematics, as well as in applied mathematics, physics, and engineering. In more detail, if A is an n x m matrix and B is an m x p matrix, their product AB is an n x p matrix, in which the m entries across a row of A are multiplied with the m emtries down a column of B and summed to produce an entry of AB. When two linear maps are represented by matrices, then the matrix product represents the composition of the two maps.
We can only multiply two matrices if their dimensions are compatible, which means the number of columns in the first matrix is the same as the number of rows in the second matrix.
If A is an n x m matrix and B is an m x p matrix,the matrix product C = AB is defined to be the n x p matrix
such that
,
for i = 1,2, …, n and j = 1,2, …, p.
Your task is to design a matrix multiplication calculator to multiply two matrices and
display the output. If the matrices cannot be multiplied, display “ERROR”.
The first line of the input is T(1≤ T ≤ 100), which stands for the number of test cases you need to solve.
For each test case, the first line contains four integers m, n, p and q (1 ≤ m,n,p,q ≤ 20). m and n represent the dimension of matrix A, while p and q represent the dimension of matrix B.
The following m lines consist of the data for matrix A followed by p lines that contains the data for matrix B. (-100 ≤ aij ≤ 100, -100 ≤ bij ≤ 100).
For each test case, print the case number and the output of the matrix multiplication.
1 | 2 |
1 | Case 1: |
矩阵相乘
模板题
1 |
|
传送门:2018 ACM 国际大学生程序设计竞赛上海大都会赛
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛
2018-08-05 12:00:00 至 2018-08-05 17:00:00
时长: 5小时
难度差不多介于省赛和区域赛之间吧。开题A是计算几何,有点思路后就先放下去写签到题,B读错题WA一发,K直接套模板,然后就接着看A。之前写过类似题,没注意数据范围就头铁地交了发n3的代码,TE后才发现数据范围是之前那道十多倍,就听学长的先看D。推十分钟公式无果后打算直接暴力打表,算到最后三个多边形时,HSQ大佬先推出公式(Orz),改过精度问题之后也过了就回去改A。改成n2代码后还是TE,至此一切都结束了。
太TM菜,四个月了还是只能写基础题
4类题解肯定没有的,3类题解先填坑,慢慢补吧。
]]>
- A Fruit Ninja
- B Perfect Numbers(签到)
- C Rescue
- D Thinking-Bear magic
- E Thinking-Bear’s necklace
- F Color it
- G External Square
- H A Simple Problem with Integers
- I Matrix Game
- J Beautiful Numbers
- K Matrix Multiplication(签到)
- L Calculation
There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can’t move on red tiles, he can move only on black tiles.
Write a program to count the number of black tiles which he can reach by repeating the moves described above.
The input consists of multiple data sets. A data set starts with a line containing two positive integers W and H; W and H are the numbers of tiles in the x- and y- directions, respectively. W and H are not more than 20.
There are H more lines in the data set, each of which includes W characters. Each character represents the color of a tile as follows.
‘.’ - a black tile
‘#’ - a red tile
‘@’ - a man on a black tile(appears exactly once in a data set)
The end of the input is indicated by a line consisting of two zeros.
For each data set, your program should output a line which contains the number of tiles he can reach from the initial tile (including itself).
1 | 6 9 |
1 | 45 |
给定一个W*H的矩形,里面的值为“.” “#”,其中“.”代表可到达的,“#”表示障碍,某人在一个“@”的起始点,求他所能到达的格子有多少个(包括第一所占的格子)。
深搜广搜都行,直接暴力就好。
1 |
|
传送门:Silver Cow Party
One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way roads connects pairs of farms; road i requires Ti (1 ≤ Ti ≤ 100) units of time to traverse.
Each cow must walk to the party and, when the party is over, return to her farm. Each cow is lazy and thus picks an optimal route with the shortest time. A cow’s return route might be different from her original route to the party since roads are one-way.
Of all the cows, what is the longest amount of time a cow must spend walking to the party and back?
Line 1: Three space-separated integers, respectively: N, M, and X
Lines 2..M+1: Line i+1 describes road i with three space-separated integers: Ai, Bi, and Ti. The described road runs from farm Ai to farm Bi, requiring Ti time units to traverse.
Line 1: One integer: the maximum of time any one cow must walk.
1 | Line 1: One integer: the maximum of time any one cow must walk. |
1 | 4 8 2 |
Cow 4 proceeds directly to the party (3 units) and returns via farms 1 and 3 (7 units), for a total of 10 time units.
有向图,首行给出N,M,X代表有N个点,M条边,接着M行每行u,v,w代表u到v权值为w,求出各点到X加上X到各点最小权值中的最大值。
建边的同时,反向建边,各跑一遍Dijkstra。最后遍历所有点维护最大值MAX。
1 |
|
While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time that is BEFORE you entered the wormhole! Each of FJ’s farms comprises N (1 ≤ N ≤ 500) fields conveniently numbered 1..N, M (1 ≤ M ≤ 2500) paths, and W (1 ≤ W ≤ 200) wormholes.
As FJ is an avid time-traveling fan, he wants to do the following: start at some field, travel through some paths and wormholes, and return to the starting field a time before his initial departure. Perhaps he will be able to meet himself :) .
To help FJ find out whether this is possible or not, he will supply you with complete maps to F (1 ≤ F ≤ 5) of his farms. No paths will take longer than 10,000 seconds to travel and no wormhole can bring FJ back in time by more than 10,000 seconds.
Line 1: A single integer, F. F farm descriptions follow.
Line 1 of each farm: Three space-separated integers respectively: N, M, and W
Lines 2..M+1 of each farm: Three space-separated numbers (S, E, T) that describe, respectively: a bidirectional path between S and E that requires T seconds to traverse. Two fields might be connected by more than one path.
Lines M+2..M+W+1 of each farm: Three space-separated numbers (S, E, T) that describe, respectively: A one way path from S to E that also moves the traveler back T seconds.
Lines 1..F: For each farm, output “YES” if FJ can achieve his goal, otherwise output “NO” (do not include the quotes).
1 | 2 |
1 | NO |
给定F(1<=F<=5)组数据,对应与一个farm,每组数据对应一个结果。
对于其中一组数据,给定 N , M , W ,N为点数,M为无向边数(普通路径,通过之后时间前进),W为有向边数(虫洞,通过虫洞之后时间倒退),求每组数据是否存在一条回路能使时间倒退。
若存在这样一条回路,则图中肯定存在负环。只要判断是否有负环就行了。
1 |
|
传送门:POJ-2253 Frogger
Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dirty and full of tourists’ sunscreen, he wants to avoid swimming and instead reach her by jumping.
Unfortunately Fiona’s stone is out of his jump range. Therefore Freddy considers to use other stones as intermediate stops and reach her by a sequence of several small jumps.
To execute a given sequence of jumps, a frog’s jump range obviously must be at least as long as the longest jump occuring in the sequence.
The frog distance (humans also call it minimax distance) between two stones therefore is defined as the minimum necessary jump range over all possible paths between the two stones.You are given the coordinates of Freddy’s stone, Fiona’s stone and all other stones in the lake. Your job is to compute the frog distance between Freddy’s and Fiona’s stone.
The input will contain one or more test cases. The first line of each test case will contain the number of stones n (2<=n<=200). The next n lines each contain two integers xi,yi (0 <= xi,yi <= 1000) representing the coordinates of stone #i. Stone #1 is Freddy’s stone, stone #2 is Fiona’s stone, the other n-2 stones are unoccupied. There’s a blank line following each test case. Input is terminated by a value of zero (0) for n.
For each test case, print a line saying “Scenario #x” and a line saying “Frog Distance = y” where x is replaced by the test case number (they are numbered from 1) and y is replaced by the appropriate real number, printed to three decimals. Put a blank line after each test case, even after the last one.
1 | 2 |
1 | Scenario #1 |
青蛙想从一个石子跳到另一个石子,中间有很多石子,要求青蛙跳跃距离应为路径中最大的距离,现在要求所有路径中最小的跳跃距离,就是求所有路径中最大距离的最小值。
和POJ-1979 Heavy Transportation这一题很像,建图后都是最大生成树。
1 |
|
传送门:text
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 her beauty sleep, so she wants to get back as quickly as possible.
Farmer John’s field has N (2 <= N <= 1000) landmarks in it, uniquely numbered 1..N. Landmark 1 is the barn; the apple tree grove in which Bessie stands all day is landmark N. Cows travel in the field using T (1 <= T <= 2000) bidirectional cow-trails of various lengths between the landmarks. Bessie is not confident of her navigation ability, so she always stays on a trail from its start to its end once she starts it.
Given the trails between the landmarks, determine the minimum distance Bessie must walk to get back to the barn. It is guaranteed that some such route exists.
Line 1: Two integers: T and N
Lines 2..T+1: Each line describes a trail as three space-separated integers. The first two integers are the landmarks between which the trail travels. The third integer is the length of the trail, range 1..100.
- Line 1: A single integer, the minimum distance that Bessie must travel to get from landmark N to landmark 1.
1 | 5 5 |
1 | 90 |
INPUT DETAILS:
There are five landmarks.
OUTPUT DETAILS:
Bessie can get home by following trails 4, 3, 2, and 1.
有N个点,给出从a点到b点的距离,当然a和b是互相可以抵达的,问从1到n的最短距离
模板题
1 |
|
传送门:POJ-1125 Stockbroker Grapevine
Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spreading disinformation amongst the stockbrokers to give your employer the tactical edge in the stock market. For maximum effect, you have to spread the rumours in the fastest possible way.
Unfortunately for you, stockbrokers only trust information coming from their “Trusted sources” This means you have to take into account the structure of their contacts when starting a rumour. It takes a certain amount of time for a specific stockbroker to pass the rumour on to each of his colleagues. Your task will be to write a program that tells you which stockbroker to choose as your starting point for the rumour, as well as the time it will take for the rumour to spread throughout the stockbroker community. This duration is measured as the time needed for the last person to receive the information.
Your program will input data for different sets of stockbrokers. Each set starts with a line with the number of stockbrokers. Following this is a line for each stockbroker which contains the number of people who they have contact with, who these people are, and the time taken for them to pass the message to each person. The format of each stockbroker line is as follows: The line starts with the number of contacts (n), followed by n pairs of integers, one pair for each contact. Each pair lists first a number referring to the contact (e.g. a ‘1’ means person number one in the set), followed by the time in minutes taken to pass a message to that person. There are no special punctuation symbols or spacing rules.
Each person is numbered 1 through to the number of stockbrokers. The time taken to pass the message on will be between 1 and 10 minutes (inclusive), and the number of contacts will range between 0 and one less than the number of stockbrokers. The number of stockbrokers will range from 1 to 100. The input is terminated by a set of stockbrokers containing 0 (zero) people.
For each set of data, your program must output a single line containing the person who results in the fastest message transmission, and how long before the last person will receive any given message after you give it to this person, measured in integer minutes.
It is possible that your program will receive a network of connections that excludes some persons, i.e. some people may be unreachable. If your program detects such a broken network, simply output the message “disjoint”. Note that the time taken to pass the message from person A to person B is not necessarily the same as the time taken to pass it from B to A, if such transmission is possible at all.
1 | 3 |
1 | 3 2 |
此题题意远比题目难~
股票经纪人要在一群人中散布一个谣言,而谣言只能在亲密的人中传递,题目各处了人与人之间的关系及传递谣言所用的时间,要求程序给出应以那个人为起点,可以在最短的时间内让所有的人都得知这个谣言。要注意从a到b传递的时间不一定等于从b到a的时间,如果没有方案能够让每一个人都知道谣言,则输出”disjoint”。
题目数据的输入第一行为n,代表总人数,当n=0时结束程序,接着n行,第i+1行的第一个是一个整数t,表示第i个人与t个人的关系要好,接着有t对整数,每对的第一个数是j,表示i与j要好,第二个数是从i直接传递谣言到j所用的时间,数据的输出是两个整数,第一个为选点的散布谣言的起点,第二个整数时所有人得知谣言的最短时间
例如,对于数据1,
可知如果从3开始传播,则1,2得知谣言的时间都是2,所用的时间比从1,2开始传播所用的时间要短,故程序的输出时3 2;
题意理解后思路就比较清晰了,先Floyd更新所有点的最短路,再遍历更新最大值MAX。
1 |
|
In the age of television, not many people attend theater performances. Antique Comedians of Malidinesia are aware of this fact. They want to propagate theater and, most of all, Antique Comedies. They have printed invitation cards with all the necessary information and with the programme. A lot of students were hired to distribute these invitations among the people. Each student volunteer has assigned exactly one bus stop and he or she stays there the whole day and gives invitation to people travelling by bus. A special course was taken where students learned how to influence people and what is the difference between influencing and robbery.
The transport system is very special: all lines are unidirectional and connect exactly two stops. Buses leave the originating stop with passangers each half an hour. After reaching the destination stop they return empty to the originating stop, where they wait until the next full half an hour, e.g. X:00 or X:30, where ‘X’ denotes the hour. The fee for transport between two stops is given by special tables and is payable on the spot. The lines are planned in such a way, that each round trip (i.e. a journey starting and finishing at the same stop) passes through a Central Checkpoint Stop (CCS) where each passenger has to pass a thorough check including body scan.
All the ACM student members leave the CCS each morning. Each volunteer is to move to one predetermined stop to invite passengers. There are as many volunteers as stops. At the end of the day, all students travel back to CCS. You are to write a computer program that helps ACM to minimize the amount of money to pay every day for the transport of their employees.
The input consists of N cases. The first line of the input contains only positive integer N. Then follow the cases. Each case begins with a line containing exactly two integers P and Q, 1 <= P,Q <= 1000000. P is the number of stops including CCS and Q the number of bus lines. Then there are Q lines, each describing one bus line. Each of the lines contains exactly three numbers - the originating stop, the destination stop and the price. The CCS is designated by number 1. Prices are positive integers the sum of which is smaller than 1000000000. You can also assume it is always possible to get from any stop to any other stop.
For each case, print one line containing the minimum amount of money to be paid each day by ACM for the travel costs of its volunteers.
1 | 2 |
1 | 46 |
给定一个有向图,求一个点到所有点的最短距离之和加上所有点到这个点距离之和。
图中的节点个数范围:0~1e6;
建图时反向建边,先做一次Dijkstra,然后将所有的边反序做一次Dijkstra即可,Dijkstra必须是heap优化的。
SPFA同理,先做一次spfa,然后将所有的边反序做一次spfa即可。
1 |
|
传送门:POJ-1979 Heavy Transportation
Background
Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place where it is needed on which all streets can carry the weight.
Fortunately he already has a plan of the city with all streets and bridges and all the allowed weights.Unfortunately he has no idea how to find the the maximum weight capacity in order to tell his customer how heavy the crane may become. But you surely know.Problem
You are given the plan of the city, described by the streets (with weight limits) between the crossings, which are numbered from 1 to n. Your task is to find the maximum weight that can be transported from crossing 1 (Hugo’s place) to crossing n (the customer’s place). You may assume that there is at least one path. All streets can be travelled in both directions.
The first line contains the number of scenarios (city plans). For each city the number n of street crossings (1 <= n <= 1000) and number m of streets are given on the first line. The following m lines contain triples of integers specifying start and end crossing of the street and the maximum allowed weight, which is positive and not larger than 1000000. There will be at most one street between each pair of crossings.
The output for every scenario begins with a line containing “Scenario #i:”, where i is the number of the scenario starting at 1. Then print a single line containing the maximum allowed weight that Hugo can transport to the customer. Terminate the output for the scenario with a blank line.
1 | 1 |
1 | Scenario #1: |
从城市1到城市N运送货物,有M条道路,每条道路都是双向的,每条道路都有它的最大载重量,问从城市1到城市N运送最多的重量是多少。
这一题方法不唯一,生成树变形和最短路变形都能过这题,我当时使用kruscal水过了,有机会把几种写法都补齐。
1 |
|
作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿。终于有一天,小Z再也无法忍受这恼人的找袜子过程,于是他决定听天由命……
具体来说,小Z把这N只袜子从1到N编号,然后从编号L到R(L 尽管小Z并不在意两只袜子是不是完整的一双,甚至不在意两只袜子是否一左一右,他却很在意袜子的颜色,毕竟穿两只不同色的袜子会很尴尬。
你的任务便是告诉小Z,他有多大的概率抽到两只颜色相同的袜子。当然,小Z希望这个概率尽量高,所以他可能会询问多个(L,R)以方便自己选择。
作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿。终于有一天,小Z再也无法忍受这恼人的找袜子过程,于是他决定听天由命……
具体来说,小Z把这N只袜子从1到N编号,然后从编号L到R(L 尽管小Z并不在意两只袜子是不是完整的一双,甚至不在意两只袜子是否一左一右,他却很在意袜子的颜色,毕竟穿两只不同色的袜子会很尴尬。
你的任务便是告诉小Z,他有多大的概率抽到两只颜色相同的袜子。当然,小Z希望这个概率尽量高,所以他可能会询问多个(L,R)以方便自己选择。
包含M行,对于每个询问在一行中输出分数A/B表示从该询问的区间[L,R]中随机抽出两只袜子颜色相同的概率。若该概率为0则输出0/1,否则输出的A/B必须为最简分数。(详见样例)
1 | 6 4 |
1 | 2/5 |
询问1:共C(5,2)=10种可能,其中抽出两个2有1种可能,抽出两个3有3种可能,概率为(1+3)/10=4/10=2/5。
询问2:共C(3,2)=3种可能,无法抽到颜色相同的袜子,概率为0/3=0/1。
询问3:共C(3,2)=3种可能,均为抽出两个3,概率为3/3=1/1。
注:上述C(a, b)表示组合数,组合数C(a, b)等价于在a个不同的物品中选取b个的选取方案数。
中文题面
莫涛大佬的论文题
假设区间为[L,R],分母为(R-L+1)(R-L)。分子为\sum{cnt[x](cnt[x]-1)},cnt[x]表示当前区间内颜色为x的袜子的数量。
区间每增加1,假设增加了一个颜色为x的袜子,在原区间中x颜色的袜子对答案的贡献为cnt[x](cnt[x]-1),现在贡献为cnt[x]++后的cnt[x]*(cnt[x]-1),直接计算两个之间的差值不方便,我们可以减去原区间中x颜色的袜子对答案的贡献,然后cnt[x]++或–,再加上x颜色的袜子对答案的贡献。(来自ZSC)
下面这个博客有对莫队更深的讲解
【莫队算法】-大米饼
1 |
|
1 |
|
John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task is
only possible if other tasks have already been executed.
The input will consist of several instances of the problem. Each instance begins with a line containing
two integers, 1 ≤ n ≤ 100 and m. n is the number of tasks (numbered from 1 to n) and m is the
number of direct precedence relations between tasks. After this, there will be m lines with two integers
i and j, representing the fact that task i must be executed before task j.
An instance with n = m = 0 will finish the input.
For each instance, print a line with n integers representing the tasks in a possible order of execution.
1 | 5 4 |
1 | 1 4 2 5 3 |
给出n组数据,前面的的序号表示这个任务先于后面序号的任务,要求将任务先后排序(不一定有一种)
拓扑序模板题,将入度为零的点进队,每次出队更新入度,继续将入度为零的点进队,最后输出。
1 |
|
传送门:HDU-1285 确定比赛名次
有N个比赛队(1<=N<=500),编号依次为1,2,3,。。。。,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委员会不能直接获得每个队的比赛成绩,只知道每场比赛的结果,即P1赢P2,用P1,P2表示,排名时P1在P2之前。现在请你编程序确定排名。
输入有若干组,每组中的第一行为二个数N(1<=N<=500),M;其中N表示队伍的个数,M表示接着有M行的输入数据。接下来的M行数据中,每行也有两个整数P1,P2表示即P1队赢了P2队。
给出一个符合要求的排名。输出时队伍号之间有空格,最后一名后面没有空格。
其他说明:符合条件的排名可能不是唯一的,此时要求输出时编号小的队伍在前;输入数据保证是正确的,即输入数据确保一定能有一个符合要求的排名。
1 | 4 3 |
1 | 1 2 4 3 |
中文题面
比较裸的拓扑排序题。我是用邻接表写的,邻接矩阵的话注意重边即可了。还有本题符合条件的排名可能不是唯一的,此时坑点要求输出时编号小的队伍在前。其次就是输出格式的限定。
1 |
|
不好意思,平时都是写C++,所以格式上可能和大家学的C有点出入。
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
]]>大家真的是非常优秀,我去年是在军训时才打下自己的第一句Hello World,暑假啥也没学,啥也没看,所以很佩服大家。
学习这事不要急,慢慢来,当时一个排序、一个打印菱形就能磕我一下午。
但无论如何你最后选择了什么方向,大学都一定不要荒废。
anyway,祝大家有一个充实的大学生活~
–没错,我就是群里那个叫“何世全”的(感谢队友不杀之恩情)。
小Hi和小Ho所在学校的校园网被黑客入侵并投放了病毒。这事在校内BBS上立刻引起了大家的讨论,当然小Hi和小Ho也参与到了其中。从大家各自了解的情况中,小Hi和小Ho整理得到了以下的信息:
校园网主干是由N个节点(编号1..N)组成,这些节点之间有一些单向的网路连接。若存在一条网路连接(u,v)链接了节点u和节点v,则节点u可以向节点v发送信息,但是节点v不能通过该链接向节点u发送信息。
在刚感染病毒时,校园网立刻切断了一些网络链接,恰好使得剩下网络连接不存在环,避免了节点被反复感染。也就是说从节点i扩散出的病毒,一定不会再回到节点i。
当1个病毒感染了节点后,它并不会检查这个节点是否被感染,而是直接将自身的拷贝向所有邻居节点发送,它自身则会留在当前节点。所以一个节点有可能存在多个病毒。
现在已经知道黑客在一开始在K个节点上分别投放了一个病毒。
举个例子,假设切断部分网络连接后学校网络如下图所示,由4个节点和4条链接构成。最开始只有节点1上有病毒。最开始节点1向节点2和节点3传送了病毒,自身留有1个病毒:
其中一个病毒到达节点2后,向节点3传送了一个病毒。另一个到达节点3的病毒向节点4发送自己的拷贝:
当从节点2传送到节点3的病毒到达之后,该病毒又发送了一份自己的拷贝向节点4。此时节点3上留有2个病毒:
最后每个节点上的病毒为:
小Hi和小Ho根据目前的情况发现一段时间之后,所有的节点病毒数量一定不会再发生变化。那么对于整个网络来说,最后会有多少个病毒呢?
第1行:3个整数N,M,K,1≤K≤N≤100,000,1≤M≤500,000
第2行:K个整数A[i],A[i]表示黑客在节点A[i]上放了1个病毒。1≤A[i]≤N
第3..M+2行:每行2个整数 u,v,表示存在一条从节点u到节点v的网络链接。数据保证为无环图。1≤u,v≤N
第1行:1个整数,表示最后整个网络的病毒数量 MOD 142857
1 | 4 4 1 |
1 | 6 |
中文题面
从入度为0的节点开始,对于这些节点,它并不会再增加病毒数量。那么我们就根据它所关联的连接将病毒分发出去,然后这个节点就没有作用了。那不妨就删掉好了,它所关联的边也删掉,这样图中又会产生一些新的没有入度的节点。这样一直删点,直到所有的点都被删掉,将所有点的病毒数量加起来就是总的病毒数。
1 |
|
我们都知道大学的课程是可以自己选择的,每一个学期可以自由选择打算学习的课程。唯一限制我们选课是一些课程之间的顺序关系:有的难度很大的课程可能会有一些前置课程的要求。比如课程A是课程B的前置课程,则要求先学习完A课程,才可以选择B课程。大学的教务收集了所有课程的顺序关系,但由于系统故障,可能有一些信息出现了错误。现在小Ho把信息都告诉你,请你帮小Ho判断一下这些信息是否有误。错误的信息主要是指出现了”课程A是课程B的前置课程,同时课程B也是课程A的前置课程”这样的情况。当然”课程A是课程B的前置课程,课程B是课程C的前置课程,课程C是课程A的前置课程”这类也是错误的。
第1行:1个整数T,表示数据的组数T(1 <= T <= 5)
接下来T组数据按照以下格式:
第1行:2个整数,N,M。N表示课程总数量,课程编号为1..N。M表示顺序关系的数量。1 <= N <= 100,000. 1 <= M <= 500,000
第2..M+1行:每行2个整数,A,B。表示课程A是课程B的前置课程。
第1..T行:每行1个字符串,若该组信息无误,输出”Correct”,若该组信息有误,输出”Wrong”。
1 | 2 |
1 | Wrong |
中文题面
先扫描所有点和边维护每一个点的入度值,复杂度O(N+M)。 把入度为0的点加入队列Q中,当然有可能存在多个入度为0的点,同时它们之间也不会存在连接关系,所以按照任意顺序加入Q都是可以的。从Q中取出一个点p。对于每一个未删除且与p相连的点q,入度值-1;如果入读值为0,把q加入Q。不断重复第3步,直到Q为空。
最后剩下的未被删除的点,也就是组成环的点了。
1 |
|
Farmer John is an astounding accounting wizard and has realized he might run out of money to run the farm. He has already calculated and recorded the exact amount of money (1 ≤ moneyi ≤ 10,000) that he will need to spend each day over the next N (1 ≤ N ≤ 100,000) days.
FJ wants to create a budget for a sequential set of exactly M (1 ≤ M ≤ N) fiscal periods called “fajomonths”. Each of these fajomonths contains a set of 1 or more consecutive days. Every day is contained in exactly one fajomonth.
FJ’s goal is to arrange the fajomonths so as to minimize the expenses of the fajomonth with the highest spending and thus determine his monthly spending limit.
Line 1: Two space-separated integers: N and M
Lines 2.. N+1: Line i+1 contains the number of dollars Farmer John spends on the ith day
Line 1: The smallest possible monthly limit Farmer John can afford to live with.
1 | 7 5 |
1 | 500 |
If Farmer John schedules the months so that the first two days are a month, the third and fourth are a month, and the last three are their own months, he spends at most $500 in any month. Any other method of scheduling gives a larger minimum monthly limit.
分期:将N个账款分割成M个财务期,使得每个分期账款和的最大值最小。
给出农夫在n天中每天的花费,要求把这n天分作m组,每组的天数必然是连续的,要求分得各组的花费之和应该尽可能地小,最后输出各组花费之和中的最大值。
最大值最小的问题,可以采用二分来解决,二分其中一个值,算另一个结果,找到上届或下届。
在这个题中 二分组的最大花费,计算是不是可以分为m组,找出最小的花费。
1 |
|
Today is Ignatius’ birthday. He invites a lot of friends. Now it’s dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not all the friends know each other, and all the friends do not want to stay with strangers.
One important rule for this problem is that if I tell you A knows B, and B knows C, that means A, B, C know each other, so they can stay in one table.
For example: If I tell you A knows B, B knows C, and D knows E, so A, B, C can stay in one table, and D, E have to stay in the other one. So Ignatius needs 2 tables at least.
The input starts with an integer T(1<=T<=25) which indicate the number of test cases. Then T test cases follow. Each test case starts with two integers N and M(1<=N,M<=1000). N indicates the number of friends, the friends are marked from 1 to N. Then M lines follow. Each line consists of two integers A and B(A!=B), that means friend A and friend B know each other. There will be a blank line between two cases.
For each test case, just output how many tables Ignatius needs at least. Do NOT print any blanks.
1 | 2 |
1 | 2 |
要宴请一些客人,但是客人彼此之间并不是完全互相认识的,规定如果A认识B,且B认识C,则认为A,B,C互相认识,可以安排在同一桌,求需要安排的桌数。
并查集模板题,水题。
1 |
|
传送门:HDU-1875 畅通工程再续
相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实现。现在政府决定大力发展百岛湖,发展首先要解决的问题当然是交通问题,政府决定实现百岛湖的全畅通!经过考察小组RPRush对百岛湖的情况充分了解后,决定在符合条件的小岛间建上桥,所谓符合条件,就是2个小岛之间的距离不能小于10米,也不能大于1000米。当然,为了节省资金,只要求实现任意2个小岛之间有路通即可。其中桥的价格为 100元/米。
输入包括多组数据。输入首先包括一个整数T(T <= 200),代表有T组数据。
每组数据首先是一个整数C(C <= 100),代表小岛的个数,接下来是C组坐标,代表每个小岛的坐标,这些坐标都是 0 <= x, y <= 1000的整数。
每组输入数据输出一行,代表建桥的最小花费,结果保留一位小数。如果无法实现工程以达到全部畅通,输出”oh!”.
1 | 2 |
1 | 1414.2 |
中文题面
先建图,之后就是最小生成树的模板题。
1 |
|
传送门:HDU-1874 畅通工程续
某省自从实行了很多年的畅通工程计划后,终于修建了很多路。不过路多了也不好,每次要从一个城镇到另一个城镇时,都有许多种道路方案可以选择,而某些方案要比另一些方案行走的距离要短很多。这让行人很困扰。
现在,已知起点和终点,请你计算出要从起点到终点,最短需要行走多少距离。
本题目包含多组数据,请处理到文件结束。
每组数据第一行包含两个正整数N和M(0<N<200,0<M<1000),分别代表现有城镇的数目和已修建的道路的数目。城镇分别以0~N-1编号。
接下来是M行道路信息。每一行有三个整数A,B,X(0<=A,B<N,A!=B,0<X<10000),表示城镇A和城镇B之间有一条长度为X的双向道路。
再接下一行有两个整数S,T(0<=S,T<N),分别代表起点和终点。
对于每组数据,请在一行里输出最短需要行走的距离。如果不存在从S到T的路线,就输出-1.
1 | 3 3 |
1 | 2 |
中文题面
最短路模板题,几种最短路的算法都能直接过。
1 |
|
1 |
|
1 |
|
传送门:HDU-1232 畅通工程
某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇。省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只要互相间接通过道路可达即可)。问最少还需要建设多少条道路?
测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数,分别是城镇数目N ( < 1000 )和道路数目M;随后的M行对应M条道路,每行给出一对正整数,分别是该条道路直接连通的两个城镇的编号。为简单起见,城镇从1到N编号。
注意:两个城市之间可以有多条道路相通,也就是说
3 3
1 2
1 2
2 1
这种输入也是合法的
当N为0时,输入结束,该用例不被处理。
对每个测试用例,在1行里输出最少还需要建设的道路数目。
1 | 4 2 |
1 | 1 |
Huge input, scanf is recommended.
中文题面
最小生成树的边为n-1。初始化时每个城镇都没有路,所以要连接的路的数量为n-1个,一次判断两个城镇是否在一个集合内,若不在同一集合内则建边,并入同一集合中。
1 |
|
Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The stalls are located along a straight line at positions x1,…,xN (0 <= xi <= 1,000,000,000).
His C (2 <= C <= N) cows don’t like this barn layout and become aggressive towards each other once put into a stall. To prevent the cows from hurting each other, FJ want to assign the cows to the stalls, such that the minimum distance between any two of them is as large as possible. What is the largest minimum distance?
Line 1: Two space-separated integers: N and C
Lines 2..N+1: Line i+1 contains an integer stall location, xi
- Line 1: One integer: the largest minimum distance
1 | 5 3 |
1 | 3 |
OUTPUT DETAILS:
FJ can put his 3 cows in the stalls at positions 1, 4 and 8, resulting in a minimum distance of 3.
Huge input data,scanf is recommended.
有n个牛栏,选m个放进牛,相当于一条线段上有 n 个点,选取 m 个点,使得相邻点之间的最小距离值最大。
先排序,再二分枚举相邻两牛的间距,判断大于等于此间距下能否放进所有的牛。
1 |
|
传送门:POJ-1321 棋盘问题
在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。
输入含有多组测试数据。
每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目。 n <= 8 , k <= n
当为-1 -1时表示输入结束。
随后的n行描述了棋盘的形状:每行有n个字符,其中 # 表示棋盘区域, . 表示空白区域(数据保证不出现多余的空白行或者空白列)。
对于每一组数据,给出一行输出,输出摆放的方案数目C (数据保证C<2^31)。
1 | 2 1 |
1 | 2 |
中文题面
DFS累计可行的方案数,因为题目要求不可以将棋子摆放在同一行和同一列,所以走过一列就把它标记下来下次的时候就不可以再摆放在这一列。然后就从下一行开始寻找可行的地方,直到摆放的棋子数与被要求摆放的棋子数相同时,就将方案数进行一次++,然后再进行递归下去。
1 |
|
传送门:FZU-2150 Fire Game text url
Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this board is consisting of grass or just empty and then they start to fire all the grass. Firstly they choose two grids which are consisting of grass and set fire. As we all know, the fire can spread among the grass. If the grid (x, y) is firing at time t, the grid which is adjacent to this grid will fire at time t+1 which refers to the grid (x+1, y), (x-1, y), (x, y+1), (x, y-1). This process ends when no new grid get fire. If then all the grid which are consisting of grass is get fired, Fat brother and Maze will stand in the middle of the grid and playing a MORE special (hentai) game. (Maybe it’s the OOXX game which decrypted in the last problem, who knows.)
You can assume that the grass in the board would never burn out and the empty grid would never get fire.
Note that the two grids they choose can be the same.
The first line of the date is an integer T, which is the number of the text cases.
Then T cases follow, each case contains two integers N and M indicate the size of the board. Then goes N line, each line with M character shows the board. “#” Indicates the grass. You can assume that there is at least one grid which is consisting of grass in the board.
1 <= T <=100, 1 <= n <=10, 1 <= m <=10
For each case, output the case number first, if they can play the MORE special (hentai) game (fire all the grass), output the minimal time they need to wait after they set fire, otherwise just output -1. See the sample input and output for more details.
1 | 4 |
1 | Case 1: 1 |
俩小孩放火,只有‘#’格子可燃,两人同时各点燃一个‘#’(可以是同一个),火可以向上向下向左向右在有草的格子蔓延,点火的地方时间为0,蔓延至下一格的时间依次加一,问最快多久能烧完‘#’,如不能烧完则输出“-1”。
依次枚举两个‘#’,然后双路BFS,同时维护最小时间min
1 |
|
The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It then analyzes each plot separately, using sensing equipment to determine whether or not the plot contains oil. A plot containing oil is called a pocket. If two pockets are adjacent, then they are part of the same oil deposit. Oil deposits can be quite large and may contain numerous pockets. Your job is to determine how many different oil deposits are contained in a grid.
The input file contains one or more grids. Each grid begins with a line containing m and n, the number of rows and columns in the grid, separated by a single space. If m = 0 it signals the end of the input; otherwise 1 <= m <= 100 and 1 <= n <= 100. Following this are m lines of n characters each (not counting the end-of-line characters). Each character corresponds to one plot, and is either ‘*’, representing the absence of oil, or `@’, representing an oil pocket.
For each grid, output the number of distinct oil deposits. Two different pockets are part of the same oil deposit if they are adjacent horizontally, vertically, or diagonally. An oil deposit will not contain more than 100 pockets.
1 | 1 1 |
1 | 0 |
判断有多少个‘@’的联通块,八个方向有接触就算在同一联通块内。
搜索入门题,直接暴力枚举每个点,DFS、BFS都可以,把搜索到的点标记下,维护下num标记即可。
1 |
|
1 |
|
Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Ningbo one year, yifenfei have many people to meet. Especially a good friend Merceki.
Yifenfei’s home is at the countryside, but Merceki’s home is in the center of city. So yifenfei made arrangements with Merceki to meet at a KFC. There are many KFC in Ningbo, they want to choose one that let the total time to it be most smallest.
Now give you a Ningbo map, Both yifenfei and Merceki can move up, down ,left, right to the adjacent road by cost 11 minutes.
The input contains multiple test cases.
Each test case include, first two integers n, m. (2<=n,m<=200).
Next n lines, each line included m character.
‘Y’ express yifenfei initial position.
‘M’ express Merceki initial position.
‘#’ forbid road;
‘.’ Road.
‘@’ KCF
For each test case output the minimum total time that both yifenfei and Merceki to arrival one of KFC.You may sure there is always have a KFC that can let them meet.
1 | 4 4 |
1 | 66 |
Y和M要去肯德基聚餐,图中有多个kfc,他们要选的那个kfc必须到彼此的所用时间之和最小,问最少需要多少时间。这里一格代表了11分钟。
以Y和M为起点各跑一次BFS,每个‘@’累加两次的最短路,最后遍历整张地图更新min。
1 |
|
Start coding now.
第一次搭建博客,好多地方都还不完善,欢迎大佬指点。
留言系统来必应实在太丑了,虽然Gitment只能用GitHub登录,但考虑到博客的访问人群,先忍忍,等过几天就换过去。