poj1067

maksyuki 发表于 oj 分类,标签:
0

取石子游戏

有两堆石子,数量任意,可以不同。游戏开始由两个人轮流取石子。游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子;二是可以在两堆中同时取走相同数量的石子。最后把石子全部取完者为胜者。现在给出初始的两堆石子的数目,如果轮到你先取,假设双方都采取最好的策略,问最后你是胜者还是败者。 阅读全文 »

poj1064

maksyuki 发表于 oj 分类,标签:
0

Cable master

Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Committee has volunteered and has promised to organize the most honest contest ever. It was decided to connect computers for the contestants using a "star" topology - i.e. connect them all to a single central hub. To organize a truly honest contest, the Head of the Judging Committee has decreed to place all contestants evenly around the hub on an equal distance from it.To buy network cables, the Judging Committee has contacted a local network solutions provider with a request to sell for them a specified number of cables with equal lengths. The Judging Committee wants the cables to be as long as possible to sit contestants as far from each other as possible.

The Cable Master of the company was assigned to the task. He knows the length of each cable in the stock up to a centimeter,and he can cut them with a centimeter precision being told the length of the pieces he must cut. However, this time, the length is not known and the Cable Master is completely puzzled.
You are to help the Cable Master, by writing a program that will determine the maximal possible length of a cable piece that can be cut from the cables in the stock, to get the specified number of pieces.

Input

The first line of the input file contains two integer numb ers N and K, separated by a space. N (1 = N = 10000) is the number of cables in the stock, and K (1 = K = 10000) is the number of requested pieces. The first line is followed by N lines with one number per line, that specify the length of each cable in the stock in meters. All cables are at least 1 meter and at most 100 kilometers in length. All lengths in the input file are written with a centimeter precision, with exactly two digits after a decimal point.

Output

Write to the output file the maximal length (in meters) of the pieces that Cable Master may cut from the cables in the stock to get the requested number of pieces. The number must be written with a centimeter precision, with exactly two digits after a decimal point.
If it is not possible to cut the requested number of pieces each one being at least one centimeter long, then the output file must contain the single number "0.00" (without quotes).

Sample Input

4 11

8.02

7.43

4.57

5.39

Sample Output

2.00

Source

Northeastern Europe 2001

 

题目类型:二分

算法分析:在[0, INF]之间二分枚举长度。对于每一次枚举的长度,判断使用该长度是否能够将k个电缆割好。如果能,则向上枚举长度,否则向下枚举长度,注意本题的坑点是精度!!!!!!

 

poj1061

maksyuki 发表于 oj 分类,标签:
0

青蛙的约会

两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面。它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止。可是它们出发之前忘记了一件很重要的事情,既没有问清楚对方的特征, 阅读全文 »

poj1060

maksyuki 发表于 oj 分类,标签: ,
0

Modular multiplication of polynomials

Consider polynomials whose coefficients are 0 and 1. Addition of two polynomials is achieved by 'adding' the coefficients for the corresponding powers in the polynomials. The addition of coefficients is performed by addition modulo 2, i.e., (0 + 0) mod 2 = 0, (0 + 1) mod 2 = 1, (1 + 0) mod 2 = 1, and (1 + 1) mod 2 = 0. Hence, it is the same as the exclusive-or operation. Description
(x^6 + x^4 + x^2 + x + 1) + (x^7 + x + 1) = x^7 + x^6 + x^4 + x^2

Subtraction of two polynomials is done similarly. Since subtraction of coefficients is performed by subtraction modulo 2 which is also the exclusive-or operation, subtraction of polynomials is identical to addition of polynomials.

(x^6 + x^4 + x^2 + x + 1) - (x^7 + x + 1) = x^7 + x^6 + x^4 + x^2

Multiplication of two polynomials is done in the usual way (of course, addition of coefficients is performed by addition modulo 2).

(x^6 + x^4 + x^2 + x + 1) (x^7 + x + 1) = x^13 + x^11 + x^9 + x^8 + x^6 + x^5 + x^4 + x^3 + 1

Multiplication of two polynomials f(x) and g(x) modulo a polynomial h(x) is the remainder of f(x)g(x) divided by h(x).

(x^6 + x^4 + x^2 + x + 1) (x^7 + x + 1) modulo (x^8 + x^4 + x^3 + x + 1) = x^7 + x^6 + 1
The largest exponent of a polynomial is called its degree. For example, the degree of x^7 + x^6 + 1 is 7.

