2013ACM-ICPC杭州赛区全国邀请赛(题目重现)

Robot

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
  
  
Michael has a telecontrol robot. One day he put the robot on a loop with n cells. The cells are numbered from 1 to n clockwise.
At first the robot is in cell 1. Then Michael uses a remote control to send m commands to the robot. A command will make the robot walk some distance. Unfortunately the direction part on the remote control is broken, so for every command the robot will chose a direction(clockwise or anticlockwise) randomly with equal possibility, and then walk w cells forward. Michael wants to know the possibility of the robot stopping in the cell that cell number >= l and <= r after m commands.
 

Input
  
  
There are multiple test cases. Each test case contains several lines. The first line contains four integers: above mentioned n(1≤n≤200) ,m(0≤m≤1,000,000),l,r(1≤l≤r≤n). Then m lines follow, each representing a command. A command is a integer w(1≤w≤100) representing the cell length the robot will walk for this command.   The input end with n=0,m=0,l=0,r=0. You should not process this test case.
 

Output
  
  
For each test case in the input, you should output a line with the expected possibility. Output should be round to 4 digits after decimal points.
 

Sample Input
  
  
3 1 1 2 1 5 2 4 4 1 2 0 0 0 0
 

Sample Output
  
  

0.5000

0.2500

 

 

X-Boxes

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
  
  
Crazygirl is a crazy fan of XBOX games. Today, she’s here middle in a competition, in which the winner will be rewarded with an opportunity of working in the XBOX Company as a game testing player. Now, here comes the final game. As Cazygirl get a draw with the other competitor, Lich King, she must beat Lich this time. The game is quite simple. There are n balls numbered from 1 to n and k boxes B 1, B 2,…, B k satisfying following conditions: 1.  With any ball x in box B i, there must be ball 2x in box B i+1 if there is a box B i+1; 2.  With any ball x in box B i, there must be ball y in box B i-1 satisfying 2y=x if there is a box B i-1; 3.  You can’t put a ball in two different boxes at the same time; 4.  Your score is the number of balls in box B 1; 5.  The player who get the highest score win the game of course. So, you should tell Crazygirl the highest score she can get.
 


 

Input
  
  
The first line is the number of test cases. Each test case has one line containing two integers n and k, meaning that there are n balls and k boxes. ( 1≤n≤10 10000, 2≤k≤25 )
 


 

Output
  
  
For each test case, output one line that contains an integer equals to the highest score you can get.
 


 

Sample Input
  
  
3 10 2 7 5 8 3
 
 
3.

Transformation

Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 65535/65536 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
   
   
Yuanfang is puzzled with the question below: There are n integers, a 1, a 2, …, a n. The initial values of them are 0. There are four kinds of operations. Operation 1: Add c to each number between a x and a y inclusive. In other words, do transformation a k<---a k+c, k = x,x+1,…,y. Operation 2: Multiply c to each number between a x and a y inclusive. In other words, do transformation a k<---a k×c, k = x,x+1,…,y. Operation 3: Change the numbers between a x and a y to c, inclusive. In other words, do transformation a k<---c, k = x,x+1,…,y. Operation 4: Get the sum of p power among the numbers between a x and a y inclusive. In other words, get the result of a x p+a x+1 p+…+a y p. Yuanfang has no idea of how to do it. So he wants to ask you to help him.
 

Input
   
   
There are no more than 10 test cases. For each case, the first line contains two numbers n and m, meaning that there are n integers and m operations. 1 <= n, m <= 100,000. Each the following m lines contains an operation. Operation 1 to 3 is in this format: "1 x y c" or "2 x y c" or "3 x y c". Operation 4 is in this format: "4 x y p". (1 <= x <= y <= n, 1 <= c <= 10,000, 1 <= p <= 3) The input ends with 0 0.
 

Output
   
   
For each operation 4, output a single integer in one line representing the result. The answer may be quite large. You just need to calculate the remainder of the answer when divided by 10007.
 

Sample Input
   
   
5 5 3 3 5 7 1 2 4 4 4 1 5 2 2 2 5 8 4 3 5 3 0 0
 

Sample Output
   
   
307 7489
 

4.

Random Walk

Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 65535/65536 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
   
   
Yuanfang is walking on a chain. The chain has n nodes numbered from 1 to n. Every second, he can move from node i to node j with probability:
c(i,j) is an element in a given parameter matrix which is n×m. (1 <= c(i, j) <= 9) Yuanfang wants to know the expectation time for him to walk from node 1 to node n.
 

Input
   
   
There are no more than 10 test cases. In each case, there are two integers n (2 <= n <= 50000), m (1 <= m <= 5), in the first line, meaning that there are n nodes and the parameter matrix is n×m . There are m integers in each of the next n lines which describe the parameter matrix . The input ends with 0 0.
 

Output
   
   
For each case, output the expectation time for Yuanfang to walk from node 1 to node n in one line. The answer should be rounded to 2 digits after decimal point.
 

Sample Input
   
   
3 1 1 1 1 5 2 1 2 2 1 3 2 2 3 1 3 0 0
 

Sample Output
   
   
6.94 8.75
5.

Worm

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
    
    
Guy is a flying worm. A gun men are hunting him. Guy can't keep running all the time . At night ,he has to find a place to sleep, and that's very dangerous. In the sky, there are many flying rocks, Guy decides to stay on those rocks at night. The good thing is that the gun man is stupid, he always fire toward a fixed direction. And Guy knows the direction. Guy wants to find a place on a certain rock so that the rock can protect him best from the bullets. The more distance a bullet has to travel inside the rock to reach Guy, the safer is Guy. Please find the safest place for Guy. Guy's world is a 2D plane. A rock can be consider as a polygon. Guy can just stay on the edge of the rock, he can't get inside a rock. Guy stands on a rock ,but he can't hang on a rock. As shown below, Guy can stay on point B,C and D, but he can't stay on point A,E,F and G because if he stay there, he will fall down to the ground when he get asleep.
The direction of the gun fire can be described as a vector (d x, d y). The gun man is infinite far away, and he can choose any infinite far away point as the firing position. In other words, the bullet may fly along any straight line which is parallel to the vector (d x,d y).
 
 
  
Input
    
    
First Line is an integer T <=20, means the number of test cases. In each test cases, the first line is one integer m describing the number of polygons. Then m polygons follow. Each Polygon P starts with an integer n as the number of vertex of P. after that there are n lines, each line is an integer pair (x, y) , meaning a vertex of P, in clockwise or counter-clockwise order. The last line of each test case is two integers d x, d y, meaning that vector (d x,d y) is the direction of the gun fires. The sum of the vertexes number of all polygons is smaller or equal to 1000. The polygons will not intersect with each other or themselves. One polygon cannot be inside another. There may be extra spaces and empty lines in the input data. For more detail, see the sample input.
 
 
  
Output
    
    
Output one line for each test case ---- the distance a bullet has to travel inside the rock to reach Guy when Guy stays on the safest place. If the bullet can hit Guy directly, output “Poor guy” instead. The result must be round to 2 digits after decimal point.
 
 
  
Sample Input
    
    
3 1 6 0 0 0 1 -1 1 -1 -1 1 -1 1 0 0 1 1 6 0 0 0 1 -1 1 -1 -1 1 -1 1 0 0 -1 3 4 0 0 0 1 2 1 2 0 4 0 2 0 3 1 3 1 2 4 1 3 1 4 2 4 2 3 0 -1
 
 
  
Sample Output
    
    
2.00 Poor guy 1.00
Hint
In the first sample input, Guy could only stand on two segments: {(-1,1)-(0,1)}, and{(0,0)-(1,0)} Notice that, Guy cannot stand on (-1,1),(0,1) and (1,0).
For the firing direction dx = 0, dy = 1, we could see that the safest place is any point on segment (-1,1) - (0,1) (except two ends). And a bullet has two travel distance 2 inside the rock to hit Guy. Please do pay attention to the test case 2 and 3.
 
6.

Microblog Subscription

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
    
    
Jia Baoyu was the best programmer in his big family—the Family of Jia, which is why he was regarded as the most charming gentleman among girls. Recently he was designing a new microblog to target the requirements of sharing information in his family. In his system, a microblog can be regarded as a document contains no more than 2000 words. By asked to other member’s in the Family of Jia, he decided to release a function of “subscription” in his microblog. Let’s describe this function more specifically: A user can submit a query to describe subscription requirement. A query contains a match type, a match distance constraint and a set of not more than 5 English words. After the user submitted the query, he/she will receive all the new microblog that satisfies the query in his/her “Feeds stream”. If a microblog satisfies a query, it should match all the words in the query. And a microblog matches a word X when there is at least a word in microblog that matches the word X. Note that the match constraint is applied independently for each word in the query. There are three types of word matching: exact match, approximate match under a Hamming distance constraint and approximate match under an edit distance. The definitions of these three matches is are follows: Exact match: two words are exactly the same; Approximate match under Hamming distance D constraint:two words with the same length have at most D positions at which corresponding letters are different. Approximate match under edit distance D constraint:one word can be changed into the other word in at most D single-letter edits, including insertion, deletion and substitution. For example, Lin Daiyu submitted a query: edit distance match with distance 1, and the word set “flower poem tear”. Then she will receive the microblog “I wrote a pom full of tears after I saw Daiyu buried the flowers”. In this case, “flower” can be matched with “flowers” in 1 edit distance, “tear” can be matched with “tears” and “poem” can be matched with “pom” (obviously it was a typo). After a user submitted a query, he/she could delete the query in anytime. After that he/she would not receive microblogs that satisfy this query. Now please help Jia Baoyu to accomplish this function.
 
 
  
