文档库 最新最全的文档下载
当前位置:文档库 › ACM题目整理

ACM题目整理

ACM题目整理
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/1f5129993.html,/faq.php

二、ACM分类

主流算法:

1.搜索//回溯

Problem 1019 猫捉老鼠

Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description

一只猫和一只老鼠在10*10的迷宫中。迷宫中的每个方格可以是空的,或者含有障碍。猫和老鼠可以进入任意一个空的方格中。当他们相遇时,猫和老鼠在同一个方格中。但是,无论猫或老鼠都不能进入有障碍的方格。我们可以用字符组成的二维数组表示迷宫,如下图所示。

老鼠在迷宫中按照一种固定的方式行走:每个时刻,老鼠都向它所面对的方向前进一格,这需要花费1秒时间。如果前方是一个障碍或者是迷宫的边界,它将花1秒的时间按顺时针方向转90度。

为了抓到老鼠,这只猫决定也按照与老鼠相同的行走方式行进。

猫和老鼠在每个单位时间内是同时行动的。因此,如果猫和老鼠在行进过程中“擦肩而过”,猫是无法捉到老鼠的。只有当猫和老鼠同时到达一个相同的格子时,猫才能捉住老鼠。

初始时,猫和老鼠不会在同一个方格中。并且它们都面向北方。

你的任务是编一个程序,求出猫捉到老鼠的所花时间。

Input

输入数据的第一行n,表示输入数据的组数。

每组数据由10行组成,每行10个字符,表示迷宫的地图以及猫和老鼠的初始位置。输入数据保证只有一只猫和一只老鼠。

每组输入数据之后均有一个空行作为间隔。

Output

对于每组给定的输入,输出一行仅含一个数,即猫捉到老鼠所花的时间。如果猫永远都无法抓到老鼠,则输出0。

Sample Input

1

*...*.....

......*...

...*...*..

..........

...*.c....

*.....*...

...*......

..m......*

...*.*....

.*.*......

Sample Output

49

My answer:

#include

char str[12][12];

void doing(int *fs,int *x,int *y)

{

if(*fs==1)

{

if(str[*x-1][*y]=='*') *fs=4;

else *x=*x-1;

}

else if(*fs==2)

{

if(str[*x+1][*y]=='*') *fs=3;

else *x=*x+1;

}

else if(*fs==3)

{

if(str[*x][*y-1]=='*') *fs=1;

else *y=*y-1;

}

else

{

if(str[*x][*y+1]=='*') *fs=2;

else *y=*y+1;

}

}

main()