Given three polynomials f(x), g(x), and h(x), you are to write a program that computes f(x)g(x) modulo h(x).
We assume that the degrees of both f(x) and g(x) are less than the degree of h(x). The degree of a polynomial is less than 1000.

Since coefficients of a polynomial are 0 or 1, a polynomial can be represented by d+1 and a bit string of length d+1, where d is the degree of the polynomial and the bit string represents the coefficients of the polynomial. For example, x^7 + x^6 + 1 can be represented by 8 1 1 0 0 0 0 0 1.

Input

The input consists of T test cases. The number of test cases (T) is given in the first line of the input file. Each test case consists of three lines that contain three polynomials f(x), g(x), and h(x), one per line. Each polynomial is represented as described above.

Output

The output should contain the polynomial f(x)g(x) modulo h(x), one per line.

Sample Input

2

7 1 0 1 0 1 1 1

8 1 0 0 0 0 0 1 1

9 1 0 0 0 1 1 0 1 1

10 1 1 0 1 0 0 1 0 0 1

12 1 1 0 1 0 0 1 1 0 0 1 0

15 1 0 1 0 1 1 0 1 1 1 1 1 0 0 1

Sample Output

8 1 1 0 0 0 0 0 1

14 1 1 0 1 1 0 0 1 1 1 0 1 0 0

Source

Taejon 2001

 

题目类型:模拟+高精度

算法分析:按照题目的要求模拟计算的过程即可

 

poj1050

maksyuki 发表于 oj 分类,标签:
0

To the Max

Given a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous sub-array of size 1*1 or greater located within the whole array. The sum of a rectangle is the sum of all the elements in that rectangle. In this problem the sub-rectangle with the largest sum is referred to as the maximal sub-rectangle.

As an example, the maximal sub-rectangle of the array:

0 -2 -7 0
9 2 -6 2
-4 1 -4 1
-1 8 0 -2
is in the lower left corner:

9 2
-4 1
-1 8
and has a sum of 15.

Input

The input consists of an N * N array of integers. The input begins with a single positive integer N on a line by itself, indicating the size of the square two-dimensional array. This is followed by N^2 integers separated by whitespace (spaces and newlines). These are the N^2 integers of the array, presented in row-major order. That is, all numbers in the first row, left to right, then all numbers in the second row, left to right, etc. N may be as large as 100. The numbers in the array will be in the range [-127,127].

Output

Output the sum of the maximal sub-rectangle.

Sample Input

4

0 -2 -7 0 9 2 -6 2

-4 1 -4  1 -1

8  0 -2

Sample Output

15

Source

Greater New York 2001

 

题目类型:线性dp扩展

算法分析: 使用变量i和j(i <= j)枚举所有的行下标,然后将同列的数压缩成一个数。使得二维的矩阵变成了一个一维的数组,然后直接求解最大连续子段和即可

 不使用dp数组来存储中间结果,直接边算边更新最大值,可以优化空间复杂度

 

poj1047

maksyuki 发表于 oj 分类,标签:
0

Round and Round We Go

A cyclic number is an integer n digits in length which, when multiplied by any integer from 1 to n, yields a"cycle"of the digits of the original number. That is, if you consider the number after the last digit to "wrap around"back to the first digit, the sequence of digits in both numbers will be the same, though they may start at different positions.For example, the number 142857 is cyclic, as illustrated by the following table:

142857 *1 = 142857
142857 *2 = 285714
142857 *3 = 428571
142857 *4 = 571428
142857 *5 = 714285
142857 *6 = 857142

Input

Write a program which will determine whether or not numbers are cyclic. The input file is a list of integers from 2 to 60 digits in length. (Note that preceding zeros should not be removed, they are considered part of the number and count in determining n. Thus, "01"is a two-digit number, distinct from "1" which is a one-digit number.)

Output

For each input integer, write a line in the output indicating whether or not it is cyclic.

Sample Input

142857

142856

142858

01

0588235294117647

Sample Output

142857 is cyclic

142856 is not cyclic

142858 is not cyclic

01 is not cyclic

0588235294117647 is cyclic

Source

Greater New York 2001

 

题目类型:简单数学

算法分析:若循环节的位数为6,将上式乘以10 ^ 6得 =>10 ^ 6 / 7 = 142857.142857142857...

=>(10 ^ 6 - 1) / 7 = 142857 => 999999 / 7 = 142857。对于其他数num,如果其位数是n,如果num * (n + 1)得到的结果是n个9,那么这个数就是可循环的

 

