文档库 最新最全的文档下载
当前位置:文档库 › ACM比赛试题

ACM比赛试题

ACM比赛试题
ACM比赛试题

The 35th ACM-ICPC Asia Regional Contest (Hangzhou)

Contest Section

October 24, 2010

Sponsored by IBM & Alibaba

Zhejiang Sci-Tech University

This problem set should contain 10 problems on numbered 24 pages. Please inform a runner immediately if something is missing from your problem set.

Problem A. Naughty fairies

Description

Once upon a time, there lived a kind of fairy in the world. Those fairies could hear the voice of fruit trees, and helped people with a harvest. But people did n’t know that fruits are also those fairies’ favorite food. After the fairies ate people’s fruits, they always did something to cover it up.

One day a little fairy named Lily flew into an orchard and found a large peach tree. Hungry as Lily was, she started eating without thinking until her stomach was full. In the fairy world, when a fairy ate the fruits in a fruit tree, sometimes the fruit tree would feel honored and bore more fruits immediately. That’s why sometimes the number of fruits in a tree got increased after a fairy ate fruits of that tree.

But the fairies didn’t want people to find out weird things such as fruits become more or less suddenly. Lily decided to use a magic spell so that the orchard owner couldn’t find the change of the number of p eaches.

Suppose there were N peaches on a tree originally and there were M peaches left after Lily was full. M may be greater than, less than or equal to N. All M peaches were visible at first, and Lily wanted to make an illusion so that exactly N peaches are visible.

Lily can do 3 kinds of spell to change the total visible number of peaches:

1) “PAPADOLA”:This spell would increase the number of visible peaches by one.

2) “EXPETO POTRONUM”:This spell would double the number of visible peaches.

3) “SAVIDA LOHA”:This spell would decrease the number of visible peaches by one. Each spell would take one minute and Lily wanted to finish as fast as possible. Now please tell Lily the least time she needs to change the number of visible peaches to N.

Input

There are several test cases, ended by “0 0”.

For each test case, there are only one line containing two numbers separated by a blank, N and M, the original numbers of peaches and the numbers of peaches left(0

Output

For each test case, you should output just a number K indicating the minimum time (in minutes) Lily needed to finish her illusion magic.

Sample Input

5 2

1 99

86 32

0 0

Sample Output

2

98

12

Problem B. Prison Break

Description

Rompire is a robot kingdom and a lot of robots live there peacefully. But one day, the king of Rompire was captured by human beings. His thinking circuit was changed by human and thus became a tyrant. All those who are against him were put into jail, including our clever Micheal#1. Now it’s time to escape, but Micheal#1 needs an optimal plan and he contacts you, one of his human friends, for help.

The jail area is a rectangle contains n×m little grids, each grid might be one of the following:

1) Empty area, represented by a capital letter ‘S’.

2) The starting position of Micheal#1, represented by a capital letter ‘F’.

3) Energy pool, represented by a capital letter ‘G’. When entering a n energy pool, Micheal#1 can use it to charge his battery ONLY ONCE. After the charging, Micheal#1’s batt ery will become FULL and the energy pool will become an empty area. Of course, passing an energy pool without using it is allowed.

4) Laser sensor, represented by a capital letter ‘D’. Since it is extremely sensitive, Micheal#1 cannot step into a grid with a laser sensor.

5) Power switch, represented by a capital letter ‘Y’. Once Micheal#1 steps into a grid with a Power switch, he will certainly turn it off.

In order to escape from the jail, Micheal#1 need to turn off all the power switches to stop the electric web on the roof—then he can just fly away. Moving to an adjacent grid (directly up, down, left or right) will cost 1 unit of energy and only moving operation costs energy. Of course, Micheal#1 cannot move when his battery contains no energy.

The larger the battery is, the more energy it can save. But larger battery means more weight and higher probability of being found by the weight sensor. So Micheal#1 needs to make his battery as small as possible, and still large enough to hold all energy he need. Assuming that the size of the battery equals to maximum units of energy that can be saved in the battery, and Micheal#1 is fully charged at the beginning, Please tell him the minimum size of the battery needed for his Prison break.

Input

Input contains multiple test cases, ended by 0 0. For each test case, the first line contains two integer numbers n and m showing the size of the jail. Next n lines consist of m capital letters each, which stands for the description of the jail.

You can assume that 1<=n,m<=15, and the sum of energy pools and power switches is less than 15.

Output

For each test case, output one integer in a line, representing the minimum size of the battery Micheal#1 needs. If Micheal#1 can’t escape, output -1.

Sample Input

5 5

GDDSS

SSSFS

SYGYS

SGSYS

SSYSS

0 0

Sample Output

4

Problem C. To Be an Dream Architect Description

The “dream architect” is the key role in a team of “dream extractors” who enter other’s dreams to steal secrets. A dream architect is responsible for crafting the virtual world that the team and the target will dream into. To avoid the target noticing the world is artificial, a dream architect must have powerful 3D imagination.

Cobb uses a simple 3D imagination game to test whether a candidate has the potential to be an dream architect. He lets the candidate imagine a cube consisting of n×n×n blocks in a 3D coordinate system as Figure 1. The block at bottom left front corner is marked (1, 1, 1) and the diagonally opposite block is marked (n, n, n). Then he tells the candidate that the blocks on a certain line are eliminated. The line is always parallel to an axis. After m such block eliminations, the candidate is asked to tell how many blocks are eliminated. Note that one block can only be eliminated once even if it is on multiple lines.

Here is a sample graph according to the first test case in the sample input:

Input

The first line is the number of test cases.

In each test case, the first line contains two integers n and m( 1 <= n <= 1000, 0 <= m <= 1000).,meaning that the cube is n x n x n and there are m eliminations.

