| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5135 人关注过本帖
标题:ACM题集(即时更新)
取消只看楼主 加入收藏
PcrazyC
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:5652
专家分:0
注 册:2006-10-20
结帖率:100%
收藏
 问题点数:0 回复次数:11 
ACM题集(即时更新)

有些题目答案我没保存,所以就没有写了,以后我做出来的都保存下来帖到这里面,先不要看答案(答案都已通过),做出来一题,将答案和标号附上,我给你去验证是否正确


NO.: 1001

Phone Numbers

Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 848 Accepted: 204

Description

There are lots of phone numbers in stone’s address book, all of them are formatted differently in several kinds, but the general format of them is like below:

[Name] [Phone Number]

Where name and Phone Number are NULL ended strings no longer than 20 characters. What’s more, there can’t be any other characters except 1~9 and dash (‘-’) in the Phone Number string. But there are several formats of the phone numbers such as:

Stone 027-88888888

Wendy 0795-0000888

Cathy 135--8475-5581

etc.

Between any two digits of a Phone Number there can be one or more dashes (‘-’).

You are supposed to help stone to make the phone numbers into the same format which has no dash in the Phone Number string.

Input

There are several but no more than 100 cases in the input file, and exactly two strings separated with exactly one space in each line.

Output

You are supposed to print the formatted Name and Phone Numbers (with no dash in it) strings line by line, and separate the Name and Phone Number strings with exactly one space.
Sample Input

Stone 027-88888888
Wendy 0795-0000888
Cathy 135--8475-5581

Sample Output

Stone 02788888888
Wendy 07950000888
Cathy 13584755581



answer:

#include<stdio.h>
void main()
{
int a,b;
scanf("%d%d",&a,&b);
printf("%d",a+b);
}


#include<stdio.h>
#include<string.h>
int main()
{
char number[21],name[21];
int i,n;
while(EOF!=scanf("%s%s",name,number))
{
n=strlen(number);
for(i=0;i<n;i++)
{
if((number[i]<'0'||number[i]>'9')&&number[i]!='-')
{
return 0;
}
}

if(n<21)
{
printf("%s ",name);
for(i=0;i<n;i++)
if(number[i]!='-')
printf("%c",number[i]);
printf("\n");
}
else
return 0;
}
return(1);
}



N0: 1002

Inver-Over for TSP

Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 432 Accepted: 130

Description

The Traveling Salesman Problem (TSP) is one of the most widely studied NP-hard combinatorial optimization problems. Its statement is deceptively simple: Let G = (V, E) be a graph where V is a set of vertices and E is a set of edges. Let C = (cij) be a distance (or cost) matrix associated with E. The TSP requires determination of a minimum distance circuit (Hamiltonian circuit or cycle) passing through each vertex once and only once.

A lot of algorithms have been proposed to solve TSP. Some of them (based on dynamic programming or branch and bound methods) provide the global optimum solution (the largest nontrivial instance of the TSP solved to optimality is of 7397 cities, however, it required almost 4 years of CPU time on network of machines). Other algorithms are heuristic ones, which are much faster, but they do not guarantee the optimal solutions.

One of the heuristic algorithms is GuoTao algorithm. The most important operation in GuoTao algorithm is Inver-Over

Let N be the number of the vertexes and a sequence of number 0~N-1 such as: {423105 , N=6} be an approximate optimal solution. (the circuit is 4→2→3→1→0→5→4)

Inver over operator is supposed to improve this solution by rearrange the sequence by inverse the order of vertexes between (inclusive) the given index Pi and Pj (0≤Pi,Pj<N, Pi≠Pj). For example if the current circuit is {423105, N=6} and Pi = 1, Pj = 4, after the Inver-Over operator the sequence is supposed to be: {401325, N=6}, the order of vertexes {2310} was inversed.

Always remember that the sequence is indicating a cycle. So maybe Pj is smaller than Pi.

Input

There are several cases in the input file. In each case, there are 3 integers in the first line: number of vertexes N (0≤N≤100), the start and end position for the Inver-Over operation Pi and Pj. In the second line there are N integers Ci (0≤Ci<100), indicating an approximate optimal solution. N=0 indicating the end of input.
Output

