本人将陆续推出浙江大学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
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
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...)|编辑