ACM STUDY
ACM学习<二>
穷举算法思想:

#include <iostream> //头文件
using namespace std;
int qiongju(int head, int foot , int *chicken,int *rabbit) //穷举算法
{
int re,i,j;
re=0;
for(i=0;i<=head;i++) //循环
{
j=head-i;
if(i*2+j*4==foot) //判断,找到答案
{
re=1;
*chicken=i;
*rabbit=j;
}
}
return re;
}
int main() //主函数
{
int chicken,rabbit,head,foot;
int re;
cout<<"鸡兔同笼问题:"<<endl;
cout<<"输入头数:";
cin >>head;
cout<<"输入脚数:";
cin >>foot;
re =qiongju(head,foot,&chicken,&rabbit); //& 跟 qiongju()里面的 * 是不是表示 引用??
if(re==1)
{
cout<<"鸡有:"<<chicken<<"只, 兔有"<<rabbit<<"只。" <<endl;
}else
{
cout<<"无法求解!"<<endl;
}
}


#include <iostream>
using namespace std;
int fibonacci(int n)
{
if(n==1 || n==2)
{
return 1;
}
else
{
return fibonacci(n-1)+fibonacci(n-2);//递归调用
}
}
int main()
{
int n,num;
cout<<"斐波那契数列——兔子产子:"<<endl;
cout<<"请输入时间:";
cin >> n;
num=fibonacci(n);
cout<<"经过"<<n<<"年,可以产子"<<num<<"对"<<endl;
}

![]() #include <iostream> ![]() |
![]() #include <iostream> ![]() |
![]() #include <iostream> ![]() |
ACM STUDY的更多相关文章
- ACM study day3
今天练了二分和快速幂,题目挺难的,挑几个我做上的说一下吧. 先给出几个二分和快速幂的模板函数: 二分 void BS(int m) { int x=,y=a[m-]-a[]; while(y-x> ...
- Ubuntu 16.04 安装CodeBlocks
首先将软件源添加进来,就是运行以下命令 sudo add-apt-repository ppa:damien-moore/codeblocks-stable sudo apt-get update 完 ...
- IEEE/ACM ASONAM 2014 Industry Track Call for Papers
IEEE/ACM International Conference on Advances in Social Network Analysis and Mining (ASONAM) 2014 In ...
- Call for Papers IEEE/ACM International Conference on Advances in Social Network Analysis and Mining (ASONAM)
IEEE/ACM International Conference on Advances in Social Network Analysis and Mining (ASONAM) 2014 In ...
- Machine Learning Algorithms Study Notes(3)--Learning Theory
Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 本系列文章是Andrew Ng 在斯坦福的机器学习课程 CS 22 ...
- Machine Learning Algorithms Study Notes(2)--Supervised Learning
Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 本系列文章是Andrew Ng 在斯坦福的机器学习课程 CS 22 ...
- Machine Learning Algorithms Study Notes(1)--Introduction
Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 目 录 1 Introduction 1 1.1 ...
- ACM: POJ 1401 Factorial-数论专题-水题
POJ 1401 Factorial Time Limit:1500MS Memory Limit:65536KB 64bit IO Format:%lld & %llu ...
- IEEE/ACM International Conference on Advances in Social Network Analysis and Mining (ASONAM) 2014 Industry Track Call for Papers
IEEE/ACM International Conference on Advances in Social Network Analysis and Mining (ASONAM) 2014 In ...
随机推荐
- C语言中符号格式说明
scanf 语法: #include <stdio.h>int scanf( const char *format, ... ); scanf()函数根据由format(格式)指定的格式从 ...
- 使用Maven管理Spring[转]
原文链接: Spring with Maven 原文日期: 2013年04月17日 翻译日期: 2014年06月29日 翻译人员: 铁锚 翻译原文连接:http://blog.csdn.net/ren ...
- javascript权威指南(1)
javascript常用知识点: http://www.cnblogs.com/pingfan1990/p/4309223.html Function.prototype.bind()Function ...
- C语言学习之路,第一篇章。
看的书是 C primer plus ,这本书好评很多, 学过C#,没有精通,了解Java,所以看这本书会很容易上手,编译器用的是VC++6.0,因为VS2010好像不支持C99标准,有些代码功能 ...
- [Cocoa]深入浅出 Cocoa 之消息
深入浅出 Cocoa 之消息 罗朝辉(http://blog.csdn.net/kesalin) 转载请注明出处 在入门级别的ObjC 教程中,我们常对从C++或Java 或其它面向对象语言转过 ...
- mvc中动态给一个Model类的属性设置验证
原文:mvc中动态给一个Model类的属性设置验证 在mvc中有自带的验证机制,比如如果某个字段的类型是数字或者日期,那么用户在输入汉字或者英文字符时,那么编译器会自动验证并提示用户格式不正确,不过这 ...
- OC的构造方法与分类知识点总结
OC语言构造方法: 用来初始化对象的方法,对象方法,以减号开头 为了让对象创建出来,成员变量就会有一些固定的值 重写构造方法的注意点: 先调用父类的构造方法([super init]) 再进行子类内部 ...
- Kafka的常用管理命令
1. 查看kafka都有那些topic a. list/usr/hdp/current/kafka-broker/bin/kafka-topics.sh --list --zookeeper test ...
- white-space的值
white-space的值:normal 默认.空白会被浏览器忽略.pre 空白会被浏览器保留.其行为方式类似 HTML 中的 标签.nowrap 文本不会换行,文本会在在同一行上继续,直到遇到 标签 ...
- JavaScript重载解读
在JavaScript有一个特殊的数据类型---Function种类,JavaScript每个功能Function的类型,例如可以.由于函数是对象.指针,不会与某个函数绑定. <pre name ...