摘要: 问题:某人写了n封信和n个信封,如果所有的信都装错了信封。求所有的信都装错信封,共有多少种不同情况。 思路:由这道题引入错排公式:f(n)=(n-1)*[f(n-1)+f(n-2)]。 当N=1和2时,易得解~,假设F(N-1)和F(N-2)已经得到,重点分析下面的情况: 当有N封信的时候,前面N- 阅读全文
posted @ 2017-08-25 18:33 北梗 阅读(94) 评论(0) 推荐(0) 编辑
摘要: 问题:平面上有n条折线,问这些折线最多能将平面分割成多少块? 思路:像这种平面被线段分割成几部分的问题,80%用递推解决,因为n条线段与(n-1)条线段能建立联系。 你可以作图观察一下,会发现新增加的折线被分割成几个区段,平面就会增加几部分,而区段的增加又与新增折线与原有折线的交点数有关,这便建立了 阅读全文
posted @ 2017-08-25 16:20 北梗 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 求A^B的最后三位数表示的整数。说明:A^B的含义是“A的B次方” 思路:后三位只跟后三位相乘有关,所以可以每乘一次都对1000取余。 代码: #include <stdio.h>#include <stdlib.h> int main(){ int result,i,m,n; while(scan 阅读全文
posted @ 2017-08-24 21:56 北梗 阅读(72) 评论(0) 推荐(0) 编辑
摘要: Problem Description Given a positive integer N, you should output the most right digit of N^N. Input The input contains several test cases. The first 阅读全文
posted @ 2017-08-24 20:40 北梗 阅读(98) 评论(0) 推荐(0) 编辑
摘要: Problem Description Julius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever faced was keeping himself alive. In order 阅读全文
posted @ 2017-08-24 16:57 北梗 阅读(140) 评论(0) 推荐(0) 编辑
摘要: Problem Description Given two integers n and m, count the number of pairs of integers (a,b) such that 0 < a < b < n and (a^2+b^2 +m)/(ab) is an intege 阅读全文
posted @ 2017-08-24 16:37 北梗 阅读(95) 评论(0) 推荐(0) 编辑
摘要: Problem Description(数根) The digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit 阅读全文
posted @ 2017-08-24 16:21 北梗 阅读(79) 评论(0) 推荐(0) 编辑
摘要: Problem Description In many applications very large integers numbers are required. Some of these applications are using keys for secure transmission o 阅读全文
posted @ 2017-08-24 16:12 北梗 阅读(115) 评论(0) 推荐(0) 编辑
摘要: Problem Description The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at w 阅读全文
posted @ 2017-08-24 16:06 北梗 阅读(214) 评论(0) 推荐(0) 编辑
摘要: c语言调用函数时,实参和形参的类型不匹配时 ,会发生类型的自动转换,要格外注意! c语言调用函数时,只能传值给函数。 本地变量、局部变量、自动变量指的都是一种东西。 本地变量的生存期、作用域都是以大括号为准的,都是定义在块内的,进入这个块之前,变量不存在,离开这个块之后,变量就消失了。 块外面定义的 阅读全文
posted @ 2017-04-20 22:26 北梗 阅读(158) 评论(0) 推荐(0) 编辑