For each test case you are supposed to print the sequence after the Inver-Over operator. Each sequence in one line, and separate the index numbers with exactly one space.
Sample Input

6 1 4
4 2 3 1 0 5
6 4 1
4 2 3 1 0 5
0

Sample Output

4 0 1 3 2 5
5 0 3 1 2 4


N0: 1004

Relatively prime Problem

Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 555 Accepted: 150

Description

Now , BusyCai is still busy with the "World's hardest" problem his professor left him 3 days ago , and the problem is too hard for BusyCai to get the right answer , so he turns to your help .
The problem is: give you a positive integer N , you have to calculate how many positive integers less than N are relatively prime to N.
Two integers a and b are relatively prime if there are no integers x>1 , y>0 , z>0 such that a=x*y and b=x*z .
Input

There are several test cases . For each test case , standard input contains a line with N <= 1000,000,000 . A line containing 0 follows the last case .
Output

The output is very simple , for each test case , there should be a single line of output answering the question posed above.
Sample Input

7
12
0

Sample Output

6
4



NO: 1005

Kasperkey

Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 126 Accepted: 60

Description

In computers, a virus is a program or programming code that replicates by being copied or initiating its copying to another program, computer boot sector or document. Viruses can be transmitted as attachments to an e-mail note or in a downloaded file, or be present on a diskette or CD. The immediate source of the e-mail note, downloaded file, or diskette you've received is usually unaware that it contains a virus. Some viruses wreak their effect as soon as their code is executed; other viruses lie dormant until circumstances cause their code to be executed by the computer. Some viruses are benign or playful in intent and effect ("Happy Birthday, asky007!") and some can be quite harmful, erasing data or causing your hard disk to require reformatting. A virus that replicates itself by resending itself as an e-mail attachment or as part of a network message is known as a worm.

To protect their system from virus, people usually install Anti-Virus softwares.This is a big problem to asky007. He likes Kaspersky Anti-Virus ,but it costs too mush computer resource. Unfortunately, asky007's CPU is PIII 433, and it is impossible to run Kaspersky. So , asky007 wants to develop a Anti-Virus software, he calls it Kasperkey.

When asky007 tests Kasperkey, he finds a new problem. Some viruses use a technical name 'olymorphic code' to let AV can't find them. Viruses can be change their code in different times.For example , a virus'code is 'asky007' now and may be '007asky' an hour later.Thank Godness! Asky007 finds a rule. He captures the virus two times, and marks the shadinesses.For example , it is :

ID Shadiness


The First Time The Second Time

1 1 111

2 10111 10

3 10 0

The rule is if you make a sequence use the ID, the shadiness of two times may be same.Just like '2113'. The first time 's Shadiness become '101111110', so do the second time. Now, you can say it is a virus. If can's find a such sequence or the shadiness's length is bigger than 100, you can suppose it can't be a virus.

Input

The first line of the input file contains the number N , the number of IDs, then followed by 2N lines.The first N lines mean the first time's shadiness, and then the second.Process to the end of file.
Output

If it exists some sequence descripted above, output the shortest ID sequence; otherwise output “It is not a virus.” In one line.
Sample Input

3
1
10111
10
111
10
0
3
10
10111
1
111
10
0

Sample Output

2113
It is not a virus.


NO: 1006

JurassicXC's number

Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 328 Accepted: 110

Description

Do you love the number ‘8’? Many people make it their lucky number, so does JurassicXC in the Jurassic . And JurassicXC named the positive integer include at least one ‘8’ “JurassicXC’s number” . Such as 8, 208, 812134353.

It’s easy to judge whether a number is JurassicXC’s number or not, isn’t it. But JurassicXC want to know how many JurassicXC’s numbers are not bigger than the given number N. Can you help lazy JurassicXC to count it ?

Input

There are several test cases . In each test case there are a single none positive integer N ( N<2^31 ) in a single line . The number ‘0’ mean the end of input .
Output

For each N, output the number of JurassicXC’s number, which is not bigger than the given number N in a single line . The last integer ‘0’ will not be processed
Sample Input

2
8
90
0
Sample Output