Each of the following m lines represents an elimination in the following format:

axis_1=a, axis_2=b

where axis_i (i=1, 2) is ‘X’ or ‘Y’, or ‘Z’ and axis_1 is not equal to axis_2. a and b ar e 32-bit signed integers.

Output

For each test case output the number of eliminated blocks.

Sample Input

2

3 2

Y=1,Z=3

X=3,Y=1

10 2

X=3,Y=3

Y=3,Z=3

Sample Output

5

19

Problem D. Gomoku

Description

You are probably not familiar with the title, “Gomoku”, but you must have played it a lot. Gomoku is an abstract strategy board game and is also called Five in a Row, or GoBang. It is traditionally played with go pieces (black and white stones) on a go board (19x19 intersections). Nowadays, standard chessboard of Gomoku has 15x15 intersections. Black plays first, and players alternate in placing a stone of their color on an empty intersection. The winner is the first player to get an unbroken row of five or more stones horizontally, vertically, or diagonally.

For convenience, we coordinate the chessboard as illustrated above. The left-bottom intersection is (0,0). And the bottom horizontal edge is x-axis, while the left vertical line is y-axis.

I am a fan of this game, actually. However, I have to admit t hat I don’t have a sharp mind. So I need a computer program to help me. What I want is quite simple. Given a chess layout, I want to know whether someone can win within 3 moves, assuming both players are clever enough. Take the picture above for example. There are 31 stones on it already, 16 black ones and 15 white ones. Then we know it is white turn. The white player must place a white stone at (5,8). Otherwise, the black player will win next turn. After that, however, the white player also gets a perfect situation that no matter how his opponent moves, he will win at the 3rd move.

So I want a program to do similar things for me. Given the number of stones and positions of them, the program should tell me whose turn it is, and what will happen within 3 moves.

Input

The input contains no more than 20 cases.

Each case contains n+1 lines which are formatted as follows.

n

x1 y1 c1

x2 y2 c2

......

x n y n c n

The first integer n indicates the number of all stones. n<=222 which means players have enough space to place stones. Then n lines follow. Each line contains three integers: x i and y i and c i. x i and y i are coordinates of the stone, and ci means the color of the stone. If c i=0 the stone is white. If c i=1 the stone is black. It is guaranteed that 0<=x i,y i<=14, and c i=0 or 1. No two stones are placed at the same position. It is also guaranteed that there is no five in a row already, in the given cases.

The input is ended by n=0.

Output

For each test case:

First of all, the program should check whose turn next. Le t’s call the player who will move next “Mr. Lucky”. Obviously, if the number of the black stone equals to the number of white, Mr. Lucky is the black player. If the number of the black stone equals to one plus the numbers of white, Mr. Lucky is the white player. If it is not the first situation or the second, print “Invalid.”

A valid chess layout leads to four situations below:

1)Mr. Lucky wins at the 1st move. In this situation, print :

Place TURN at (x,y) to win in 1 move.

“TURN” must be replaced by “black” or “white” according to the situation and (x,y) is the position of the move. If there are different moves to win, choose the

one where x is the smallest. If there are still different moves, choose the one where y is the smallest.

2)Mr. Lucky’s opp onent wins at the 2nd move. In this situation, print:

Lose in 2 moves.

3)Mr. Lucky wins at the 3rd move. If so, print:

Place TURN at (x,y) to win in 3 moves.

“TURN” should replaced by “black” or “white”, (x,y) is the position where the Mr.

Lucky should place a stone at the 1st move. After he place a stone at (x,y), no matter what his opponent does, Mr. Lucky will win at the 3rd step. If there are multiple choices, do the same thing as described in situation 1.

4)Nobody wins within 3 moves. If so, print:

Cannot win in 3 moves.

Sample Input

31

3 3 1

3 4 0

3 5 0

3 6 0

4 4 1

4 5 1

4 7 0

5 3 0

5 4 0

5 5 1

5 6 1

5 7 1

5 9 1

6 4 1

6 5 1

6 6 0

6 7 1

6 8 0

6 9 0

7 5 1

7 6 0

7 7 1

7 8 1

7 9 0

8 5 0

8 6 1

8 7 0

8 8 1

8 9 0

9 7 1

10 8 0

1

7 7 1

1

7 7 0

Sample Output

Place white at (5,8) to win in 3 moves. Cannot win in 3 moves.

Invalid.

Problem E. Gunshots

Description

President Bartlet was shot! A group of terrorists shot to the crowd when President Bartlet waved to cheering people after his address. Many people were shot by the irrational bullets. Senior FBI agent Don Epps takes responsibility for this case. According to a series of crime scene investigation, including analyzing shot shells, replaying video from closed-circle television and collecting testimony by witnesses, Don keeps all the information about where and how the terrorists shot to crowd, as well as the location of every single person when the gun shoot happened. Now he wants to know how many gunshot victims are there in this case.

Imagine that each target person can be regarded as a polygon (can be concave or self-intersecting) and each gunshot can be regarded as a half-line. The bullet will be stopped by the first person it shoots. A person can be shot in three ways:

To simplify the problem, we assume that any two polygons can be completely separated by a line. Also each start point of the gunshot can be separated from each polygon by a line. Now given M people and N gunshots, please work out which person has been shot by each bullet.

Input

There are multiple test cases in the input. The first line of the input file is an integer T demonstrating the number of test cases. (T<=10).

