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


2007-03-31 21:26
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
LZ 还不如放为每期的题目,但最好答案不要先给出来.

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

倚天照海花无数,流水高山心自知。
2007-03-31 21:27
mp3aaa
Rank: 5Rank: 5
等 级:贵宾
威 望:17
帖 子:2013
专家分:8
注 册:2006-2-15
收藏
得分:0 
希望以后能多发点中文的题

羊肉串 葡萄干 哈密瓜!!
2007-03-31 21:29
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
收藏
得分:0 

厉害,以后要多发点


2007-03-31 21:33
我不是郭靖
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:494
专家分:6
注 册:2006-10-4
收藏
得分:0 
支持!!!!!

2007-03-31 21:37
游乐园
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:671
专家分:0
注 册:2006-11-1
收藏
得分:0 
很不错哦...

但对ACM的题迟钝

unicorn-h.spaces. ◇◆ sava-scratch.spaces.
2007-03-31 21:40
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
我不是郭靖
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:494
专家分:6
注 册:2006-10-4
收藏
得分:0 
以下是引用PcrazyC在2007-3-31 21:59:57的发言:

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

恩,好习惯.

这儿有一道英文的.你看看:

http://bbs.bc-cn.net/viewthread.php?tid=127835


2007-03-31 22:03
快速回复:ACM题集(即时更新)
数据加载中...
 
   



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

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