0
1
18


NO: 1007

Calendar

Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 428 Accepted: 112

Description

A calendar is a system for measuring time, from hours and minutes, to months and days, and finally to
years and centuries. The terms of hour, day, month, year and century are all units of time measurements
of a calender system.
According to the Gregorian calendar, which is the civil calendar in use today, years evenly divisible by 4
are leap years, with the exception of centurial years that are not evenly divisible by 400. Therefore, the
years 1700, 1800, 1900 and 2100 are not leap years, but 1600, 2000, and 2400 are leap years.
Given the number of days that have elapsed since January 1, 2000 A.D, your mission is to find the date
and the day of the week.
Input

The input consists of lines each containing a positive integer, which is the number of days that have
elapsed since January 1, 2000 A.D. The last line contains an integer −1, which should not be processed.
You may assume that the resulting date won’t be after the year 9999.
Output

For each test case, output one line containing the date and the day of the week in the format of
“YYYY-MM-DD DayOfWeek”, where “DayOfWeek” must be one of “Sunday”, “Monday”, “Tuesday”,
“Wednesday”, “Thursday”, “Friday” and “Saturday”.
Sample Input

1730
1740
1750
1751
-1
Sample Output

2004-09-26 Sunday
2004-10-06 Wednesday
2004-10-16 Saturday
2004-10-17 Sunday



NO: 1008

Fibonacci Number

Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 324 Accepted: 157

Description

The Fibonacci Numbers {0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55…} are defined by the recurrence:
F0 = 0
F1 = 1
Fi = Fi-1 + Fi-2 for all i >1
Write a program to calculate the Fibonacci Numbers.

Input

The first line of the input file contains a single integer T, the number of test cases. The following T lines each contains an integer n ( 0 ≤n≤ 45 ), and you are expected to calculate Fn.
Output

Output Fn on a separate line.
Sample Input

5
0
3
5
9
20

Sample Output

0
2
5
34
6765




N0:1171


Easy problem 2 --- 求 n!

Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 10 Accepted: 10

Description

给定一个n( 1 <= n <= 12 ),求n 的阶乘.

Input

每行一个 n .当 n = 0 时文件结束。
Output

每行一个整数 n!.
Sample Input

4

Sample Output

24

answer:

#include<stdio.h>

long fun(int n)
{
int f;
if(n==1)
f=1;
else
f=n*fun(n-1);
return f;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF&&n)
{
printf("%ld\n",fun(n));
}
return 1;
}


[此贴子已经被作者于2007-3-31 20:57:31编辑过]

搜索更多相关主题的帖子: ACM Limit Phone numbers Numbers 
2007-03-31 20:55
PcrazyC
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:5652
专家分:0
注 册:2006-10-20
收藏
得分:0 
以下是引用nuciewth在2007-3-31 21:27:43的发言:
LZ 还不如放为每期的题目,但最好答案不要先给出来.

第2个写成递归不太划算,特别是在比赛的时候.

多谢提醒

的确如此,递归很费时,一般程序有时间限制,一般是1S

我又有一个程序就是用递归通不过,改成FOR就可以通过了


雁无留踪之意,水无取影之心
2007-03-31 21:57
PcrazyC
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:5652
专家分:0
注 册:2006-10-20
收藏
得分:0 
以下是引用mp3aaa在2007-3-31 21:29:47的发言:
希望以后能多发点中文的题

我现在都不习惯做中文的了,喜欢做英语的


雁无留踪之意,水无取影之心
2007-03-31 21:59
PcrazyC
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:5652
专家分:0
注 册:2006-10-20
收藏
得分:0 

来了没,王永亮

[此贴子已经被作者于2007-4-15 13:38:23编辑过]


雁无留踪之意,水无取影之心
2007-03-31 22:11
PcrazyC
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:5652
专家分:0
注 册:2006-10-20
收藏
得分:0 

Contest Problem E : The gamblers

Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 67 Accepted: 16

Description

There are N gamblers,one day,they want to find the person who is the best.Each time,three of them have a match,and two of them lose the game.Sometimes two of them have a match may needed.There are a lot of gamblers,so they want the match as fewer as possible.Give the number of N,can you tell the number of matches.

