ImageVerifierCode 换一换
格式:DOCX , 页数:11 ,大小:25.92KB ,
资源ID:13295464      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/13295464.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(大学ACM考试题目及作业答案整理docWord文档格式.docx)为本站会员(b****1)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

大学ACM考试题目及作业答案整理docWord文档格式.docx

1、2、 LELE的RPG难题:有排成一行的n个方格,用红(Red)、粉(Pink)、绿(Green) 三色涂每个格子,每格涂一色,要求任何相邻的方格不能同色,且首尾两格也 不同色.编程全部的满足要求的涂法.#in cludeif(n=l) return 3;else if(n二=2) return 6;else return f(n-l)+f(n-2)*2;cinf( n)v 3、北大 ACM(1942)Paths on a GridTime Limit: 1000MS Memory Limit: 30000KDescriptionImagine you are attending your m

2、ath lesson at school. Once again, you are bored because your teacher tells things that you already mastered years ago (this time he*s explaining that (a+b)2=a2+2ab+b2) So you decide to waste your time with drawing modern art instead.Fortunately you have a piece of squared paper and you choose a rect

3、angle of size n*m on the paper. Lets call this rectangle together with the lines it contains a grid. Starting at the lower left corner of the grid, you move your pencil to the upper right corner, taking care that it stays on the lines and moves only to the right or up. The result is shown on the lef

4、t:Really a masterpiece, isn*t it? Repeating the procedure one more time, you arrive with the picture shown on the right. Now you wonder: how many different works of art can you produce?InputThe input contains several testcases. Each is specified by two unsigned 32-bit integers n and m, denoting the

5、size of the rectangle. As you can observe, the number of lines of the corresponding grid is one more in each dimenision. Input is terminated by n=m=0.OutputFor each test case output on a line the number of different art works that can be generated using the procedure described above. That is, how ma

6、ny paths are there on a grid where each step of the path consists of moving one unit to the right or one unit up? You may safely assume that this number fits into a 32-bit unsigned integer.Sample Input5 41 10 0Sample Output1262#includeusing namespace std;long long f(long long m, long long n)if(n=O)

7、return 1; else return f(m-l,n-l)*m/n;int main()long long m,n;while(scanf(%l64d %l64d,&n,&m) & n+m) printf(%l64dnzf(m+n,min(mzn);return 0;1、(并查集)若某个家族人员过于庞大,要判断两个是否是亲戚,确实还很不容易, 现在给出某个亲戚关系图,求任意给出的两个人是否具有亲戚关系。规定:x和y是亲戚,y和z是亲戚,那么x和z也是亲戚。如果x,y是亲戚,那么 x的亲戚都是y的亲戚,y的亲戚也都是x的亲戚。数据输入:第一行:三个整数(nv=5000,mv=5000,pv

8、=5000),分别表示有n个人,m个亲 戚关系,询问p对亲戚关系。以下m行:每行两个数Mi, Mj, l=Mi, Mjint fatherlOOOO;int find(int x)讦(fatherx=x) return x;elsereturn fatherx二find(fatherx);int n,m,p; scanf(%d%d%dn/&m,&p); for(int i=l;i二n;i+) fatheri=i;int a,b;for(int i=l;=m;i+)scanf(%d%da,&b); a=find(a);b=find(b);if(a!=b) fathera=b;=p;a=fi nd

9、(a);=b) printf(”Non“);YesnH); return 0;假设有两个皇后被放置在(i, j)和(k, 1)的位置上,明显,当且仅当 吋,两个皇后才在同一条对角线上。(1)先从首位开始检查,如果不能放置,接着检查该行第二个位置,依次检查 下去,直到在该行找到一个可以放置一个皇后的地方,然后保存当前状态,转到 下一行重复上述方法的检索。(2)如果检查了该行所有的位置均不能放置一个皇后,说明上一行皇后放置的 位置无法让所有的皇后找到自己合适的位置,因此就要回溯到上一行,重新检查 该皇后位置后面的位置。int PLACE (int n) /*检查当前列能否放置皇后*/queen i

10、 = queen n用于保证元素不能再冋一列/abs (queen i - queen n ) = abs (n - i)用于约束元索不能再同一行J4不能再同一 条斜线上int i;for (i = 0; i n; i + +) /*检查横排和对角线上是否可以放置皇后*/if(queen i = queenn | | abs(queen i - queenn) = abs(n - i)return 1; 1 2345678 9 10 11 12131415具体的实现代码如下:stdlibh#define max 4/sum用于描述解的可能的个数,每当输出一次复合要求的位置/sum的数量就会被+

11、1int queen max , sum=O; /* max 为棋盘最大坐标 */void show () /*输出所有皇后的坐标*/printf (n (n);/i代表行数,queen i代表当前行元素所处的列数,/注意此处下标是从0开始的 max; i+)printf ( n %d”,queeni+1);printf(”)n);/每次输出一种解的时候,那么他的解的数量就会增加1sum+;/此函数用于判断皇后当前皇后是否可以放在此位置/queen i = queen n用于保证元素不能再同一列/abs (queen i - queen n ) = abs (n - i)用于约束元素不能再同一

12、行且不能再同一 条斜线上 n; i+) /*检查横排和对和线上是否可以放置皇后*/if(queeni = queenn | | abs (queeni 一 queenn) = abs(n 一 i)/核心函数,冋溯法的思想void NQUEENSfint n) /*回溯尝试皇后位置小为横坐标*/首先将皇后放在第0列的位置,对于第一次來说是肯定成立的/所以第一次将皇后放在第0行0列的位置queen n = i; /*将皇后摆到当前循环到的位置*/if(PLACE(n)if (n = max 一 1)show(); /*如果全部摆好,则输出所有皇后的坐标*/NQUEENS (n + 1) ; /*否则继续摆放下一个皇后*/FF31KAHZD1H8ETZ8WWEZWUUVAint main ()NQUEENS (0) ; /*从横坐标为0开始依次尝试*/printf(nn H;print f

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1