{

int i,j,k,n,p,fs1,fs2,x1,y1,x2,y2;

scanf("%d",&n);

getchar();

for(i=0;i<=11;i++)

{

str[i][0]='*';str[i][11]='*';

str[0][i]='*';str[11][i]='*';

}

for(i=1;i<=n;i++)

{

fs1=1;fs2=1;p=1;

for(j=1;j<=10;j++)

{

for(k=1;k<=10;k++)

{

scanf("%c",&str[j][k]);

if(str[j][k]=='c')

{

x1=j;y1=k;str[j][k]='.';

}

if(str[j][k]=='m')

{

x2=j;y2=k;str[j][k]='.';

}

}

getchar();

}

for(j=1;j<10000;j++)

{

doing(&fs1,&x1,&y1);

doing(&fs2,&x2,&y2);

if(x1==x2&&y1==y2)

{

printf("%d\n",j);p=0;break;

}

}

if(p)printf("0\n");

if(i

}

}

Problem 1063 三维扫描

Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description

工业和医学上经常要用到一种诊断技术——核磁共振成像(Magnetic Resonance Imagers)。利用该技术可以对三维物体(例如大脑)进行扫描。扫描的结果用一个三维的数组来保存,数组的每一个元素表示空间的一个象素。数组的元素是0-255的整数,表示该象素的灰度。例如0表示该象素是黑色的,255表示该象素是白色的。

被扫描的物体往往是由若干个部件组合而成的。例如临床医学要对病变的器官进行检查,而器官是由一些不同的组织构成的。在实际问题中,同一个部件内部的色彩变化相对连续,而不同的部件的交界处色彩往往有突变。下面是一个简化的植物细胞的例子。

从细胞的平面图来看,该细胞大致是由四个“部件”构成的,细胞壁、细胞核、液泡和细胞质。为了方便起见,我们对部件的概念做如下的规定:

1.如果一个象素属于某部件,则或者该象素至少与该部件的一个象素相邻,或者该象素单独组成一个部件。(说明:每一个象素与前后、左右、上下的6个象素相邻)

2.同一个部件内部,相邻两个象素的灰度差不超过正整数M。M决定了程序识别部件的灵敏度。

你的任务是对于给定的物体,判断该物体是由几个部件组成的。

Input

输入数据由多组数据组成。每组数据格式如下:

第一行是三个正整数L,W,H(L,W,H≤50),表示物体的长、宽、高。

第二行是一个整数M(0≤M≤255),表示识别部件的灵敏度。

接下来是L×W×H个0-255的非负整数,按照空间坐标从小到大的顺序依次给出每个象素的灰度。

说明:对于空间两点P1(x1,y1,z1)和P2(x2,y2,z2),P1

(x1

对于每组数据,输出仅一行包含一个整数M,即一共识别出几个部件。Sample Input

2 2 2

1 1 1 1

2 2 2 2

Sample Output

2

My answer:

#include

#include

int m,l,w,h,c[51][51][51];

long sum;

doing(int i,int j,int r)

{

int q;

q=c[i][j][r];

c[i][j][r]=-1;

if(i-1>0)

if(c[i-1][j][r]!=-1)

if(fabs(c[i-1][j][r]-q)<=m)

doing(i-1,j,r);

if(i+1<=l)

if(c[i+1][j][r]!=-1)

if(fabs(c[i+1][j][r]-q)<=m)

doing(i+1,j,r);

if(j-1>0)

if(c[i][j-1][r]!=-1)

if(fabs(c[i][j-1][r]-q)<=m)

doing(i,j-1,r);

if(j+1<=w)

if(c[i][j+1][r]!=-1)

if(fabs(c[i][j+1][r]-q)<=m)

doing(i,j+1,r);

if(r-1>0)

if(c[i][j][r-1]!=-1)

if(fabs(c[i][j][r-1]-q)<=m)

doing(i,j,r-1);

if(r+1<=h)

if(c[i][j][r+1]!=-1)

if(fabs(c[i][j][r+1]-q)<=m)

doing(i,j,r+1);

}

main()

{

int i,j,r;

while(scanf("%d%d%d",&l,&w,&h)!=EOF)

{

scanf("%d",&m);

for(i=1;i<=l;i++)

for(j=1;j<=w;j++)

for(r=1;r<=h;r++)

scanf("%d",&c[i][j][r]);

sum=0;

for(i=1;i<=l;i++)

for(j=1;j<=w;j++)

for(r=1;r<=h;r++)

if(c[i][j][r]!=-1)

{

sum++;

doing(i,j,r);

}

printf("%d\n",sum);

}

}

Problem 1073 Raiders of the Lost Ark Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description

In this famous film, renowned archeologist and expert in the occult, Dr. Indiana Jones, is hired by the U.S. Government to find the Ark of the Covenant, which is believed to still hold the ten commandments. Unfortunately, agents of Hitler are also after the Ark. Dr. Jones escapes from various close scrapes in a quest that takes him from Nepal to Cairo. Your task is to help him to find the lost Ark of the Covenant in the maze earlier than the enemy.

There are several barriers in the maze, Dr. Jones can bypass these barriers on foot or by jump .He can go on foot in four directions of east, south, west and north to reach a neighboring position. He can also jump cross a cell in the directions of southeast, southwest, northeast and northwest to reach a new position. The following figure shows Dr. Jones's action where O denotes the original position and X denotes the new possible positions after one action.

Input

The first line of the input is an integer n (0<=n<=20), denoting the number of test cases. The following lines are the data of n test cases. The first line of each test case consists of two integer x and y (0

Output

For each test case, output one line. If there is a solution for the problem, output the number of the least steps to find the Ark. Otherwise output "NO ANSWER".

Sample Input

3

3 3

SWB

BWB

XBB

5 4

BXWB

BBWS

BBWB

BBWB

BBBB

3 2

WX

WW

WS

Sample Output

2

2

NO ANSWER

My answer:

#include

int n,m,p[13][13],x1,x2,y1,y2;

char s[13][13];

doing(int x,int y,int z)

{

if(z>=p[x][y])return 0;

p[x][y]=z;

if(x-1>0)

if(s[x-1][y]=='B')

doing(x-1,y,z+1);

if(y-1>0)

if(s[x][y-1]=='B')

doing(x,y-1,z+1);

if(x

if(s[x+1][y]=='B')

doing(x+1,y,z+1);

if(y

if(s[x][y+1]=='B')

doing(x,y+1,z+1);

if(x-2>0&&y-2>0)

if(s[x-2][y-2]=='B')

doing(x-2,y-2,z+1);

if(x-2>0&&y+2<=m)

if(s[x-2][y+2]=='B')

doing(x-2,y+2,z+1);

if(x+2<=n&&y-2>0)

if(s[x+2][y-2]=='B')

doing(x+2,y-2,z+1);

if(x+2<=n&&y+2<=m)

if(s[x+2][y+2]=='B')

doing(x+2,y+2,z+1);

}

main()

{

int i,j,r,k;

scanf("%d",&k);

for(r=1;r<=k;r++)

{

scanf("%d%d%*c",&n,&m);

for(i=1;i<=n;i++)

{

for(j=1;j<=m;j++)

{

p[i][j]=20000;

scanf("%c",&s[i][j]);

if(s[i][j]=='S')

{

x1=i;y1=j;s[i][j]='B';

}

if(s[i][j]=='X')

{

x2=i;y2=j;s[i][j]='B';

}

}

getchar();

}

doing(x1,y1,0);

if(p[x2][y2]==20000)printf("NO ANSWER\n");

else printf("%d\n",p[x2][y2]);

}

}

Problem 1081 等分液体

Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description

有三种容器R1,R2,R3,其容积分别是L,M,N。L,M,N 都是正整数且L=M+N。今R1 装满液体,试用最少的操作步骤将R1 中的液体均分。

Input

第一行仅包含一个表示测试例个数的正整数n 。以下n 行为n个测试例的输入数据。每个测试例仅有一行输入数据,含三个正整数L,M,N (1<=L,M,N<=150),两数间用一个空格隔开。

Output

每个测试例都仅有一行输出,若有解,输出操作的次数,若无解则输出“no”。

Sample Input

3

100 70 30

90 60 30

80 45 35

Sample Output

9

no

15

My answer:

#include

int n,l,a,b,min,v,s[151][151];

doing(int x1,int x2,int x3,int z)

{

if(z

if(z

{

s[x1][x2]=z;

if(x1==v&&x2==v)min=z;

else

{

if(x1)

{

if(x2!=a)

{

if(x1

else doing(x1-a+x2,a,x3,z+1);

}

if(x3!=b)

{

if(x1

else doing(x1-b+x3,x2,b,z+1);

}

}

if(x2)

{

if(x1!=l)

{

if(x2

else doing(l,x2-l+x1,x3,z+1);

}

if(x3!=b)

{

if(x2

else doing(x1,x2-b+x3,b,z+1);

}

}

if(x3)

{

if(x1!=l)

{

if(x3

else doing(l,x2,x3-l+x1,z+1);

}

if(x2!=a)

{

if(x3

else doing(x1,a,x3-a+x2,z+1);

}

}

}

}

}

main()

{

int i,j,t;

scanf("%d",&n);

for(i=1;i<=n;i++)

{

scanf("%d%d%d",&l,&a,&b);

if(a==b)

{

printf("1\n");continue;

}

min=10000;v=l/2;

if(b>a)

{

t=a;a=b;b=t;

}

for(j=0;j<=l;j++)

for(t=0;t<=a;t++)

s[j][t]=min;

doing(l,0,0,0);

if(min==10000)printf("no\n");

else printf("%d\n",min);

}

}

Problem 1082 最大黑区域

Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description

二值图像是由黑白两种像素组成的矩形点阵,图像识别的一个操作是求出图像中最大黑区域的面积。请设计一个程序完成二值图像的这个操作。黑区域由黑像素组成,一个黑区域中的每个像素至少与该区域中的另一个像素相邻,规定一个像素仅与其上、下、左、右的像素相邻。两个不同的黑区域没有相邻的像素。一个黑区域的面积是其所包含的像素的个数。

Input

输入由多个测试例组成。每个测试例的第一行含两个整数n和m, (1 <=n,m<=100), 分别表示二值图像的行数与列数,后面紧跟着n行,每行含m个整数0或1,其中第i行表示图像的第i行的m个像素,0表示白像素,1表示黑像素。同一行的相邻两个整数之间用一个空格隔开,两个测试例之间用一个空行隔开,最后一个测试例之后隔一个空行,再接的一行含有两个整数0,标志输入的结束。

Output

每个测试例对应一行输出,含一个整数,表示相应的图像中最大黑区域的面积。

Sample Input

5 6

0 1 1 0 0 1

1 1 0 1 0 1

0 1 0 0 1 0

0 0 0 1 1 1

1 0 1 1 1 0

0 0

Sample Output

7

My answer:

#include

int n,m,q,s[101][101];

doing(int x,int y,int z)

{

s[x][y]=z;q++;

if(x>1)

if(s[x-1][y]==1)

doing(x-1,y,z);

if(x

if(s[x+1][y]==1)

doing(x+1,y,z);

if(y>1)

if(s[x][y-1]==1)

doing(x,y-1,z);

if(y

if(s[x][y+1]==1)

doing(x,y+1,z);

}

main()

{

int i,j,p,max;

scanf("%d%d",&n,&m);

while(n>0)

{

p=1;max=0;

for(i=1;i<=n;i++)

for(j=1;j<=m;j++)

scanf("%d",&s[i][j]); for(i=1;i<=n;i++)

for(j=1;j<=m;j++)

if(s[i][j]==1)

{

p++;q=0;

doing(i,j,p);

if(q>max)max=q;

}

printf("%d\n",max);

scanf("%d%d",&n,&m);

}

}

Problem 1099 Square

Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description

Given a set of sticks of various lengths, is it possible to join them end-to-end to form a square? Input

The first line of input contains N, the number of test cases. Each test case begins with an integer 4 <= M <= 20, the number of sticks. M integers follow; each gives the length of a stick - an integer between 1 and 10,000.

Output

For each case, output a line containing "yes" if is is possible to form a square; otherwise output "no".

Sample Input

3

4 1 1 1 1

5 10 20 30 40 50

8 1 7 2 6 4 4 3 5

Sample Output

yes

no

yes

My answer:

#include

int v,p,m,l[30],h[30]={0};

doing(int g,int z,int c)

{

if(p)return 0;

if(c==3)

{

p=1;return 0;

}

if(z==v)

{

doing(1,0,c+1);return 0;

}

if(g<=m)

{

if(!h[g]&&z+l[g]<=v)

{

h[g]=1;

doing(g+1,z+l[g],c);

h[g]=0;

}

doing(g+1,z,c);

}

}

main()

{

int n,i,j,sum,max,q,z;

scanf("%d",&n);

while(n--)

{

scanf("%d",&m);

sum=0;

for(i=1;i<=m;i++)

{

scanf("%d",&l[i]);

sum+=l[i];

}

for(i=1;i<=m;i++)

for(j=i+1;j<=m;j++)

if(l[j]>l[i])

{

q=l[i];l[i]=l[j];l[j]=q;

}

v=sum/4;

if(sum%4==0&&l[1]<=v)

{

p=0;

doing(1,0,0);

if(p)printf("yes\n");

else printf("no\n");

}

else printf("no\n");

}

}

Problem 1501 Country in a map

Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description

You are given a rectangular map of a continent. The map is a grid of squares, each square has a color. A country is a connected set of squares (squares are connected if they share an edge) that have the same color. Neighboring countries have different colors. Find the size (in squares) of the largest country.

There will be at least one country in the map.

Input

Input data will be provided as standard input to the program. The first line of input contains the number of test cases (<=10). Each test case begins with a line containing two numbers W and H, the width and height of the map, separated by a single space, 1 <= W,H <= 10. The next H lines contain W characters each | they describe the map. Colors are represented by the letters A-Z. Water (no country) is represented by a dot.

Output

For each test case output one line containing the size of the largest country.

Sample Input

1

6 5

...BBB

.AAAAB

..BBA.

..BB..

......

Sample Output

5

My answer:

#include

char s[15][15],ch;

int max,q;

doing(int x,int y)

{

q++;

s[x][y]='.';

if(s[x-1][y]==ch)doing(x-1,y);

if(s[x+1][y]==ch)doing(x+1,y);

if(s[x][y-1]==ch)doing(x,y-1);

if(s[x][y+1]==ch)doing(x,y+1);

}

main()

{

int i,j,r,k,m,n;

scanf("%d",&k);

for(i=1;i<=k;i++)

{

scanf("%d%d%*c",&m,&n);

for(j=0;j<=n+1;j++)

for(r=0;r<=m+1;r++)

s[j][r]='.';

for(j=1;j<=n;j++)

{

for(r=1;r<=m;r++)

scanf("%c",&s[j][r]);

getchar();

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/1f5129993.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/1f5129993.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/1f5129993.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/1f5129993.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.

相关文档