Input

The input contains several test cases. Each case is specified by one positive integer n (0 < n <= 1000000000), indicating the number of players.

Output

For each test case, output a single line with the least number of matches.

Sample Input

3
4
5
Sample Output

1
2
2


第二题:

Contest Problem D : Mine again

Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 17 Accepted: 6

Description

Typhoon likes playing a game named "Mine Sweeper". Have you ever played it ?
The game Minesweeper is played on an n by n grid. In this grid are hidden m mines, each at a distinct grid location. The player repeatedly touches grid positions. If a position with a mine is touched, the mine explodes and the player loses. If a position not containing a mine is touched, an integer between 0 and 8 appears denoting the number of adjacent or diagonally adjacent grid positions that contain a mine.
//这个地方是一个扫雷的图,复制不上来,知道是扫雷就可以了

Now , giving you the position of the mines , your task is to print the number of all grids.


Input

The first line of input contains a single positive integer n <= 100. The next n lines represent the positions of the mines. Each line represents the contents of a row using n characters: "*" indicates a mined position while "." indicates a position with no mine .

Input contains multiple test cases. Process to the end of file.
Output

Your output should represent the board.Grids that do not contain a mine should contain an integer between 0 and 8 , else print "*".

Separate output for subsequent test cases with a single blank line.

Sample Input

8
...**..*
......*.
***.*...
*.*.....
***.....
.....*..
...**.*.
.....*..
Sample Output

001**22*
233433*2
***3*211
*8*41100
***21110
23333*21
001**4*1
00123*21

第三题:

Contest Problem C : Joseph's problem

Time Limit: 5000 MS Memory Limit: 65536 K
Total Submit: 20 Accepted: 14

Description


The Joseph's problem is well known for us.There are N person stand in a circle,and the Mth person has to leave.Assume that we always start from the person 1,and give the number N and M,can you tell me who is the person that the last to leave.
Input

Input contains multiple test cases. For each test case,there is one line containing two integers N and M (1000>=N>M>1), where N represents the number of person and M means that every Mth is going to leave.

Output

For each test case, output a single line with the number of the person last to leave.

Sample Input

5 3
Sample Output

4

第四题:

Contest Problem B : How fast can I drive

Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 24 Accepted: 4

Description

There are N city and M roads connect them,and each road is bidirectional with a number stand
the fastest speed you can drive.I want to go from city 0 to city N-1(1<=N<1000),if the car have to drive in a changeless speed,can you tell me the fastest speed I can drive.

Input

Input contains multiple test cases. For each test case,there is one line containing two integers N and M , where N represents the number of city and M represents the number of road.Then M lines follows,each line contain three integers A,B,Speed.It means the fastest speed between A and B is Speed.

Output

For each test case, output a single line with fastest speed .If you can't find a path from 0 to N-1,just output -1 in s single line.

Sample Input

3 3
1 2 5
2 3 5
1 3 4
4 4
1 2 8
2 3 5
2 4 7
3 4 7

Sample Output

5
7

第五题:

Contest Problem F : The problem with Tom

Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 7 Accepted: 3

Description

One day,Tom's teacher give him a problem,give a number N(1<=N<=1000),it can be writen as a sum of some of positive integer.As N=s1+s2+s3+….But si must be the power of 2.Then Tom has to tell how many way are there can from N.If two sequences have the same number but different order,they consider as one.Tom is poor in math,so as his best friend,slove this problem for him.
Input

Input consists of multiple test cases. Eath case contain a number N which described as before.

Output

For eath number,output a number stand the number of different kinds of string.

Sample Input

2
5
Sample Output

2
4


第六题:

Contest Problem G : The problem with TomⅡ

Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 6 Accepted: 2

Description

Another day,Tom's teacher give him one more problem,use three letter 't','h','e' to form a string with length of N.But 't' will not appear in adjacent position.Then the problem is to find the number of different kind of the string.Tom is poor in math,so as his best friend,slove this problem for him.
Input

Input consists of multiple test cases. Eath case contain a number N (1<=N<1000) stands the length of the string.
Output

