In Africa there is a very special species of bee. Every year, the female bees of such species give birth
to one male bee, while the male bees give birth to one male bee and one female bee, and then they die!
Now scientists have accidentally found one “magical female bee” of such special species to the effect
that she is immortal, but still able to give birth once a year as all the other female bees. The scientists
would like to know how many bees there will be after N years. Please write a program that helps them
find the number of male bees and the total number of all bees after N years.
Input
Each line of input contains an integer N (≥ 0). Input ends with a case where N = −1. (This case
should NOT be processed.)
Output
Each line of output should have two numbers, the first one being the number of male bees after N
years, and the second one being the total number of bees after N years. (The two numbers will not
exceed 232.)
Sample Input
1
3
-1
Sample Output
1 2
4 7

题意: 蜜蜂,每年每只雄蜂产下一只雌蜂和一只雄蜂,每只雌蜂产下一只雄蜂,然后就死去, 现在发现了一只不会死的雌蜂,问以她为起始点,第N年有多少雄蜂和一共多少蜜蜂。

题解:    设第i年的雄蜂和雌蜂分别为a(i)与s(i),则有如下递推关系:

1 s(i)= a(i-1)+ 1

2 a(i)= s(i-1)+ a(i-1)

整理得:a(i)=a(i-1)+ a(i-2)+ 1;

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#include<vector>
#include <map>
using namespace std ;
typedef long long ll; const int N=+;
const int maxn = 1e9 + ; ll a[N];
void init() {
a[] = ;
a[] = ;
for(int i=;i<=N;i++) a[i] = a[i-] + a[i-] +1ll;
}
int main() {
init();
int n;
while(~scanf("%d",&n)) {
if(n == -) break;
printf("%lld %lld\n", a[n] , a[n+]);
}
return ;
}

代码

最新文章

  1. 解决adobe air sdk打包 apk后自动在包名前面加上air. (有个点)前缀的问题
  2. block传值和代理传值的异同点
  3. js获取单选按钮的值
  4. TXT导入出现乱码
  5. Java NIO读书笔记2
  6. boost库的使用(一)
  7. mysql分表,分区的区别和联系
  8. RAC的负载均衡有2种方式
  9. c#添加事物(全部执行和带保存点的执行)
  10. SQL点滴6—“微软不认识闰年2月29日”&amp;字符&quot;N&quot;的作用
  11. javaWeb学习总结(8)- JSP原理
  12. Dynamics CRM FORM脚本库加载本地脚本
  13. Get Remote Computer Install Software
  14. activiti 任务监听参数的配置
  15. Opening Ceremony(贪心)
  16. es6学习一 promise上
  17. testng执行用例失败,再次执行
  18. PHPthinking赠书了!
  19. Java提高篇(转)
  20. linux-git服务搭建

热门文章

  1. IDEA中Lombok插件的安装与使用
  2. A - Antipalindrome
  3. Hadoop MapReduce编程 API入门系列之统计学生成绩版本2(十八)
  4. 使用Micrisoft.net设计方案 第二章组织模式
  5. Android ExpandableListView group的item有间距child间隔不变
  6. Android App退出检测
  7. C语言运算符类型
  8. C++基础 (4) 第四天 this指针 全局函数和成员函数 友元 操作符重载
  9. LCIS 最长公共上升子序列问题DP算法及优化
  10. Project Euler 47 Distinct primes factors( 筛法记录不同素因子个数 )