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 ...
随机推荐
- 大数据系列修炼-Scala课程06
关于Scala中的正则表达式与模式匹配结合的正则表达式Reg 正则表达式的实现:正则表达式的定义与其它语言差不多,只需在表达式后加一个.r,并且可以遍历相应的表达式进行匹配 //定义的正则表达式 va ...
- 阅读小记3(《C编程专家》)
gets()不检查缓冲区空间.多余的字符将覆盖原来的栈的内容. fgets()的第二个參数说明最大读入的字符数. 假设这个參数值为n,那么fgets()就会读取最多n-1个字符或读完一个换行符为止.两 ...
- csdn 博客,你很努力,有人帮你-2015年03一个月17日本
今天泛化 开始使用简书 正则表达式的博客写了两篇文章 回顾 Core Data 基本使用 总结 Xcode6新特性 简单聊聊 简书,事实上一開始学 MarkDown 语法的时候,已经用了,但是,一直认 ...
- CSharp设计模式读书笔记(11):外观模式(学习难度:★☆☆☆☆,使用频率:★★★★★)
定义: 外观模式:为子系统中的一组接口提供一个统一的入口.外观模式定义了一个高层接口,这个接口使得这一子系统更加容易使用. 模式角色与结构: 示例代码: using System; using Sys ...
- PsExec.exe执行远程程序
PsExec.exe \\192.168.1.1 -u username -p password -i -d -s c:\Windows\system32\NETSTAT.exe -a
- Android游戏开发研究与主角在地图滚动
让人感动的地图过程平滑滚动 玩过rpg朋友应该都知道RPG的游戏地图一般都比較大 今天我和大家分享一下在RPG游戏中怎样来处理超出手机屏幕大小的游戏地图. 如图所看到的为程序效果 ...
- POJ 3311 Hie with the Pie floyd+状压DP
链接:http://poj.org/problem?id=3311 题意:有N个地点和一个出发点(N<=10),给出全部地点两两之间的距离,问从出发点出发,走遍全部地点再回到出发点的最短距离是多 ...
- php 基础算法(用*表示金字塔)通过hash 比較两个数组同样的数
当作为一名php 程序猿,每天总与数据库打交道,做着最底层的程序猿的工作,開始着手研究一些算法,希望自己能在计算机的道路上走的更远.事实上我更喜欢管理,希望自己能作为一个卓越的管理者,但并不影响我对技 ...
- Ejb in action(七)——message与JMS
我们扩大MDBs学前,我们需要理解message(新闻)与JMS(Java Message Service)的概念. 我们在Java EE中谈论消息,实际上就是意味着实现一个松耦合的过程.系统组件之间 ...
- Appium Android Bootstrap源码分析之命令解析执行
通过上一篇文章<Appium Android Bootstrap源码分析之控件AndroidElement>我们知道了Appium从pc端发送过来的命令如果是控件相关的话,最终目标控件在b ...