For each test case, the first line is an integer N, representing the number of people (polygons). Following lines demonstrates the polygons. For the i th polygon (0<=i

1.Normal shot

2.The bullet’s path is

parallel to an edge

3.The bullet’s path is

tangent to an vertex

Then there is a line contains an integer M representing the number of gunshots. In the following M lines, each line contains four real numbers x, y, dx and dy, representing the start point (x, y) and direction vector (dx, dy) of that gunshot.

In all test cases, we assume that 0< N<=100, 0

Output

For each test case, output contains M lines and the i th line demonstrates the result of the i th gunshot.

If the i th gunshot shoots the j th polygon, the i th line contains “HIT j”, otherwise it contains a word “MISS” (means that it does not shoot any target). The polygons are numbered in the order of their appearance in the input file, and the numbers start from 0.

At the end of each test case, please output a single line with “*****”.

Sample Input

1

1

4

0 0

1 1

0 1

1 0

2

-1 0 1 0

-2 0 -1 0

Sample Output

HIT 0

MISS

*****

Hint

The figure of the first case in the samples is as follows:

Problem F. Rotational Painting

Description

Josh Lyman is a gifted painter. One of his great works is a glass painting. He creates some well-designed lines on one side of a thick and polygonal glass, and renders it by some special dyes. The most fantastic thing is that it can generate different meaningful paintings by rotating the glass. This method of design is called “Rotatio nal Painting (RP)” which is created by Josh himself.

You are a fan of Josh and you bought this glass at the astronomical sum of money. Since the glass is thick enough to put erectly on the table, you want to know in total how many ways you can put it so that you can enjoy as many as possible different paintings hiding on the glass. We assume that material of the glass is uniformly distributed. If you can put it erectly and stably in any ways on the table, you can enjoy it.

More specifically, if the polygonal glass is like the polygon in Figure 1, you have just two ways to put it on the table, since all the other ways are not stable. However, the glass like the polygon in Figure 2 has three ways to be appreciated.

Pay attention to the cases in Figure 3. We consider that those glasses are not stable.

Input

The input file contains several test cases. The first line of the file contains an integer T representing the number of test cases.

For each test case, the first line is an integer n representing the number of lines of the polygon. (3<=n<=50000). Then n lines follow. The i th line contains two real number x i and y i representing a point of the polygon. (x i, y i) to (x i+1, y i+1) represents a edge of the polygon (1<=i

Output

For each test case, output a single integer number in a line representing the number of ways to put the polygonal glass stably on the table.

Sample Input

2

4

0 0

100 0

99 1

1 1

6

0 0

0 10

1 10

1 1

10 1

10 0

Sample Output

2

3

Hint

The sample test cases can be demonstrated by Figure 1 and Figure 2 in Description part.

Problem G. Traffic Real Time Query System Description

City C is really a nightmare of all drivers for its traffic jams. To solve the traffic problem, the mayor plans to build a RTQS (Real Time Query System) to monitor all traffic situations. City C is made up of N crossings and M roads, and each road connects two crossings. All roads are bidirectional. One of the important tasks of RTQS is to answer some queries about route-choice problem. Specifically, the task is to find the crossings which a driver MUST pass when he is driving from one given road to another given road.

Input

There are multiple test cases.

For each test case:

The first line contains two integers N and M, representing the number of the crossings and roads.

The next M lines describe the roads. In those M lines, the i th line (i starts from 1)contains two integers X i and Y i, representing that road i connects crossing X i and Y i (X i≠Y i).

The following line contains a single integer Q, representing the number of RTQs. Then Q lines follows, each describing a RTQ by two integers S and T(S≠T) meaning that a driver is now driving on the road s and he wants to reach road t . It will be always at least one way from road s to road t.

The input ends with a line of “0 0”.

Please note that: 0

For each RTQ prints a line containing a single integer representing the number of crossings which the driver MUST pass.

Sample Input

5 6

1 2

2 3

3 4

4 5

3 5

2

2 3

2 4

0 0

Sample Output 0

1

Problem H. National Day Parade

Description

There are n×n students preparing for the National Day parade on the playground. The playground can be considered as a n×m grid. The coordinate of the west north corner is (1,1) , and the coordinate of the east south corner is (n,m).

When training, every students must stand on a line intersection and all students must form a n×n square. The figure above shows a 3×8 playground with 9 students training on it. The thick black dots stand for the students. You can see that 9 students form a 3×3 square.

After training, the students will get a time to relax and move away as they like. To make it easy for their masters to control the training, the students are only allowed to move in the east-west direction. When the next training begins, the master would gather them to form a n×n square again, and the position of the square doesn’t matter. Of course, no student is allowed to stand outside the playground.

You are given the coordinates of each student when they are having a rest. Your task is to figure out the minimum sum of distance that all students should move to form a n×n square.

Input

There are at most 100 test cases.

For each test case:

The first line of one test case contain two integers n,m. (n<=56,m<=200)

Then there are n×n lines. Each line contains two integers, 1<=X i<=n,1<= Y i<=m indicating that the coordinate of the i th student is (X i , Y i ). It is possible for more than one student to stand at the same grid point.

The input is ended with 0 0.

ACM题

求体积 #include #include #define PI 3.1415927 int main() { double x; while(scanf("%lf",&x)!=EOF) { printf("%.3lf\n",(4.0*PI*x*x*x)/3.0); } return 0; } 求a+b II. #include #include #define N 1005 char A[N],B[N],sum[N]; int main() { int T,i,j,k,x,sign; while(scanf("%d",&T)!=EOF) { for(i=0;i

{ sum[x]=(A[j]-'0')+(B[k]-'0')+sign-10; sign=1; } } #include using namespace std; int main() { int a, b; while(cin >> a >> b) cout << a + b << endl; return 0; 求a+b #include using namespace std; int main() { int a,b,s; while(cin>>a>>b) { s=a+b; cout< #include int main() { char s[3],a,b,c,temp; while(scanf("%s",s)!=EOF) { a=s[0];b=s[1];c=s[2]; if(a>b) { temp=a; a=b;

ACM竞赛试题集锦

取石子游戏 Time Limit:1S Memory Limit:1000K Total Submit:505 Accepted:90 Description 有两堆石子,数量任意,可以不同。游戏开始由两个人轮流取石子。游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子;二是可以在两堆中同时取走相同数量的石子。最后把石子全部取完者为胜者。现在给出初始的两堆石子的数目,如果轮到你先取,假设双方都采取最好的策略,问最后你是胜者还是败者。 Input 输入包含若干行,表示若干种石子的初始情况,其中每一行包含两个非负整数a和b,表示两堆石子的数目,a和b都不大于1,000,000,000。 Output 输出对应也有若干行,每行包含一个数字1或0,如果最后你是胜者,则为1,反之,则为0。 Sample Input

2 1 8 4 4 7 Sample Output 1 跳蚤 Time Limit:1S Memory Limit:1000K Total Submit:198 Accepted:44 Description Z城市居住着很多只跳蚤。在Z城市周六生活频道有一个娱乐节目。一只跳蚤将被请上一个高空钢丝的正中央。钢丝很长,可以看作是无限长。节目主持人会给该跳蚤发一张卡片。卡片上写有N+1个自然数。其中最后一个是M,而前N个数都不超过M,卡片上允许

有相同的数字。跳蚤每次可以从卡片上任意选择一个自然数S,然后向左,或向右跳S个单位长度。而他最终的任务是跳到距离他左边一个单位长度的地方,并捡起位于那里的礼物。 比如当N=2,M=18时,持有卡片(10, 15, 18)的跳蚤,就可以完成任务:他可以先向左跳10个单位长度,然后再连向左跳3次,每次15个单位长度,最后再向右连跳3次,每次18个单位长度。而持有卡片(12, 15, 18)的跳蚤,则怎么也不可能跳到距他左边一个单位长度的地方。 当确定N和M后,显然一共有M^N张不同的卡片。现在的问题是,在这所有的卡片中,有多少张可以完成任务。 Input 两个整数N和M(N <= 15 , M <= 100000000)。 Output 可以完成任务的卡片数。 Sample Input

ACM题目整理

题目来源:福州大学acm网站 代码:fpcdq 一、入门 熟悉ACM竞赛规则以及程序提交注意事项 例题: Problem 1000 A+B Problem Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description Calculate a + b. Input The input will consist of a series of pairs of integers a and b,separated by a space, one pair of integers per line. Output For each pair of input integers a and b you should output the sum of a and b in one line,and with one line of output for each line in input. Sample Input 1 5 2 3 Sample Output 6 5

My answer: #include main() { long a,b; while((scanf("%ld%ld",&a,&b))!=EOF) { printf("%ld\n",a+b); } } 详情参考https://www.wendangku.net/doc/746734051.html,/faq.php 二、ACM分类 主流算法: 1.搜索//回溯 Problem 1019 猫捉老鼠 Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description 一只猫和一只老鼠在10*10的迷宫中。迷宫中的每个方格可以是空的,或者含有障碍。猫和老鼠可以进入任意一个空的方格中。当他们相遇时,猫和老鼠在同一个方格中。但是,无论猫或老鼠都不能进入有障碍的方格。我们可以用字符组成的二维数组表示迷宫,如下图所示。

Acm试题及答案

Acm试题及答案 1001 Sum Problem ............................................. 错误!未定义书签。1089 A+B for Input-Output Practice (I) ...................... 错误!未定义书签。1090 A+B for Input-Output Practice (II) ..................... 错误!未定义书签。1091 A+B for Input-Output Practice (III) .................... 错误!未定义书签。1092 A+B for Input-Output Practice (IV) ...................... 错误!未定义书签。1093 A+B for Input-Output Practice (V) ...................... 错误!未定义书签。1094 A+B for Input-Output Practice (VI) ..................... 错误!未定义书签。1095 A+B for Input-Output Practice (VII) ..................... 错误!未定义书签。1096 A+B for Input-Output Practice (VIII) ................... 错误!未定义书签。2000 ASCII码排序............................................ 错误!未定义书签。2001计算两点间的距离........................................ 错误!未定义书签。2002计算球体积.............................................. 错误!未定义书签。2003求绝对值................................................ 错误!未定义书签。2004成绩转换................................................ 错误!未定义书签。2005第几天.................................................. 错误!未定义书签。2006求奇数的乘积............................................ 错误!未定义书签。2007平方和与立方和.......................................... 错误!未定义书签。2008数值统计................................................ 错误!未定义书签。2009求数列的和.............................................. 错误!未定义书签。2010水仙花数................................................ 错误!未定义书签。2011多项式求和.............................................. 错误!未定义书签。2012素数判定................................................ 错误!未定义书签。2014青年歌手大奖赛_评委会打分............................... 错误!未定义书签。

ACM题目

【题目 1】N皇后问题(含八皇后问题的扩展,规则同八皇后):在N*N的棋盘上,放置N个皇后,要求每一横行 每一列,每一对角线上均只能放置一个皇后,问可能的方案及方案数。 【题目 2】排球队员站位问题 ┏━━━━━━━━┓图为排球场的平面图,其中一、二、三、四、五、六为位置编号,┃ ┃二、三、四号位置为前排,一、六、五号位为后排。某队比赛时,┃ ┃一、四号位放主攻手,二、五号位放二传手,三、六号位放副攻┠──┬──┬──┨手。队员所穿球衣分别为1,2,3,4,5,6号,但每个队 ┃ 四 │ 三 │ 二 ┃员的球衣都与他们的站位号不同。已知1号、6号队员不在后排,┠──┼──┼──┨2号、3号队员不是二传手,3号、4号队员不在同一排,5号、┃ 五 │ 六 │ 一 ┃6号队员不是副攻手。 ┗━━┷━━┷━━┛编程求每个队员的站位情况。 【算法分析】本题可用一般的穷举法得出答案。也可用回溯法。以下为回溯解法。 【题目 2】把自然数N分解为若干个自然数之和。 【参考答案】 n │ total 5 │ 7 6 │ 11 7 │ 15 10 │ 42 100 │ 190569291 【题目 3】把自然数N分解为若干个自然数之积。 【题目 4】马的遍历问题。在N*M的棋盘中,马只能走日字。马从位置(x,y)处出发,把棋盘的每一格都走一次,且只走一次。找出所有路径。 【参考程序】 {深度优先搜索法} 【题目 5】加法分式分解。如:1/2=1/4+1/4.找出所有方案。 输入:N MN为要分解的分数的分母 M为分解成多少项 【题目 6】地图着色问题 【题目 7】在n*n的正方形中放置长为2,宽为1的长条块,问放置方案如何 【题目 8】找迷宫的最短路径。(广度优先搜索算法)

整理出ACM所有题目及答案

1111111杭电: 1000 A + B Problem (4) 1001 Sum Problem (5) 1002 A + B Problem II (6) 1005 Number Sequence (8) 1008 Elevator (9) 1009 FatMouse' Trade (11) 1021 Fibonacci Again (13) 1089 A+B for Input-Output Practice (I) (14) 1090 A+B for Input-Output Practice (II) (15) 1091 A+B for Input-Output Practice (III) (16) 1092 A+B for Input-Output Practice (IV) (17) 1093 A+B for Input-Output Practice (V) (18) 1094 A+B for Input-Output Practice (VI) (20) 1095 A+B for Input-Output Practice (VII) (21) 1096 A+B for Input-Output Practice (VIII) (22) 1176 免费馅饼 (23) 1204 糖果大战 (25) 1213 How Many Tables (26) 2000 ASCII码排序 (32) 2001 计算两点间的距离 (34) 2002 计算球体积 (35) 2003 求绝对值 (36) 2004 成绩转换 (37) 2005 第几天? (38) 2006 求奇数的乘积 (40) 2007 平方和与立方和 (41) 2008 数值统计 (42) 2009 求数列的和 (43) 2010 水仙花数 (44) 2011 多项式求和 (46) 2012 素数判定 (47) 2014 青年歌手大奖赛_评委会打分 (49) 2015 偶数求和 (50) 2016 数据的交换输出 (52) 2017 字符串统计 (54) 2019 数列有序! (55) 2020 绝对值排序 (56) 2021 发工资咯:) (58) 2033 人见人爱A+B (59) 2037 今年暑假不AC (61) 2039 三角形 (63) 2040 亲和数 (64)

acm ZOJ刷题推荐

初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 1334 1337 1338 1350 1365 1382 1383 1394 1402 1405 1414 1494 1514 1622 1715 1730 1755 1760 1763 1796 1813 1879 1889 1904 1915 1949 2001 2022 2099 2104 2108 2172 2176 2201 2208 2321 2345 2351 2376 2388 2405 2417 2433 模拟问题: 1006 1009 1012 1016 1019 1023 1026 1028 1038 1042 1045 1051 1056 1057 1058 1061 1065 1066 1068 1072 1073 1078 1087 1088 1097 1098 1099 1103 1111 1121 1124 1126 1128 1133 1138 1146 1152 1154 1160 1175 1178 1187 1194 1207 1222 1224 1244 1259 1267 1274 1275 1277 1278 1279 1281 1282 1294 1295 1300 1308 1317 1324 1339 1351 1362 1392 1393 1397 1398 1399 1400 1402 1432 1434 1444 1452 1475 1487 1493 1497 1517 1526 1527 1530 1531 1552 1569 1573 1592 1601 1610 1623 1631 1641 1652 1657 1659 1682 1692 1700 1702 1707 1708 1712 1728 1732 1737 1746 1747 1750 1752 1754 1758 1764 1768 1774 1797 1799 1804 1807 1811 1822 1824 1831 1834 1837 1838 1842 1844 1845 1854 1858 1862 1870 1881 1884 1889 1896 1906 1921 1951 1969 1978 2000 2022 2040 2046 2047 2051 2072 2084 2101 2112 2131 2133 2138 2148 2153 2156 2160 2164 2172 2178 2184 2185 2187 2189 2193 2196 2201 2204 2208 2211 2212 2220 2229 2233 2239 2240 2261 2262 2269 2277 2288 2301 2309 2311 2312 2316 2320 2321 2322 2328 2330 2350 2389 2405 2410 2414 2420 2421 2483 2508 2560 2569 2572 2593 2613 2617 2680 2681 2731 2732 2743 动态规划:

部分ACM题目与答案

1001 Sum Problem (2) 1089 A+B for Input-Output Practice (I) (3) 1090 A+B for Input-Output Practice (II) (3) 1091 A+B for Input-Output Practice (III) (3) 1092 A+B for Input-Output Practice (IV) (3) 1093 A+B for Input-Output Practice (V) (3) 1094 A+B for Input-Output Practice (VI) (3) 1095 A+B for Input-Output Practice (VII) (3) 1096 A+B for Input-Output Practice (VIII) (3) 2000 ASCII码排序 (3) 2001计算两点间的距离 (3) 2002计算球体积 (3) 2003求绝对值 (3) 2004成绩转换 (3) 2005第几天? (3) 2006求奇数的乘积 (3) 2007平方和与立方和 (3) 2008数值统计 (3) 2009求数列的和 (3) 2010水仙花数 (3) 2011多项式求和 (3) 2012素数判定 (3) 2014青年歌手大奖赛_评委会打分 (3) 2015偶数求和 (3) 2016数据的交换输出 (3) 2017字符串统计 (3) 2019数列有序! (3) 2020绝对值排序 (3) 2021发工资咯:) (3) 2033人见人爱A+B (3) 2039三角形 (3) 2040亲和数 (3)

ACM部分练习题目答案

ACM部分习题答案: A + B Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 100972 Accepted Submission(s): 33404 Problem Description Calculate A + B. Input Each line will contain two integers A and B. Process to end of file. Output For each case, output A + B in one line. Sample Input 1 1 Sample Output 2 # include Int main() {int x,y,s; while(scanf("%d %d",&x,&y)!=EOF) {s=x+y; printf("%d\n",s);} return 0; } Sum Problem Time Limit: 1000/500 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 85964 Accepted Submission(s): 19422 Problem Description Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge). In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n. Input The input will consist of a series of integers n, one integer per line. Output For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer. Sample Input 1 100 Sample Output 1 5050 # include int main() {int n; long int s;

北大 poj acm题目推荐50题

-北大poj acm题目推荐50题 POJ == 北京大学ACM在线评测系统https://www.wendangku.net/doc/746734051.html,/JudgeOnline 1. 标记难和稍难的题目大家可以看看,思考一下,不做要求,当然有能力的同学可以直接切掉。 2. 标记为A and B 的题目是比较相似的题目,建议大家两个一起做,可以对比总结,且二者算作一个题目。 3. 列表中大约有70个题目。大家选做其中的50道,且每类题目有最低数量限制。 4. 这里不少题目在BUPT ACM FTP 上面都有代码,请大家合理利用资源。 5. 50个题目要求每个题目都要写总结,养成良好的习惯。 6. 这50道题的规定是我们的建议,如果大家有自己的想法请与我们Email 联系。 7. 建议使用C++ 的同学在POJ 上用G++ 提交。 8. 形成自己编写代码的风格,至少看上去美观,思路清晰(好的代码可以很清楚反映出解题思路)。 9. 这个列表的目的在于让大家对各个方面的算法有个了解,也许要求有些苛刻,教条,请大家谅解,这些是我们这些年的经验总结,所以也请 大家尊重我们的劳动成果。 10. 提交要求:一个总文件夹名为bupt0xx (即你的比赛帐号), 这个文件夹内有各个题目类别的子目录(文件夹),将相应的解题报告放入对应 类别的文件夹。在本学期期末,小学期开始前,将该文件夹的压缩包发至buptacm@https://www.wendangku.net/doc/746734051.html,。 对于每个题目只要求一个POJxxxx.cpp 或POJxxxx.java (xxxx表示POJ该题题号) 的文件,注意不要加入整个project 。 11. 如果有同学很早做完了要求的题目,请尽快和我们联系,我们将指导下一步的训练。 下面是一个解题报告的范例: 例如:POJ1000.cpp