For eath number,output a number stand the number of different kinds of string.

Sample Input

1
2
Sample Output

3
8
Hint

The number of output maybe so large that can exceed the range of long or double.

第七题:

Contest Problem H : Who is the best

Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 18 Accepted: 2

Description

In every examnation,we all get a score given by our teacher,and we can say that the one who gets the highest score is the best.However,we can redefine another rule:there are n students, given the score array s[n]: s1,s2,s3...sn ,based on the ith num,we redefine the ith student's score by T[i]=|S1-Si|+|S2-Si|+…|Sn-Si|,so we can get another array T[n],you just need to output the highest result T[i].

Input

There are multiple test cases.In every case , there are a line with a integer n(1<=n<=100000000) representing the number of the students, the second line contains n integers representing the scores of the students.

Output

Output a line with the highest result.
Sample Input

3
1 2 3
Sample Output

3

第八题:

Contest Problem I : Help July

Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 11 Accepted: 7

Description

July 特别喜欢吃苹果。一天他的朋友 fwish 送给他N个苹果,每个苹果的颜色都各有特色。
他马上想把这些苹果马上吃光,但是......
fwish 知道July 很聪明,所以这次她想难为一下July。她要July把这N个苹果通过她的规则归并成一堆,
要是能做到的话,就让他马上吃苹果。
July只好答应了。
fwish的规则如下:

1.所有苹果都已经标好号,按顺序排好,每个苹果都有个值。
2.每次只能合并相邻的两堆。
3.开始的时候每堆只有一个苹果。
4.合并得到新堆的值为合并之前两堆的值之和,该次合并的代价为新堆的值。
5.最后将所有苹果合并成一堆.
6.合并的总代价为每次合并的代价累加之和。

fwish 要求July 计算出总代价的最小值。 July想了半天也没想到一种方法来解决这个问题。
July 知道你是一个数学和计算编程机高手,于是他请求你帮助他,
因为 fwish 的规则没有说不能请别人帮忙。

Input

有多组数据,以 N = 0 结束。
每个CASE:
第一行包含一个数N(1<=N<=100),代表 苹果的个数 。
第二行有N个数,表示这N个苹果的值。
Output

每个CASE包含一行,输出N个苹果合并成一堆的最小得分。
Sample Input

4
13 7 8 16
Sample Output

87

第九题:

Contest Problem J : Money and Happy to BJF

Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 14 Accepted: 2

Description

BJF 是一个建筑工地的工头,他现在遇到了一个问题需要他的工作秘书 你设计一个程序来解决他的问题。
问题是这样的:
现在 BJF 有一个工程学要做N个月,第i个月需要至少a[i]个工人。由于每个需要工人数不一样,所以他可以做合理安排(每个月辞退或雇佣一些工人,以便保证工程的正常进行),每个工人 每月工资为S,辞退一个工人要额外支付 F, 雇佣一个工人要额外支付 H;BJF希望完成工程花费 越少越好,并且在不影响花费的前提下最后剩下的工人越多越好(这样BJF最Happy )。
Input

