Problem
給定每一個蛋白質在下一個時刻會變成什麼,從一開始的各種蛋白質類型的數量,是否會在哪一個時刻符合目標蛋白質種類的數量。
Sample Input
|
|
Sample Output
|
|
Solution
檢查是否有蛋白質轉換的模稜兩可情況,之後模擬出下一個時刻的蛋白質情況。
|
|
給定每一個蛋白質在下一個時刻會變成什麼,從一開始的各種蛋白質類型的數量,是否會在哪一個時刻符合目標蛋白質種類的數量。
|
|
|
|
檢查是否有蛋白質轉換的模稜兩可情況,之後模擬出下一個時刻的蛋白質情況。
|
|
You are given a string S of length N. Can you find a string P which satisfies the following conditions?
Length of P will be N
Distance between S and P will be less than or equal to K
P will be a palindrome.
P can contain only characters ‘a’, ‘b’, …, ‘z’
You have to calculate, in how many ways you can choose P. This number can be very large, so print the answer modulo 1000000000 (109).
Notes:
A string is a sequence of characters. For this problem consider that all strings can contain only ‘a’, ‘b’, …, ‘z’, i.e. 26 available characters.
The length of the string is defined by the number of characters in the string. For example, length of “abcba” is 5.
A string is called palindrome when it is the same string when written from forwards or backwards. For example – “abcba”, “abba”, “a” are palindrome but “abc” is not a palindrome.
Distance between two string of same length is the number of mismatches of corresponding characters. For example, distance between “abcb” and “bcba” is 4 because no character of first string matches to the character of the corresponding index of second string, but distance between “abc” and “cba” is 2.
Input starts with an integer T (T is around 5000), the number of test cases.
Each test case consists of two lines. First line contains two integers N(1≤N≤1000) and K (0≤K≤1000). Second line contains a string S of length N. S contains only characters from ‘a’, ‘b’, …, ‘z’.
For each test case output the number of test cases followed by the number of ways the string can be chosen modulo 1000000000 (109). See sample output for exact format.
|
|
|
|
題目描述:
對一個 S 字串,修改最多 K 個字符的情況下,求最多有多少不同的字符串是迴文
題目解法:
最樸素的算法,對於每個字串 S,使用 O(NK)
的算法,利用 dp[N][K]
表示對於前綴長為 N,已經修改了 K 個字符的總數為何。
先來看最樸素的寫法,一定會拿 TLE,原因是詢問的次數過多。
|
|
之後,仔細拆解之後,發現由於只會考慮字串的一半,並且條件分為兩種,原本就已經匹配還是沒有匹配,而事實上我們可以分成 P, Q 兩種形式。
所以考慮預先建表,將這兩個事件獨立分開計算,最後乘積起來就可以了。
對於 P, Q 的情況,分別建立 dp(i, j) 為目前 i 個字符,恰好修改 j 次的迴文字串數量。但是題目要求為 最多修改 K 次
,因此對 P, Q 其中一種進行調整為 dp(i, j) 為目前 i 個字符,修改最多 j 次的回文字串數量。
因此對於每次詢問,可以在 O(N)
時間內完成。
|
|
It is very easy to find number of trailing zero in n! for a particular base b. In this problem you have to do the reverse. You have to find for how many bases b, n! has k trailing zeros in base b.
Input starts with a positive number T≤10000, denoting the number of test cases to follow.
Each test case contains two non-negative integers, n≤1015 and 1≤k≤1015 in a line. You may assume and n/k<500.
Output
For each input output one line containing the number of different bases. Print the solution modulo 1000000007
|
|
|
|
題目描述:
對於 n!
的 b 進制數中,尾數恰好為 k 個 0 情況為何?
題目解法:
質因數分解,找到每一個質數的次方數,根據數學組合和排容原理得到,大於等於 k 個 0 的基底情況個數為何,因此
對於 2^n1 * 3^n2 * 5^n3 * 7^n4 ... = n!
,
base = pi^mi * ...
,保證 (pi^mi)^k
=> mi * k <= ni
。計算 mi (0, 1, …, ni/k)的可能情況總數乘積即可。
最後用排容原理吧!
|
|
In geometry, a hypercube is an n-dimensional analogue of a square (n = 2) and a cube (n = 3). It consists in groups of opposite parallel line segments aligned in each of the space’s dimensions, at right angles to each other and of the same length. An n-dimensional hypercube is also called an n-cube.
\epsfbox{p11785.eps}
In parallel computing, the vertexes are processors, and the line segments (edges) represent connections. The n-cube architecture has the following properties:
The new company WEFAIL is designing hypercubes, but they are always contracting new people, whose do not know all the hypercube properties, and sometimes they fail; thus these properties are not satisfied in all cases. Given an arbitrary graph, your task is to write a program that determines whether the graph is a hypercube or not.
The input consists in several problem instances. Each instance contains one graph, which starts with a line with two positive integers: K and M, representing the number of vertexes ( 0 < K$ \le$1024) and the number of edges respectively. It follows ( 0$ \le$M$ \le$5130) lines, representing the edges. Each edge is given by two 32 bits integers, representing the processors connected by the edge.
The end of input is indicated by a test case with K = 0.
For each problem instance, the output is a single line, with the word YES
if the corresponding graph is a hypercube, and NO
otherwise (quotes for clarity). The output must be written to standard output.
|
|
|
|
題目描述:
判斷是否與超立方體同構
題目解法:
原本使用貪心的映射方式,然後進行超立方體的判斷,但是這樣的條件不好撰寫,其中肯定有 BUG。
最後使用全局最短路總和會相同的方式,還真是各種邪惡的題目。然而題目假使會有超出節點的編號,直接忽略報錯即可。
|
|
The racing cars of today are equipped with so many sophisticated equipment. Introduction of a new visual transducer which is interfaced with the on-board computer can tell you on the fly how many cars are ahead of you while how many are trailing. There are N cars on a racing track. Each has an on-board computer with the new feature. During the race, every single car’s computer keeps displaying two integers, a (The number of cars in front of him) & b (The number of cars behind him) for a particular moment. It is possible that at some time, some of the cars are racing side by side i.e. they are exactly at the same location. A car will not consider any other car at the same location to be a leading or trailing car.
Now, it is suspected that some of the new transducers are not working properly inside such high speed vehicles. The report with all computers’ data generated at a particular timestamp is reported to you. You are to determine the minimum number of cars that have faulty data.
Each test case begins with an integer N (1<=N<=1000), the number of cars on a track . The next N lines each has two integers - a & b (0<=a,b<=1500) for a particular car.
The last test case is followed by a line with a single 0 indicating the end of input.
For each test case, print a line in the format, “Case X: Y”, where X is the case number & Y is the minimum number of cars that must have faulty data according to the report.
|
|
|
|
題目描述:
有n个人进行比赛,给出每个人的状况,a表示这个人前面有a个人,b表示说这个人后面有b个人。问说最少有多少个人的状态是不成立的。
題目解法:
將問題轉換成區間,來表示這個人可能所在的區間,假使前面有 a 個人,後面有 b 個人,則這個人可能所在為 [a+1, n-b]
,我們允許區間內最高容量為 n - b - a
(當作權重) 個人,求不相交區間的最大權重。
最後 n 扣除這個最大權重就是答案。
|
|
In circuit design, component placement is an important step in the design automation. Inferior placements may affect the performance and manufacturing cost.
You are given a PCB (Printed Circuit Board). It’s a large green board. You can place components on either side of the PCB. However, cost of placing a component on both sides are not the same. You are given N components. For each component ci, cost of placing it on the top layer is Xi and on the bottom layer is Yi.
These components may interact with each other. If both the components are on the same side of the PCB, the interconnection cost is negligible. But, if they are on different sides, their interconnection is costly. For each such interconnection j, the cost will be Zj.
Finally, some design issues restricts some components to be on the top side or bottom side. Now, find the minimum cost to place the components.
First line contains a positive integer T (T<= 50) that denotes the number of test cases.
Each test case starts with 2 integers N (1 <= N <= 200) and M (0 <= M <= 100000, M <= N * (N-1) / 2), the number of components and number of interconnections. This will be followed by N integers in a line, each between 1 and 10000000 (inclusive), where i-th of it describes the cost of placing the component on the top layer. The next line contains N more integers, each between 1 and 10000000 (inclusive), where i-th of it denotes the cost of placing it on the bottom layer. The next line contains N more integers, each will be either 0, -1 or +1, where
-1
means i-th component can only be placed on the bottom+1
means i-th component can only be placed on the top0
means the component can be placed on either sideThen there will be M lines, each containing three integers, p, q, and r (1 <= p, q <= N, 1 <= r <= 10000000), denoting that, p and q-th component has to be interconnected and if they are on different layers, the cost of interconnection will be r. There will be at most one interconnection between any pair or components.
For each test case, output the minimum cost to place the components.
|
|
|
|
題目描述:
有一些元件,設置在電路板上面時,要不放上面或者是放下面,放置的成本各有不同,假如兩個元件之間必須相連,則當他們放置在不同側的時候,會有額外的花費,如果放在同側則無需考慮。
求放置的最小成本。
題目解法:
利用最大流 = 最小割的方式,將不同側的成本反應在最小割上面。
|
|
題目描述:
找前 S 小的 M 符合取模結果存在於給定的集合。
題目解法:
對於取模結果窮舉,可以在 O(n)
時間內利用中國餘式定理得到其最小解,但是如果窮舉情況太多,倒不如直接窮舉數字。
特別小心,M > 0
的條件,為了除去這個 bug,花了不少時間。
|
|
You have recently been appointed as the administrator for a wired network of devices. Unfortunately, your predecessor used very poor quality lines to connect the devices. The board of executives is currently deciding if they want to fund an upgrade to a wireless network, or simply replace the existing wires with ones of better quality. As expected, this decision is being weighed down with bureaucratic nonsense; it looks like it will take some time before anything is approved.
Meanwhile, you still have to deal with the problem at hand. You have access to an antiquated version of Newton Network Monitor which is a software package that, once installed on a machine, will monitor all lines connected to that machine and immediately alert the user when a line has failed. This should help reduce your response time to any failures.
Your task is to install the software on some machines so each line is being monitored by at least one of its endpoint devices. For various technical reasons, the time it takes to install the software varies from device to device so you want to minimize the total amount of time spent installing the software. You cannot install on more than one machine at a time (since you only have one copy of the software) meaning the total time spent installing the software is exactly the sum of the installation times on each machine.
Each input case begins with two numbers n,m with 1 ≤ n ≤ 1,000 and 0 ≤ m ≤ 25,000. Following this are m pairs of distinct integers between 0 and n-1 which describe a wire connecting the two devices. The time spent installing the software on machine numbered i is 2i. The input is terminated with n = m = 0; this should not be processed.
Output Format
For each input case, there is to be one line of output containing a sequence of n bits with no spaces. The i’th bit is 1 if the software is installed on machine i, and 0 if not.
|
|
|
|
題目描述:
給定一個 N 個點的城市和邊,每一條邊上至少有一個點安裝服務,而在編號 i 的地方設置服務器成本為 $2^{i}$,求最少花費。
題目解法:
明顯地,會發現對於編號最大的節點來說,周遭的點數全設置也不會比該點設置來得高,那還不如將周圍都設置服務。藉此,從編號大的開始檢查,如果還沒有設置服務,將其鄰居全都設置服務!
|
|
We are at a funfair, where an array of trampolines, named ‘’The Grasshopper Labyrinth’’, catches our attention. As the figure below shows, all of them are labelled with non-negative integers:
\epsfbox{p11705a.eps}
People are inside, jumping from one trampoline to another, trying to reach the trampoline in the northwest corner, where the exit to the attraction is located. If you reach the exit fast enough, you may win a prize. However, in order to be eligible for the prize, you must abide by the following rule: after leaping from a trampoline labelled with z, you need to get to another one z trampolines away, in the same row or column.
Therefore, your problem is to find the shortest path from any trampoline to the way out, measured by the number of leaps needed. Since the length of the jump from any trampoline is given, it is sufficient to label each trampoline with the direction of the best jump from it.
\epsfbox{p11705b.eps}
For a given starting position, a path is considered shorter than another if it requires a smaller number of jumps; in case of a tie, the path whose first step gets you northmost in the array is to be preferred; and in case of a tie, the one getting you westmost.
Instead of these symbols, we are using the plain text ones: the appropriate cardinal point (‘N’, ‘S’, ‘E’ or ‘W’) for the arrows, ‘X’ for the trampolines without possible escape, and the asterisk ‘*’ for the special trampoline at the upper left position, which represents the exit.
Several cases are given in a single test file. The first line in each test case contains a pair of integers between 1 and 50, separated by a single space; the first is the number of rows and the second the number of columns in the matrix. Then, the entries in the matrix follow, line by line, each element being a non-negative integer, again separated by single whitespace characters. A 0 x 0 matrix will denote the end of the test cases, and hence should not be analyzed.
The expected output of each data case is a character matrix. Each element is one of the allowed charset, N'',
S’’, E'',
W’’, X'' or
*’’, as described above. The output for each case is followed by a blank line.
|
|
|
|
題目描述:
每一個位置的彈簧上會標記一個數字 w,表示可以跳躍至上下左右其中一個方向的 w 距離所在。
求每一個位置下一步的方向,來獲得最短路徑 (跳躍次數) 到最左上角。
題目解法:
題目忘了講到字典順序,如果有相同的情況,則選擇跳躍越左上角越好。
|
|
After writing a solver for the “moveable maze” game last week, you have grown tired of it. After all, you already know the optimal solution. To entertain yourself, you find another puzzle game called “Pipes”, and play that for a while. On one puzzle, you have not been able to find a solution by hand, and you think that there is no solution. You decide to write a program to tell you whether this is the case.
The game is played on a grid with R rows and C columns. Each square of the grid contains a black dot in the centre and black lines in the direction of some, none, or all of its north, east, south, and west neighbouring squares, with the following restriction: if two opposite directions both have lines, then at least one of the other two directions has a line as well. In other words, it is forbidden for a square to consist of a straight line.
The objective of the game is to rotate each square, as many times as you like, such that for each square, if it has a line going in a compass direction (that is, north, east, south, or west), then it has a neighbour in that compass direction and that neighbour has a line going in the opposite compass direction. In other words, each edge in the grid should either have a line on both sides or neither side.
Your task is to determine whether a given grid has a solution.
The input consists of several test cases.
The first line of each test case contains the two integers R and C, separated by spaces, with 1 <= R,C <= 12.
The following R lines of input each contain one row of the grid, from north to south. Each of these lines contains exactly C strings of letters, separated by spaces, that correspond to squares of the grid, from west to east. Their format is as follows:
Input is terminated by a line containing 0 0. These zeros are not a test case and should not be processed.
|
|
For each test case, output SOLVABLE if there is a solution to the puzzle, and UNSOLVABLE otherwise.
Output for Sample Input
|
|
題目描述:
一個類似水管通路的遊戲,每一格都會有四個方向的缺口,請將每一個缺口與相鄰的格子缺口對齊。
題目解法:
當初以為是要從某一個邊流向到另一個邊,但是題目並沒有說明這些,其實就假想每一個格子都會有四個方向的標記,翻轉每一個格子,標記和標記之間要對到。(有標記的邊一定要與另一個有標記的邊相鄰)
因此,類似於關燈遊戲的窮舉方式,從左上依序窮舉到右下,同時檢查上一列的條件是否符合。
|
|