Input
    
    
The first line of input file contains an integer representing the following number of lines. Each of the following line has three formats: s [id] [type] [dist] [k] [word_1] [word_2] … [word_k] The line that starts with lowercase ‘s’ means adding a query into system. [id] is an integer between 1 to 1000 representing the id of the query. [type] is an integer between 0 to 2 representing the match type (0 means exact match, 1 means hamming distance match and 2 means edit distance match). [dist] is an integer representing the distance constraint (Note that the distance is always 0 for exact match). This distance constraint is at most 2. [k] means the number of following words (0<k<=5). [word_i] represents a word in this query. All the items are separated by a space. e [id] The line that starts with lowercase ‘e’ means deleting a query from system. [id] is the id of that query. We guarantee that the id always exist and has not deleted before. m [id] [k] [word_1] [word_2] … [word_k] The line that starts with lowercase ‘m’ means a microblog. [id] is an integer between 1 to 100 which means the id of the microblog. [k] is an integer meaning the number of words that follows (0<k<=2000). [word_i] represents a word in this microblog. All the items are separated by a space. The length of a word is less than or equal to 30, and there are no blanks in a word. The number of total queries is less than or equal to 1000, while the number of total microblogs is less than or equal to 100.
 
 
  
Output
    
    
For each microblog in the input file, output all the matched active queries when it published. The “active” means that query has been submitted and not deleted yet. The format is: [id] [k] [q_1] [q_2] … [q_k] [id] means the id of this microblog. [k] means the number of queries that it satisfies. [q_i] means a query id. Query ids must be sorted increasingly. The order of microblog in output file must be the same as it is displayed in the input file.
 
 
  
Sample Input
    
    
6 s 1 1 2 1 bkple m 2 1 apple s 2 0 0 2 apple banana m 1 2 apple banana e 1 m 3 2 apple banana
 
 
  
Sample Output
    
    
2 1 1 1 2 1 2 3 1 2
 
7.

DFS spanning tree

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/65536 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
    
    
Consider a Depth-First-Search(DFS) spanning tree T of a undirected connected graph G, we define a T-Simple Circle as a path v 1, v 2, ..., v k (v 1 = v k) in G that contains at most one edge which not belongs to the DFS spanning tree T. Given a graph G, we process DFS on G starting from vertex 1 and get a DFS spanning tree T, then you should choose some edges of G so that all T-Simple Circles contains at least one edge that you choose. Please minimize the number of edges you choose.
 
 
  
Input
    
    
There are at most 100 test cases. For each case, the first line contains two integers n and m denoting the number of vertices and edges. The vertexes are numbered from 1 to n. The following m lines describe the graph. Each line contains two integers x i and y i, denoting an edge between vertex x i and y i(x i ≠ y i). Note that the first n-1 edges of input construct a DFS spanning tree T which is generated by DFS from vertex 1. Input ends with n = 0 and m = 0 (1 <= n <= 2000, 1 <= m <= 20000, 1 <= x i, y i <= n)
 
 
  
Output
    
    
For each case, output the number of minimal edges that you choose.
 
 
  
Sample Input
    
    
4 5 1 2 4 2 3 2 1 3 4 1 10 14 1 2 2 9 1 3 3 4 4 10 3 5 5 7 5 8 3 6 9 1 1 10 1 6 7 3 8 3 0 0
 
 
  
Sample Output
    
    
1 3
Hint
Here is the graph G in the first test case:
The solid lines denote the edge which belongs to the DFS spanning tree, and the dotted lines denote the others. For first case, we can choose one edge (1, 2) For second case, we can choose three edges (1, 2), (1, 3), (3, 5)
 
8.

Coffee shop in Jioufen

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65536 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0
Problem Description
     
     
Cheer manages a coffee shop in Jioufen. As she is the only assistant in the shop, it is a big problem for her to mix up raw materials into a cup of coffee. To simplify the problem, we can assume that Cheer has n kinds of raw material, and the i-th raw material has been assigned with a value a i denoting its level of deliciousness. For some unknown reason, Cheer believe that a kind of coffee is perfect if and only if the value of its all kinds of raw materials are co-prime with each other. A kind of perfect coffee also can be made without any of these raw materials, only by water. Now given n kinds of raw material and their value of deliciousness, find out how many distinct kinds of perfect coffee can be made by them. Note that two kinds of coffee are considered distinct if and only if the raw material sets of them are distinct.
 