包含多个CASE, 以 N = 0 结束。
每个CASE包含三行:
第一行一个N ( 1<= N <= 50 )代表 工程要N个月才能完成。第二行有三个数 H, S, F( 0 <= H, S, F <= 15; 第三行包含N个数 { a[1], a[2], ...,a[i], ..., a[n]; 0 <= a[i] <= 510 }
a[i]( 1 <= i <= N )代表第i个月至少要a[i]个工人。
Output

每个CASE 包含一行:最小花费和在最小花费前提下,剩下的最大工人数。以一个空格分开
Sample Input

2
1 1 1
1 1
Sample Output

3 1

第十题:

Contest Problem A : A math problem

Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 46 Accepted: 1

Description

There are two sequeues of integer,can you tell me whether you can get the second from the first one through the operation as follows:
For S[i-1],S[i],S[i+1],you can get S[i-1]+s[i],s[i]-2*s[i],s[i+1]+s[i].
For example:
3 5 6 7
8 6 -11 18

Then ,from 3 5 6 7, we can get 8 -5 11 7 through the first operation on( 3 5 6 ),then we can get 8 6 -11 18 through the second one on ( -5 11 7 ),so the answer is YES;
Input

Input contains multiple test cases.For each test case,there is one line containing one integers N(3<=N<1000),
where N represents the number of integers of the sequence.Then two lines follows,each line with N integers,respectively.

Output

For each test case,if you can get the second sequence from the first one,output YES, or ouput NO.

Sample Input

4
3 5 6 7
8 6 -11 18
Sample Output

YES


雁无留踪之意,水无取影之心
2007-04-15 17:25
PcrazyC
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:5652
专家分:0
注 册:2006-10-20
收藏
得分:0 
以下是引用w5560在2007-4-16 16:49:05的发言:
给我传点中文的题目呗,刚刚学,做英文的有点不顺手,先试试中文的

好吧,我过几天去机房搞几个中文的来


雁无留踪之意,水无取影之心
2007-04-16 21:21
PcrazyC
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:5652
专家分:0
注 册:2006-10-20
收藏
得分:0 

在大家的要求下我找了几个中文的题,其中有些比较简单,难的也有,大家做了在这上面发答案,我给大家去提交

第一题:

防御导弹

Time Limit:1000MS Memory Limit:1000K
Total Submit:93 Accepted:28

Description

某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统。但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够达到任意的高度,但是以后每一发炮弹都不能高于前一发的高度。某天,雷达捕捉到敌国的导弹来袭。由于该系统还在使用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹。

Input

最多20个整数,分别表示导弹依次飞来的高度(雷达给出高度数据是不大于30000的正整数)

Output

两个整数M和N。表示:这套系统最多能拦截 M 枚导弹,如果要拦截所有导弹最少要配备 N 套这种导弹系统。


Sample Input


300 250 275 252 200 138 245


Sample Output


5 2


第二题:

母牛生小牛

Time Limit:1000MS Memory Limit:1000K
Total Submit:425 Accepted:135

Description

设有一头小母牛,从出生第四年起每年生一头小母牛,按此规律,第N年时有几头母牛?


Input

本题有多组数据。每组数据只有一个整数N,独占一行。(1≤N≤50)


Output

对每组数据,输出一个整数(独占一行)表示第N年时母牛的数量

Sample Input


1
4
5
20


Sample Output


1
2
3
872

第三题:

扬辉三角

Time Limit:1000MS Memory Limit:65536K
Total Submit:461 Accepted:116

Description

输出扬辉三角


Input

本题有测试数据,每组数据仅含一个整数N(N不大于34)。一组数据独占一行。


Output

对于每一组数据,先输出一个

Case #:
。其中#号代表第#组数据。接下来输出一个由数字组成的扬辉三角。一行中的数字之间用一个空格分开。行尾不要有多余的空格。
两组数据之间空开一行。

Sample Input


6
3


Sample Output


Case 1:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1

Case 2:
1
1 1
1 2 1

第四题:

数素数(注意:数据较大,一般的算法达不到这个效率)

Time Limit:1000MS Memory Limit:65536K
Total Submit:732 Accepted:58

Description

素数是的只能被1和它本身整除的自然数。判断一个数是素数的方法是使用2到该数的平方根的素数除它,若有能整除的则该数不是素数。


Input

本题有多组数据,每组数据由两个正整数M,N组成。(0<M<N<1000000)

Output

输出一个整数,表示介于M,N之间(包括M,N)的素数的数量。

Sample Input


5 10
1 3
6 8

Sample Output


2
2
1

第五题:

高精度整数去位去最小问题

Time Limit:1000MS Memory Limit:65536K
Total Submit:154 Accepted:11

Description

键盘输入一个高精度的正整数N,去掉其中任意M个数字后剩下的数字按原左右次序将组成一个新的正整数。编程对给定的N和M寻找一种方案使得剩下的数字组成的新数最小。输出组成的新的正整数。(不超过240位)

输入数据均不需判错。

如果去掉了某几个位后得到的新整数开头为0,保留0。

Input

本题有多组测试数据,每组测试数据占一行。

一个高精度正整数N(N不超过240位)一个正整数M。(M为不大于N的长度的正整数)

N,M由一个空格分开。

Output

新的正整数,每组数据的输出占一行。不要多余的空白


Sample Input


456547 1
456547 2
456547 3
7773359 2
103 1


Sample Output


45547
4547
447
73359
03


第六题:

行编辑器

Time Limit:10000MS Memory Limit:65536K
Total Submit:129 Accepted:45

Description

一个简单的行编辑程序的功能是:接受用户从终端输入的程序或数据,并存入用户的数据区。

由于用户在终端上进行输入时,不能保证不出差错,因此,若在编辑程序中,“每接受一个字符即存入用户数据区”的做法显然不是最恰当的。较好的做法是,设立一个输入缓冲区,用以接受用户输入的一行字符,然后逐行存入用户数据区。允许用户输入出差错,并在发现有误时可以及时更正。例如,当用户发现刚刚键入的一个字符是错的时,可补进一个退格符"#",以表示前一个字符无效;

如果发现当前键入的行内差错较多或难以补救,则可以键入一个退行符"@",以表示当前行中的字符均无效。

如果已经在行首继续输入'#'符号无效。


Input

输入一个多行的字符序列。但行字符总数(包含退格符和退行符)不大于250。


Output

按照上述说明得到的输出。


Sample Input


whli##ilr#e(s#*s)
outcha@putchar(*s=#++);

Sample Output


while(*s)
putchar(*s++);


第七题:


石子归并

Time Limit:1000MS Memory Limit:65536K
Total Submit:55 Accepted:19

Description

你有一堆石头质量分别为W1,W2,W3...WN.(W<=100000)现在需要你将石头合并为两堆,使两堆质量的差为最小。


Input

该程序有多组测试数据,每组测试数据第一行为整数N(1<=N<=20),表示有N堆石子。接下去N行,为每堆石子的质量。


Output

每组测试数据只需输出合并后两堆的质量差的最小值。

Sample Input


5
5
8
13
27
14
2
4
4


Sample Output


3
0

第八题:

青蛙的约会

Time Limit:1000MS Memory Limit:65536K
Total Submit:204 Accepted:17

Description

两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面。它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止。可是它们出发之前忘记了一件很重要的事情,既没有问清楚对方的特征,也没有约定见面的具体位置。不过青蛙们都是很乐观的,它们觉得只要一直朝着某个方向跳下去,总能碰到对方的。但是除非这两只青蛙在同一时间跳到同一点上,不然是永远都不可能碰面的。为了帮助这两只乐观的青蛙,你被要求写一个程序来判断这两只青蛙是否能够碰面,会在什么时候碰面。
我们把这两只青蛙分别叫做青蛙A和青蛙B,并且规定纬度线上东经0度处为原点,由东往西为正方向,单位长度1米,这样我们就得到了一条首尾相接的数轴。设青蛙A的出发点坐标是x,青蛙B的出发点坐标是y。青蛙A一次能跳m米,青蛙B一次能跳n米,两只青蛙跳一次所花费的时间相同。纬度线总长L米。现在要你求出它们跳了几次以后才会碰面。


Input

输入只包括一行5个整数x,y,m,n,L,其中x≠y < 2000000000,0 < m、n < 2000000000,0 < L < 2100000000。


Output

输出碰面所需要的跳跃次数,如果永远不可能碰面则输出一行"Impossible"


Sample Input


1 2 3 4 5


Sample Output


4




雁无留踪之意,水无取影之心
2007-04-17 10:41
PcrazyC
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:5652
专家分:0
注 册:2006-10-20
收藏
得分:0 
26楼时间不够
27楼和24楼错误,其它均正确,继续努力

雁无留踪之意,水无取影之心
2007-04-18 21:39
PcrazyC
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:5652
专家分:0
注 册:2006-10-20
收藏
得分:0 
30和31楼时间不够

雁无留踪之意,水无取影之心
2007-04-20 09:42
PcrazyC
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:5652
专家分:0
注 册:2006-10-20
收藏
得分:0 
我在我们学校上的OJ上找的,有几百个

雁无留踪之意,水无取影之心
2007-04-20 15:48
快速回复:ACM题集(即时更新)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029683 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved