算法训练营1

C1  C++

#include<iostream>
using namespace std;
int main(){
   cout<<"hello world!"<<end1;
   return 0;
}
#include <iostream>
using namespace std;
int main (){
    const double pi=3.1415926;
    double r,c,s;
    cout<<"输入圆的半径:"; 
    cin<<r;
    c=2.0*pi*r;
    s=pi*r*r;
    cout<<"周长:"<<c<<endl;
    cout<<"面积:"<<s<<endl;
renturn 0;}
#include<iostream>
using namespace std ;
int () {
int year ;
cin>>year ;
if ((year%4==0&&year%100!=0)||year%400==0)
   cout<<"runjian"<<endl;
else 
   cout<<"pingnian"<<endl;
return 0;}

c2   算法入门

数据结构+算法=程序

· 2—1算法优劣  (栗子:斐波那契数列)

long double fib1(int n){
if(n<1)
  return -1;
else if (n=1||n==2)
  return 1;
else 
 return fibl(n-1)+fib2(n-2);
}
long double fib2(int n){
long double temp;
if(n<1)
 return -1;
long double *a=new long double [n+1];
a[1]=a[2]=1;
for (int i=3;i<=n;i++){
a[i]=a[i-1]+a[i+2];
cout<<a[j]<<endl;
}
temp=a[n];
deleta []a;
return temp;}

2-2.1贪心算法

double tmp=0.0;
int ans =0;
for(int i=0;i<n;i++){
tmp+=w[i];
if(tmp<=c)
ans++;
else 
break;}
cout<<ans<<endl;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值