Input
     
     
There are at most 75 test cases. For each case, The first line contains one integer n indicating the number of kind of raw material. The next line contains n integers separated by space, denoting deliciousness values: a 1, a 2, ..., a n (1 <= n <= 60, 1 <= a i <= 2 31-1) The input ends with n = 0
 

Output
     
     
For each test case, print the number of distinct kind of prefect coffee she can made in one line.
 

Sample Input
     
     
2 2 2 3 1 2 3 3 2 3 4 0
 

Sample Output
     
     
3 8 6
Hint
For the first case, there 3 distinct kinds of perfect coffee: none of these raw materials, only with the first kind of raw material, and only with the second kind of raw material. Coffee with both the first kind of raw material and the second is not considered as perfect coffee, because the deliciousness levels of first kind of raw material and the second are not co-prime.


 

Sample Output
  
  
4 0 1

 

9.

Building bridges

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
  
  
Hululu and Cululu are two pacific ocean countries made up of many islands. These two country has so many years of friendship so they decide to build bridges to connect their islands. Now they want to build the first bridge to connect an island of Hululu and an island of Culuu . Their world can be considered as a matrix made up of three letters 'H','C' and 'O'.Every 'H' stands for an island of Hululu, every 'C' stands for an island of Cululu, and 'O' stands for the ocean. Here is a example:
The coordinate of the up-left corner is (0,0), and the down-right corner is (4, 3). The x-direction is horizontal, and the y-direction is vertical. There may be too many options of selecting two islands. To simplify the problem , they come up with some rules below: 1. The distance between the two islands must be as short as possible. If the two islands' coordinates are (x1,y1) and (x2,y2), the distance is |x1-x2|+|y1-y2|. 2. If there are more than one pair of islands satisfied the rule 1, choose the pair in which the Hululu island has the smallest x coordinate. If there are still more than one options, choose the Hululu island which has the smallest y coordinate. 3.After the Hululu island is decided, if there are multiple options for the Cululu island, also make the choice by rule 2. Please help their people to build the bridge.
 


 

Input
  
  
There are multiple test cases. In each test case, the first line contains two integers M and N, meaning that the matrix is M×N ( 2<=M,N <= 40). Next M lines stand for the matrix. Each line has N letters. The input ends with M = 0 and N = 0. It's guaranteed that there is a solution.
 


 

Output
  
  
For each test case, choose two islands, then print their coordinates in a line in following format: x1 y1 x2 y2 x1,y1 is the coordinate of Hululu island, x2 ,y2 is the coordinate of Cululu island.
 


 

Sample Input
  
  
4 4 CHCH HCHC CCCO COHO 5 4 OHCH HCHC CCCO COHO HCHC 0 0
 


 

Sample Output
  
  
0 1 0 0 0 1 0 2

10.

Shaolin

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
  
  
Shaolin temple is very famous for its Kongfu monks.A lot of young men go to Shaolin temple every year, trying to be a monk there. The master of Shaolin evaluates a young man mainly by his talent on understanding the Buddism scripture, but fighting skill is also taken into account. When a young man passes all the tests and is declared a new monk of Shaolin, there will be a fight , as a part of the welcome party. Every monk has an unique id and a unique fighting grade, which are all integers. The new monk must fight with a old monk whose fighting grade is closest to his fighting grade. If there are two old monks satisfying that condition, the new monk will take the one whose fighting grade is less than his. The master is the first monk in Shaolin, his id is 1,and his fighting grade is 1,000,000,000.He just lost the fighting records. But he still remembers who joined Shaolin earlier, who joined later. Please recover the fighting records for him.
 


 

Input
  
  
There are several test cases. In each test case: The first line is a integer n (0 <n <=100,000),meaning the number of monks who joined Shaolin after the master did.(The master is not included).Then n lines follow. Each line has two integer k and g, meaning a monk's id and his fighting grade.( 0<= k ,g<=5,000,000) The monks are listed by ascending order of jointing time.In other words, monks who joined Shaolin earlier come first. The input ends with n = 0.
 


 

Output
  
  
A fight can be described as two ids of the monks who make that fight. For each test case, output all fights by the ascending order of happening time. Each fight in a line. For each fight, print the new monk's id first ,then the old monk's id.
 


 

Sample Input
  
  
3 2 1 3 3 4 2 0
 


 

Sample Output
  
  
2 1 3 2 4 2
 


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值