poj1045

maksyuki 发表于 oj 分类,标签:
0

Bode Plot

Consider the AC circuit below. We will assume that the circuit is in steady-state. Thus, the voltage at nodes 1 and 2 are given 阅读全文 »

poj1028

maksyuki 发表于 oj 分类,标签:
0

Web Navigation

Standard web browsers contain features to move backward and forward among the pages recently visited. One way to implement these features is to use two stacks to keep track of the pages that can be reached by moving backward and forward. In this problem, you are asked to implement this.The following commands need to be supported:

BACK: Push the current page on the top of the forward stack. Pop the page from the top of the backward stack, making it the new current page. If the backward stack is empty, the command is ignored.
FORWARD: Push the current page on the top of the backward stack. Pop the page from the top of the forward stack, making it the new current page. If the forward stack is empty, the command is ignored.
VISIT : Push the current page on the top of the backward stack, and make the URL specified the new current page. The forward stack is emptied.
QUIT: Quit the browser.
Assume that the browser initially loads the web page at the URL http://www.acm.org/

Input

Input is a sequence of commands. The command keywords BACK, FORWARD, VISIT, and QUIT are all in uppercase. URLs have no whitespace and have at most 70 characters. You may assume that no problem instance requires more than 100 elements in each stack at any time. The end of input is indicated by the QUIT command.

Output

For each command other than QUIT, print the URL of the current page after the command is executed if the command is not ignored. Otherwise, print "Ignored". The output for each command should be printed on its own line. No output is produced for the QUIT command.

Sample Input

VISIT http://acm.ashland.edu/

VISIT http://acm.baylor.edu/acmicpc/

BACK

BACK

BACK

FORWARD

VISIT http://www.ibm.com/

BACK

BACK

FORWARD

FORWARD

FORWARD

QUIT

Sample Output

http://acm.ashland.edu/

http://acm.baylor.edu/

acmicpc/http://acm.ashland.edu/

http://www.acm.org/

Ignored

http://acm.ashland.edu/

http://www.ibm.com/

http://acm.ashland.edu/

http://www.acm.org/

http://acm.ashland.edu/

http://www.ibm.com/

Ignored

Source

East Central North America 2001

 

题目类型:模拟

算法分析:按照题目的要求直接模拟即可。注意“VISIT“命令要将栈forw清空

 

poj1011

maksyuki 发表于 oj 分类,标签:
0

Sticks

George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the original state, but he forgot how many sticks he had originally and how long they were originally. Please help him and design a program which computes the smallest possible original length of those sticks. All lengths expressed in units are integers greater than zero.

Input

The input contains blocks of 2 lines. The first line contains the number of sticks parts after cutting, there are at most 64 sticks. The second line contains the lengths of those parts separated by the space. The last line of the file contains zero.

Output

The output should contains the smallest possible length of original sticks, one per line.

Sample Input

9

5 2 1 5 2 1 5 2 1

4

1 2 3 4

0

Sample Output

6

5

Source

Central Europe 1995

 

题目类型:搜索

算法分析:本题采用DFS算法:

 1首先将数据按照降序排序。

2从数据数值最大的开始,依次减去长度值,直到棒子的长度变为0为止,同时标记用到的数值。

3如果长度变为0,则把length恢复原值,再执行一次。

4如果失败,则返回到前一个状态。

5如果做出sum/length个长度是length的棒子就成功了。

 

poj1006

maksyuki 发表于 oj 分类,标签:
0

Biorhythms

Some people believe that there are three cycles in a person's life that start the day he or she is born. These three cycles are the physical, emotional, and intellectual cycles, and they have periods of lengths 23, 阅读全文 »

poj1005

maksyuki 发表于 oj 分类,标签:
0

I Think I Need a Houseboat

Fred Mapper is considering purchasing some land in Louisiana to build his house on. In the process of investigating the land, he learned that the state of Louisiana is actually shrinking by 50 square 阅读全文 »

poj1003

maksyuki 发表于 oj 分类,标签: ,
0

Hangover

How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We're assuming that the cards must be perpendicular to the table.) With two cards you can make the top card overhang the bottom one by half a card length, and the bottom one overhang the table by a third of a card length, for a total maximum overhang of 1/2 + 1/3 = 5/6 card lengths. In general you can make n cards overhang by 1/2 + 1/3 + 1/4 + ... + 1/(n + 1) card lengths, where the top card overhangs the second by 1/2, the second overhangs tha third by 1/3, the third overhangs the fourth by 1/4, etc., and the bottom card overhangs the table by 1/(n + 1). This is illustrated in the figure below.

Input

The input consists of one or more test cases, followed by a line containing the number 0.00 that signals the end of the input. Each test case is a single line containing a positive floating-point number c whose value is at least 0.01 and at most 5.20; c will contain exactly three digits.

Output

For each test case, output the minimum number of cards necessary to achieve an overhang of at least c card lengths. Use the exact output format shown in the examples.

Sample Input

1.00

3.71

0.04

5.19

0.00

Sample Output

3 card(s)

61 card(s)

1 card(s)

273 card(s)

Source

Mid-Central USA 2001

 

题目类型:简单数学+二分

算法分析:先将所有的值预先处理出来,然后对于每一次的查询,二分答案

 

poj1001

maksyuki 发表于 oj 分类,标签:
0

Exponentiation

Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer systems.

This problem requires that you write a program to compute the exact value of Rn where R is a real number ( 0.0 < R < 99.999 ) and n is an integer such that 0 < n <= 25.

Input

The input will consist of a set of pairs of values for R and n. The R value will occupy columns 1 through 6, and the n value will be in columns 8 and 9.

Output

The output will consist of one line for each line of input giving the exact value of R^n. Leading zeros should be suppressed in the output. Insignificant trailing zeros must not be printed. Don't print the decimal point if the result is an integer.

Sample Input

95.123 12

0.4321 20

5.1234 15

6.7592  9

98.999 10

1.0100 12

Sample Output

548815620517731830194541.899025343415715973535967221869852721

.00000005148554641076956121994511276767154838481760200726351203835429763013462401

43992025569.928573701266488041146654993318703707511666295476720493953024

29448126.764121021618164430206909037173276672

90429072743629540498.107596019456651774561044010001

1.126825030131969720661201

Hint

If you don't know how to determine wheather encounted the end of input:
s is a string and n is an integer

C++
while(cin>>s>>n)
{
...
}
c
while(scanf("%s%d",s,&n)==2) //to  see if the scanf read in as many items as you want
/*while(scanf(%s%d",s,&n)!=EOF) //this also work    */
{
...
}

Source

East Central North America 1988

 

题目类型:高精度计算 

算法分析:在计算小数乘法时要注意小数点的位置。首先把R乘上适当的数值变成自然数,为了方便之后找到小数点的位置,因此乘的数值是固定值。计算的时候为了避免清除数组,就要为每一个循环准备局部数组,用完就丢掉

 

hdu4763

maksyuki 发表于 oj 分类,标签:
0

Theme Section

Problem Description

It's time for music! A lot of popular musicians are invited to join us in the music festival. Each of them will play one of their representative songs. To make the programs more interesting and challenging, the hosts are going to add some constraints to the rhythm of the songs, i.e., each song is required to have a 'theme section'. The theme section shall be played at the beginning, the middle, and the end of each song. More specifically, given a theme section E, the song will be in the format of 'EAEBE', where section A and section B could have arbitrary number of notes. Note that there are 26 types of notes, denoted by lower case letters 'a' - 'z'.

To get well prepared for the festival, the hosts want to know the maximum possible length of the theme section of each song. Can you help us?

Input

The integer N in the first line denotes the total number of songs in the festival. Each of the following N lines consists of one string, indicating the notes of the i-th (1 <= i <= N) song. The length of the string will not exceed 10^6.

Output

There will be N lines in the output, where the i-th line denotes the maximum possible length of the theme section of the i-th song.

Sample Input

5

xy

abc

aaa

aaaaba

aaxoaaaaa

Sample Output

0

0

1

1

2

Source

2013 ACM/ICPC Asia Regional Changchun Online

 

题目类型:KMP

算法分析:使用next数组从大到小枚举相等的前后缀的长度,然后在中间再使用一次KMP构建一个next,然后进行一次匹配,直到找到结果或者返回0

 

hdu4549

maksyuki 发表于 oj 分类,标签: ,
0

M斐波那契数列

Problem Description

M斐波那契数列F[n]是一种整数数列,它的定义如下:

F[0] = a
F[1] = b 阅读全文 »

hdu4472

maksyuki 发表于 oj 分类,标签:
0

Count

Problem Description

Prof. Tigris is the head of an archaeological team who is currently in charge of an excavation in a site of ancient relics.
This site contains relics of a village where civilization once 阅读全文 »