acm题库[大全]

acm题库[大全] 座位调整 题目描述: 百度办公区里到处摆放着各种各样的零食。百度人力资源部的调研发现,员工如果可以在自己喜欢的美食旁边工作,工作效率会大大提高。因此,百度决定进行一次员工座位的大调整。 调整的方法如下: 1 ( 首先将办公区按照各种零食的摆放分成 N 个不同的区域。(例如:可乐区,饼干区,牛奶区等等)。 2 ( 每个员工对不同的零食区域有不同的喜好程度(喜好程度度的范围为 1 —100 的整数,喜好程度越大表示该员工越希望被调整到相应的零食区域)。 3 ( 由于每个零食区域可以容纳的员工数量有限,人力资源部希望找到一个最优的调整方案令到总的喜好程度最大。 数据输入: 第一行包含两个整数 N , M ,( 1<=N , M<=300 )。分别表示 N 个区域和M 个员工。 第二行是 N 个整数构成的数列 a ,其中 a[i] 表示第 i 个区域可以容纳的员工数, (1<=a[i]<=M , a[1]+a[2]+..+a[N]=M) 。 紧接着是一个 M*N 的矩阵 P , P ( i , j )表示第 i 个员工对第 j 个区域的喜好度。 答案输出: 对于每个测试数据,输出可以达到的最大的喜好程度。 3 3

1 1 1 100 50 25 100 50 25 100 50 25 输出样例 175 3 10 2 4 4 100 50 25 100 50 25 100 50 25 100 50 25 100 50 25 100 50 25 100 50 25 100 50 25 100 50 25 100 50 25 2006 年百度之星程序设计大赛初赛题目 4 2007-05-14 17:39 剪刀石头布 N 个小孩正在和你玩一种剪刀石头布游戏。 N 个小孩中有一个是裁判,其余小孩分成三组(不排除某些组没有任何成员的可能性),但是你不知道谁是裁判,也不知道小孩们的分组情况。然后,小孩们开始玩剪刀石头布游戏,一共玩 M 次,

淅大acm题性分类

浙江大学(ZJU):https://www.wendangku.net/doc/746734051.html,/ DP: 1011 NTA 简单题 1013 Great Equipment 简单题 1024 Calendar Game 简单题 1027 Human Gene Functions 简单题 1037 Gridland 简单题 1052 Algernon\'\'s Noxious Emissions 简单题 1409 Communication System 简单题,但是很容易看错~~~ 1425 Crossed Matchings 简单题 1438 Asteroids! 简单题 1459 String Distance and Transform Process 简单题 1462 Team Them Up! 简单题 1556 Heroes Of Might And Magic 简单题,不过背景蛮有意思的…… 1520 Duty Free Shop 简单题 1524 Supermarket 简单题 1301 The New Villa 简单题 1303 Jury Compromise 其实不是很难,但是很容易错,555…… 1345 Best Deal 简单题,但是也很容易错……555…… 1360 Radar Installation 简单题 1396 The Umbrella Problem: 2054 简单题 1058 Currency Exchange 简单题 1076 Gene Assembly 简单题 1092 Arbitrage 简单题 1093 Monkey and Banana 简单题 1094 Matrix Chain Multiplication 简单题 1536 Labyrinth 简单题 1100 Mondriaan\'\'s Dream 简单题,DP可以过,不过据说有复杂的组合公式1103 Hike on a Graph 简单题 1134 Strategic Game 简单题 1147 Formatting Text 简单题 1148 The Game 简单题 1161 Gone Fishing 简单题 1180 Self Numbers 简单题 1192 It\'\'s not a Bug, It\'\'s a Feature! 简单题 1196 Fast Food 简单题 1107 FatMouse and Cheese 简单题,不过题目描述有些混乱 1136 Multiple 简单题,BFS 1276 Optimal Array Multiplication Sequence 简单题 1255 The Path 简单题 1250 Always On the Run 简单题 1213 Lumber Cutting 简单题 1206 Win the Bonus 简单题

2014ACM大赛题目

题目描述 恶魔猎手尤迫安野心勃勃.他背叛了暗夜精灵,率深藏在海底的那加企图叛变:守望者在与尤迪安的交锋中遭遇了围杀.被困在一个荒芜的大岛上。为了杀死守望者,尤迪安开始对这个荒岛施咒,这座岛很快就会沉下去,到那时,刀上的所有人都会遇难:守望者的跑步速度,为17m/s,以这样的速度是无法逃离荒岛的。庆幸的是守望者拥有闪烁法术,可在1s内移动60m,不过每次使用闪烁法术都会消耗魔法值10点。守望者的魔法值恢复的速度为4点/s,只有处在原地休息状态时才能恢复。 现在已知守望者的魔法初值M,他所在的初始位置与岛的出口之间的距离S,岛沉没的时间T。你的任务是写一个程序帮助守望者计算如何在最短的时间内逃离荒岛,若不能逃出,则输出守望者在剩下的时间内能走的最远距离。注意:守望者跑步、闪烁或休息活动均以秒(s)为单位。且每次活动的持续时间为整数秒。距离的单位为米(m)。 输入 输入文件escape.in仅一行,包括空格隔开的三个非负整数M,S,T。 输出 输出文件escape.out包含两行: 第1行为字符串"Yes"或"No" (区分大小写),即守望者是否能逃离荒岛。 第2行包含一个整数,第一行为"Yes" (区分大小写)时表示守望着逃离荒岛的最短时间 第一行为"No" (区分大小写) 时表示守望者能走的最远距离。 样例输入 39 200 4 样例输出 No 197 提示 7 180 9 Yes 30%的数据满足: 1 <= T<= 10,1 <=S<= 100 50%的数据满足: 1 <= T <= 1000,1 <= S <= 10000

100%的数据满足: 1 <= T <= 300000,0 <= M<=1000 1 <=S <= 10^8 题目描述 A group of friends has just completed their CS assignments, and because of the nice weather, they decide to go to Joe's house for a BBQ. Unfortunately, after all that coding, they are too tired to walk. Fortunately, between them they have enough cars to take everyone. Joe remembers that he needs to stop off at the supermarket along the way to buy some burgers and pop. Jenn proposes that they stop at her house to get a frisbee. Jim decides that he doesn't like burgers, and wants to grab a pizza along the way. After having spent so long in the computer lab, Jerry's eyes have become very sensitive to sunlight, so he needs to stop at his house for his sunglasses. And so it goes: each person needs to run a little errand along the way. At this rate, the friends worry that it will be dark by the time they get to Joe's house. They launch into a heated discussion to about who should go in which car to minimize the time needed for everyone to reach Joe's house. The discussion itself, of course, wastes precious time that could be better spent at the BBQ. To help the group, you will write a program to settle the discussion by computing an optimal assignment of people to cars. The overall travel time is the maximum of the

(整理)ACM大量习题题库及建议培养计划.

//别人总结的,确实很多,但有信心就能学完! 一.基本算法: (1)枚举.(poj1753,poj2965) (2)贪心.(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. (5)构造法.(poj3295) (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996) 二.图算法: (1)图的深度优先遍历和广度优先遍历. (2)最短路径算法.(dijkstra,bellman-ford,floyd,heap+dijkstra) (poj1860,poj3259,poj1062,poj2253,poj1125,poj2240) (3)最小生成树算法.(prim,kruskal) (poj1789,poj2485,poj1258,poj3026) (4)拓扑排序.(poj1094) (5)二分图的最大匹配(匈牙利算法).(poj3041,poj3020) (6)最大流的增广路算法(KM算法).(poj1459,poj3436) 三.数据结构. (1)串.(poj1035,poj3080,poj1936) (2)排序(快排、归并排(与逆序数有关)、堆排).(poj2388,poj2299) (3)简单并查集的应用. (4)哈希表和二分查找等高效查找法.(数的Hash,串的Hash) (poj3349,poj3274,POJ2151,poj1840,poj2002,poj2503) (5)哈夫曼树.(poj3253) (6)堆. (7)trie树(静态建树、动态建树).(poj2513) 四.简单搜索 (1)深度优先搜索.(poj2488,poj3083,poj3009,poj1321,poj2251) (2)广度优先搜索.(poj3278,poj1426,poj3126,poj3087.poj3414) (3)简单搜索技巧和剪枝.(poj2531,poj1416,poj2676,1129) 五.动态规划 (1)背包问题. (poj1837,poj1276) (2)型如下表的简单DP(可参考lrj的书page149): 1.E[j]=opt{D+w(i,j)} (poj3267,poj1836,poj1260,poj2533) 2.E[i,j]=opt{D[i-1,j]+xi,D[i,j-1]+yj,D[i-1][j-1]+zij} (最长公共子序列) (poj3176,poj1080,poj1159) 3.C[i,j]=w[i,j]+opt{C[i,k-1]+C[k,j]}.(最优二分检索树问题) 六.数学 (1)组合数学: 1.加法原理和乘法原理. 2.排列组合. 3.递推关系. (POJ3252,poj1850,poj1019,poj1942) (2)数论.

ACM必做50题——高精度

1 POJ 1001 Exponentiation 高精度数的计算,以前在网上看到过一个计算大数阶乘比如10000000!的算法,总体思想就是将结果用数组保存起来,然后将结果的每一位与乘数相乘,当然还有进位... 有了这个算法的思想,这个题思路就可以是:先将输入的小数转换成一个整数,当然这个整数肯定能够用int类型的变量保存,比如1.2345, 通过函数removeDot()将它转化成12345,然后利用大数阶乘的思想计算12345*12345.....*12345, 最后的就是输出了,这个要考虑的情况比较多,因为这个也W A了5次才AC(笨的要死), 情况虽多,但不难. 这道题是高精度计算的,不算很难,但是很繁琐,尤其是对输入输出的要求。被这道题搞了好久,耐心来,一点一点调试,总会成功的。 #include #include #include using namespace std; char ans[10]; char res[2][205]; __int64 ps;//有几位小数点 int len;//长度,R的有效长度 //计算c = b * a void Multiply(char * b,int bt,char * a,int at,char * c) { int i,j; int up=0; for(i=0;i=10) { up=t/10; t=t%10; c[i+j]=t+48; if(j==(bt-1) )

部分ACM题目与答案解析

1001 Sum Problem (3) 1089 A+B for Input-Output Practice (I) (6) 1090 A+B for Input-Output Practice (II) (9) 1091 A+B for Input-Output Practice (III) (13) 1092 A+B for Input-Output Practice (IV) (15) 1093 A+B for Input-Output Practice (V) (19) 1094 A+B for Input-Output Practice (VI) (22) 1095 A+B for Input-Output Practice (VII) (24) 1096 A+B for Input-Output Practice (VIII) (27) 2000 ASCII码排序 (30) 2001计算两点间的距离 (33) 2002计算球体积 (35) 2003求绝对值 (38) 2004成绩转换 (40) 2005第几天? (43) 2006求奇数的乘积 (47) 2007平方和与立方和 (49) 2008数值统计 (52) 2009求数列的和 (55) 2010水仙花数 (57) 2011多项式求和 (61)

2012素数判定 (64) 2014青年歌手大奖赛_评委会打分 (67) 2015偶数求和 (70) 2016数据的交换输出 (74) 2017字符串统计 (78) 2019数列有序! (80) 2020绝对值排序 (84) 2021发工资咯:) (87) 2033人见人爱A+B (90) 2039三角形 (94) 2040亲和数 (96)

整理出ACM所有题目及答案

1000 A + B Problem Problem Description Calculate A + B. Input Each line will contain two integers A and B. Process to end of file. Output For each case, output A + B in one line. Sample Input 1 1 Sample Output 2 Author HDOJ 代码: #include int main() { int a,b; while(scanf("%d %d",&a,&b)!=EOF) printf("%d\n",a+b); } 1001 Sum Problem Problem Description Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge). In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.

Input The input will consist of a series of integers n, one integer per line. Output For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer. Sample Input 1 100 Sample Output 1 5050 Author DOOM III 解答: #include main() { int n,i,sum; sum=0; while((scanf("%d",&n)!=-1)) { sum=0; for(i=0;i<=n;i++) sum+=i; printf("%d\n\n",sum); } }

acm 大赛 英语版 题目

////////////////////////////////////////////// The Mailboxes Manufacturers Problem Description: In the good old days when Swedish children were still allowed to blowup their fingers with fire-crackers, gangs of excited kids would plague certain smaller cities during Easter time, with only one thing in mind: To blow things up. Small boxes were easy to blow up, and thus mailboxes became a popular target. Now, a small mailbox manufacturer is interested in how many fire-crackers his new mailbox prototype can withstand without exploding and has hired you to help him. He will provide you with k(1 ≤ k≤ 10) identical mailbox prototypes each fitting up to m(1 ≤ m≤ 100) crackers. However, he is not sure of how many firecrackers he needs to provide you with in order for you to be able to solve his problem, so he asks you. You think for a while an d then say, “Well,if I blow up a mailbox I can’t use it again, so if you would provide me with only k = 1 mailboxes, I would have to start testing with 1 cracker, then 2 crackers, and so on until it finally exploded. In the worst case, that is if it does n ot blow up even when filled with m crackers, I would need 1 + 2 + 3 + … + m = m ×(m+ 1) ? 2 crackers. If m = 100 that would mean more than 5000 fire-crackers!” “That’s too many,” he replies. “What if I give you more than k = 1 mailboxes? Can you find a strategy that requires less crackers?” Can you? And what is the minimum number of crackers that you should ask him to provide you with? You may assume the following: 1.If a mailbox can withstand x fire-crackers, it can also withstand x? 1 fire-crackers. 2.Upon an explosion, a mailbox is either totally destroyed (blown up) or unharmed, which means that it can be reused in another test explosion.

相关文档