毕业设计,毕业论文代写。专业水平。钻石水准,黄金品质。

计算机专业毕业设计,论文,设计代写。电邮:elevenor@gmail.com。专业水平,质优价廉。

原创 浙江大学ACM试题解答(三月)收藏

新一篇: 浙江大学ACM试题解答(四月) | 旧一篇: 趣味编程之入门篇

本人将陆续推出浙江大学ACM试题解答,本版块不断更新中
试题来源:http://acm.zju.edu.cn/
(1)


A + B Problem

Time limit: 1 Seconds   Memory limit: 32768K  
Total Submit: 36266   Accepted Submit: 15674  


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

Sample Output

6

Hint

Use + operator


Submit   Back   Status

Zhejiang University Online Judge V1.0 Book
Sorce code in C:
#include <stdio.h> 
int main()
{
    int a,b;
    while(scanf("%d %d",&a, &b) != EOF)
        printf("%d\n",a+b);
}
(2)


Fire Net

Time limit: 1 Seconds   Memory limit: 32768K  
Total Submit: 10728   Accepted Submit: 3355  

Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall.

A blockhouse is a small castle that has four openings through which to shoot. The four openings are facing North, East, South, and West, respectively. There will be one machine gun shooting through each opening.

Here we assume that a bullet is so powerful that it can run across any distance and destroy a blockhouse on its way. On the other hand, a wall is so strongly built that can stop the bullets.

The goal is to place as many blockhouses in a city as possible so that no two can destroy each other. A configuration of blockhouses is legal provided that no two blockhouses are on the same horizontal row or vertical column in a map unless there is at least one wall separating them. In this problem we will consider small square cities (at most 4x4) that contain walls through which bullets cannot run through.

The following image shows five pictures of the same board. The first picture is the empty board, the second and third pictures show legal configurations, and the fourth and fifth pictures show illegal configurations. For this board, the maximum number of blockhouses in a legal configuration is 5; the second picture shows one way to do it, but there are several other ways.

 

Your task is to write a program that, given a description of a map, calculates the maximum number of blockhouses that can be placed in the city in a legal configuration.

The input file contains one or more map descriptions, followed by a line containing the number 0 that signals the end of the file. Each map description begins with a line containing a positive integer n that is the size of the city; n will be at most 4. The next n lines each describe one row of the map, with a '.' indicating an open space and an uppercase 'X' indicating a wall. There are no spaces in the input file.

For each test case, output one line containing the maximum number of blockhouses that can be placed in the city in a legal configuration.

Sample input:

4
.X..
....
XX..
....
2
XX
.X
3
.X.
X.X
.X.
3
...
.XX
.XX
4
....
....
....
....
0

Sample output:

5
1
5
2
4

Problem Source: Zhejiang University Local Contest 2001


Submit   Back   Status

Zhejiang University Online Judge V1.0 Book

 

 Sorce code in C:

/*  Acm_Fire_Net.c

    Copyright (c) 2002, 2007 by ctu_85
    All Rights Reserved.
*/
#include "stdio.h"
#define max 4
#define open 0
#define shooter 1
#define wall 2
#define workload 10
int res=-1;
int num,result[max*max],map[max*max];
int Do(int,int[]);
int Judge(int []);
void main()
{
int temp[max*max],i=0,j=0,k=0,count=0,answ[workload];
char s[max+1],t;
scanf("%d",&num);
while(count<workload&&num>0)
{
for(i=0;i<num;i++)
{
scanf("%s",s);
for(j=0;j<num;j++,k++)
if(s[j]=='.')
map[k]=open;
else
map[k]=wall;
}
Do(0,temp);
answ[count]=res;
res=-1;
k=0;
count++;
scanf("%d",&num);
}
if(count<workload)
for(i=0;i<count;i++)
printf("%d\n",answ[i]);
else
printf("\nToo much work!\n");
}
int Do(int start,int temp[max*max])
{
int i=0,answer=-2;
if(start==num*num)
{
answer=Judge(temp);
if(answer>res)
{
res=answer;
for(i=0;i<num*num;i++)
result[i]=temp[i];
}
return 1;
}
else
{
if(map[start]==wall)
{
temp[start]=wall;
Do(start+1,temp);
}
else
{
temp[start]=open;// leave the place blank
Do(start+1,temp);
temp[start]=shooter;// allocate a shooter there
Do(start+1,temp);
}
}
}
int Judge(int alloc[max*max])
{
int i,j,row,count=0;
for(i=0;i<num*num;i++)
if(alloc[i]==shooter)
{
row=i/num;
for(j=i+1;j<num*row+num;j++)// judge towards right
if(alloc[j]==wall)// first meet a wall
break;
else
if(alloc[j]==shooter)// first meet another shooter
return -1;
for(j=i+num;j<num*num;j+=num)
if(alloc[j]==wall)
break;
else
if(alloc[j]==shooter)
return -1;
}
for(i=0;i<num*num;i++)
if(alloc[i]==shooter)
count++;
return count;
}

