【试题三】 网络的可靠性
A公司是全球领先的互联网解决方案提供商,也是 2010 年世博会的高级赞助商。它将提供先进的网络协作技术,展示其 智能+互联 的生活概念,同时为参观者提供高品质的个人体验和互动,以“信息通信,尽情城市梦想”为主题贯穿。借助奇幻的剧场大屏幕和特效,展现信息通信技术的应用前景,通过生动形象的故事,向观众展示沟通无限制的未来社会前景。
为此,A公司为世博园的N个区域建立了视频通信系统,其中每个区域建立一个基站,编号依次为1,2,??,N。通过基站之间的通信线路为各区域的参观者提供视频服务。
已知在各基站之间已铺设了一些光纤通讯线路,这些线路覆盖了所有区域,即任意两个区域都可以进行视频传递。但为了节约成本开支,目前只铺设了N-1条线路,同时为了减轻各基站的信息传递负载,每个基站最多有三条光纤通讯线路与之连接。
但在通信系统试运行期间, A公司发现当某个基站发生故障时,会导致其它区域之间无法进行信息传递。为了提高该通信网络的可靠性,A公司准备在基站之间再新铺设一些光纤线路,使得任意一个基站故障后,其它基站之间仍然可以通讯。
由于铺设线路的成本昂贵,A公司希望新增设的光纤线路越少越好。A公司请求Dr. Kong来完成这个任务。 【标准输入】
第一行: N 表示有N个基站
接下来有N-1行: X Y 表示第X个基站与第Y个基站直连 【标准输出】
输出一个整数, 表示至少需新铺设的光纤线路数。 【约束条件】
1≤ N ≤ 10000 (线路是双向通信的) 【 样 例 】 标准输入 8 1 3 3 2 5 3 5 4 5 6 2 7 2 8
3 标准输出 【试题四】
虚拟城市之旅
展馆是未来城市的缩影,个人体验和互动是不变的主题。在A国展馆通过多维模式和高科技手段,引领参观者在展示空间踏上一段虚拟的城市之旅。
梦幻国有N个城市和M条道路,每条道路连接某两个城市。任意两个城市之间最多只有一条道路直接相连。这M条道路中有一部分为单向通行的道路,一部分为双向通行的道路。
梦幻国幅员辽阔,各地的资源分布情况各不相同,这就导致了同一种商品在不同城市的价格不一定相同。但是,同一种商品在同一个城市的买入价和卖出价始终是相同的。
现在你已踏上一段虚拟的城市之旅。为了给你一个意外收获,允许你在旅游的同时,利用 X 商品在不同城市中的差价赚回一点旅费,但最多只能交易一次。即,在某个城市买入X 商品,可以走到另外一个城市买掉来获得旅费。当然,在赚不到差价的情况下,你也可以不进行贸易活动。
设梦幻国N个城市的标号从1~ N,你只能从1 号城市出发,并最终在N 号城市结束自己的旅行。在旅游的过程中,任何城市可以重复经过多次,但不要求经过所有N个城市。
例如:梦幻国有5个大城市,城市的编号和道路连接情况如下图,单向箭头表示这条道路为单向通行,双向箭头表示这条道路为双向通行。假设 X 商品在1~5 号城市的价格分别为 4,3,5,6,1。
你可以选择如下一条线路:1?2?3?5,并在2 号城市以3 的价格买入X 商品,在3号城市以5 的价格卖出X 商品,赚取的旅费数为2。
你也可以选择如下一条线路1?4?5?4?5,并在第1次到达5号城市时以1的价格买入X 商品,在第2次到达4号城市时以6 的价格卖出X 商品,赚取的旅费数为5。
现在给出N个城市的X 商品价格,M条道路的信息(每条道路所连接的两个城市的编号以及该条道路的通行情况)。请问你能赚取尽可能多的旅费吗。 【标准输入】
第一行:N M 分别表示城市的数目和道路的数目。
第二行:N个正整数,每两个整数之间用一个空格隔开,分别表示1到N个城市的商品价格。 接下来 M行,每行有3个正整数,X,Y,Z,每两个整数之间用一个空格隔开。
如果 Z=1,表示这条道路是城市X到城市Y之间的单向道路; 如果Z=2,表示这条道路为城市X 和城市Y之间的双向道路。
【标准输出】
输出1个整数,表示最多能赚取的旅费。如果没有进行贸易,则输出0。
【约束条件】
1≤N≤100000,1≤M≤500000,
1≤X,Y≤N,1≤Z≤2,1≤商品价格≤100。
【 样 例 】
标准输入 5 5 4 3 5 6 1 1 2 1 1 4 1 2 3 2 3 5 1 4 5 2 标准输出 5 【试题五】 聪明的“KK”
非洲某国展馆的设计灵感源于富有传奇色彩的沙漠中陡然起伏的沙丘,体现出本国不断变换和绚丽多彩的自然风光与城市风貌。展馆由五部分组成,馆内影院播放名为《一眨眼的瞬间》的宽银幕短片,反映了建国以来人民生活水平和城市居住环境的惊人巨变。
可移动“沙丘”变戏法 的灵感源于其独特而雄伟的自然景观——富于传奇色彩的险峻沙丘。宏伟的结构、可循环的建材,与大自然相得益彰。环绕一周,发现它正是从沙丘那不断变换的形态中汲取灵感的。外形逼真到无论从哪个角度去观察,都能清楚地辨识出沙丘的特征。
它“坡面”高达20米,微风吹来,你是否感觉到沙的流动?用手去触碰,却发现原来是“魔术戏法”。它表面的不锈钢面板呈现出一种富于变幻的色彩,从不同角度观察,呈现不同色泽,由此来模仿流动沙丘的光感。
走进第三展厅有一个超大的屏幕,通过奇妙的特效,让观众犹如亲身来到浩瀚的沙漠。更为奇妙的是,只见一个小动物“KK”正从沙漠区域(矩形)的左上角沿着向右或向下的方向往右下角跑去。KK太聪明了,它居然能在跑的过程中会选择吃掉尽可能多的虫子线路。
你知道它吃掉多少虫子吗? 【标准输入】
第一行:N M 表示沙漠是一个N*M的矩形区域
接下来有N行:每行有M个正整数,Xi1 Xi2 ……Xim 表示各位置中的虫子数(单个空格隔开)
【标准输出】
输出有一个整数, 表示“KK”吃掉最多的虫子数。
【约束条件】
1≤ N M ≤ 20 0≤Xij≤ 500 (i=1,2?.N, j=1,2?,M) 假设“KK”只能向右走或向下走。
【 样 例 】
标准输入 3 4 3 1 2 8 5 3 4 6 1 0 2 3 标准输出 24 【试题六】
AMAZING AUCTION
Recently the auction house has introduced a new type of auction, the lowest price auction. In this new system, people compete for the lowest bid price, as opposed to what they did in the past. What an amazing thing! Now you could buy cool stuff with one penny. Your task is to write the software to automate this auction system.
First the auctioneer puts an upper limit on bid price for each item. Only positive price less than or equal to this price limit is a valid bid. For example, if the price limit is 100, then 1 to 100, inclusive, are all valid bid prices. Bidder can not put more than one bid for the same price on a same item. However they can put many bids on a same item, as long as the prices are different.
After all bids are set, the auctioneer chooses the winner according to the following rules:
(1). If any valid price comes from only one bidder, the price is a \bids, then the unique bid with the lowest price wins. This price is the winning price and the only bidder is the winning bidder.
(2). If there are no unique bids, then the price with fewest bids is the winning bid. If there are more than one price which has the same lowest bid count, choose the lowest one. This price is the winning price. The bidder who puts this bid first is the winning bidder.
Given the price limit and all the bids that happen in order, you will determine the winning bidder and the winning price.
【Standard input】
The first line contains two integers: U (1 <= U <= 1000), the price upper limit and M (1 <= M <= 100), the total number of bids. M lines follow, each of which presents a single bid. The bid contains the
bidder's name (consecutive non-whitespace characters<=5) and the price P (1 <= P <= U), separated with a single space. All bids in the input are guaranteed to be valid ones.
【Standard output】
Print the sentence \
【Sample Input】
30 7 Mary 10 Mary 20 Mary 30 Bob 10 Bob 30 Carl 30 Alice 23
【Sample Output】
The winner is Mary The price is 20
【试题七】
BUYING FEED
Farmer John needs to travel to town to pick up K (1 <= K <= 100)pounds of feed. Driving D miles with K pounds of feed in his truck costs D*K cents.
The county feed lot has N (1 <= N <= 100) stores (conveniently numbered 1..N) that sell feed. Each store is located on a segment of the X axis whose length is E (1 <= E <= 350). Store i is at location X_i (0 < X_i < E) on the number line and can sell John as much as F_i (1 <= F_i <= 100) pounds of feed at a cost of C_i (1 <= C_i <= 1,000,000) cents per pound. Amazingly, a given point on the X axis might have more than one store.
Farmer John starts at location 0 on this number line and can drive only in the positive
direction, ultimately arriving at location E, with at least K pounds of feed. He can stop at any of the feed stores along the way and buy any amount of feed up to the the store's limit.
What is the minimum amount Farmer John has to pay to buy and transport the K pounds of feed? Farmer John knows there is a solution.
Consider a sample where Farmer John needs two pounds of feed from three stores (locations: 1, 3, and 4) on a number line whose range is 0..5:
0 1 2 3 4 5 ---------------------------------
1 1 1 Available pounds of feed