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 ...
随机推荐
- ACM 入门计划
acm 本文由swellspirit贡献 ACM • I can accept failure. but I can't accept not trying. Life is often compar ...
- python test0729.py
#!/usr/env python #-*- coding: utf-8 -*- import urllib import urllib2 import random import requests ...
- shell变量赋值进阶
首先,要理解shell中变量的3种赋值情况: unset 例子. unset a 空字符串, null 例子. a='' 非空,即不是unset,并且不是空字符串 例子: a=1 or a=b等 然后 ...
- Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds解
产生了一个解决这个问题的方法是在项目部署到tomcat比长45第二,当项目是比较大的,框架复杂的问题经常发生. 解决方法非常easy,找到以下这个路径中 workspace\.metadata\.pl ...
- 2014年辛星jquery解读第二节
*************jquery的语法****************** 1.jquery是通过选取HTML元素,而且对选取的元素运行某些操作,从而完毕某些特效的. 2.因此,我们在使用jQu ...
- Windows Phone 8.1 多媒体(3):音乐
原文:Windows Phone 8.1 多媒体(3):音乐 Windows Phone 8.1 多媒体(1):相片 Windows Phone 8.1 多媒体(2):视频 Windows Phone ...
- linux简单的数据包捕获分析
有时我们会遇到一些问题,需要捕捉数据包分析,当手头有没有专业的抓图工具,您可以使用tcpdump相反,看看(一般版本附带这个工具) 比如,我们要分析eth0与接口192.168.7.188 这个对象I ...
- Android Notification通知详细解释
Android Notification通知具体解释 Notification: (一).简单介绍: 显示在手机状态栏的通知. Notification所代表的是一种具有全局效果的通 ...
- PHP 调用微信JS-SDK 开发详解 [网摘]
一:准备文件,并将文件置于网站根目录下 access_token.json {"access_token":"","expire_time" ...
- s2sh三大框架整合过程(仅供参考)
三大框架顾名思义就是非常有名的Struts2 ,Hibernate,Spring, 框架整合的方法很多,现在我写一个非常简单的整合过程,相信大家一看就会! 这里使用的struts-2.2.1.1.hi ...