更多内容:

麻省理工算法导论翻译
http://blog.csdn.net/ctu_85/archive/2007/06/08/1643179.aspx
浙江大学ACM试题解答(四月)
http://blog.csdn.net/ctu_85/archive/2007/04/24/1576831.aspx
浙江大学ACM试题解答(三月)
http://blog.csdn.net/ctu_85/archive/2007/03/20/1535556.aspx
华容道游戏与算法
http://blog.csdn.net/ctu_85/archive/2007/05/15/1610722.aspx
中国象棋对战程序C语言源代码
http://blog.csdn.net/ctu_85/archive/2007/05/04/1596351.aspx
三维建筑物图像的二维建模
http://blog.csdn.net/ctu_85/archive/2006/12/20/1451106.aspx
分段线性骨架
http://blog.csdn.net/ctu_85/archive/2006/06/15/799847.aspx
基于图论的图像分割技术
http://blog.csdn.net/ctu_85/archive/2006/06/15/799857.aspx
Linux文件系统
http://blog.csdn.net/ctu_85/archive/2006/06/12/791644.aspx
分层模型
http://blog.csdn.net/ctu_85/archive/2006/06/07/777997.aspx
汉语编程企业管理应用软件可行性研究报告
http://blog.csdn.net/ctu_85/archive/2007/01/22/1490139.aspx
汉语编程企业管理应用软件需求说明书
http://blog.csdn.net/ctu_85/archive/2007/01/22/1490136.aspx
计算机专业操作系统课程设计报告
http://blog.csdn.net/ctu_85/archive/2007/01/22/1490130.aspx
软件可行性报告
http://blog.csdn.net/ctu_85/archive/2006/06/06/775894.aspx
软件需求分析报告
http://blog.csdn.net/ctu_85/archive/2006/06/06/775892.aspx
两种计算Ack(m,n)的非递归算法
http://blog.csdn.net/ctu_85/archive/2006/11/29/1419396.aspx
浙江大学计算机复试解答1
http://blog.csdn.net/ctu_85/archive/2006/10/15/1334936.aspx
浙江大学计算机复试解答2
http://blog.csdn.net/ctu_85/archive/2006/10/16/1336101.aspx
浙江大学计算机复试解答3
http://blog.csdn.net/ctu_85/archive/2006/11/02/1363159.aspx

发表于 @ 2007年03月20日 22:00:00|评论(loading...)|编辑

新一篇: 浙江大学ACM试题解答(四月) | 旧一篇: 趣味编程之入门篇

评论

#icerain9999 发表于2007-07-05 12:15:09  IP: 121.70.1.*
auto spell corrector的程序有么??
#icerain9999 发表于2007-07-05 12:17:46  IP: 121.70.1.*
这道ACM题怎么做啊?求助!!!!!
Have you ever used Microsoft Word (R) to edit English document? Have you noticed the auto-spell-corrector?

Littleboy found that whenever he mistypes the "the" as "teh" or "hte", it will be corrected automatically. Littleboy noticed that people are prone to typing the characters out of order when they type too fast, and he guesses that auto-spell-corrector in Microsoft Word (R) relies on this fact. Being interested in this, he decided to write a simple auto-spell-corrector of his own.

His algorithm works as follow: given a word,

1. If the word can be found from the predefined dictionary, left it as it was.
2. If swapping one pair of consecutive characters leads to another word that can be found from the predefined dictionary, that word is an option for substitution. If one or more substitution candidates were found, output all of them.
3. If neither of the above schemes can be applied to the word, it must be a name, so left it as it was.

Input

Input consists of multiple test cases. The first line of the input will be a positive number T(0<T<=10), representing the number of the test cases. Then follow T test cases.

The first line of each test case, there will be an integer D(0<=D<=100), the number of the words in the predefined dictionary. Then D words follow, each word in its own line. After the predefined dictionary, there will be an integer Q(0<=Q<=100), the
#baidu9833 发表于2008-03-19 21:43:07  IP: 202.118.102.*
temp[start]=open;// leave the place blank
Do(start+1,temp);
temp[start]=shooter;// allocate a shooter there
Do(start+1,temp);
您好 我想问问这两个步骤怎么走的?
#wanghuaguo 发表于2008-10-02 22:04:51  IP: 117.36.60.*
好博客。。。。。。。。
#係り員 发表于2008-11-18 13:53:30  IP: 121.92.15.*
不倫おっぱいアダルト
#モテ度診断 发表于2008-11-20 11:42:10  IP: 124.26.174.*
セックス童貞熟女
#童貞 发表于2008-11-21 12:18:34  IP: 58.138.2.*
童貞で悩まないで!
童貞
#脱童貞体験 发表于2008-11-21 12:20:32  IP: 58.138.2.*
童貞で悩まないで!
童貞
#美代子 发表于2008-11-22 14:07:49  IP: 124.26.194.*
エロセックス出会い
发表评论  


登录
Csdn Blog version 3.1a
Copyright © ctu_85