东北林业大学OJ题目3

军训
Problem:103
Time Limit:1000ms
Memory Limit:65536K
Description
军训真累啊,但毕竟对我们的意志是一种考验。教官在军训时,碰到这样一个问题,N名同学,排成一排,有多少中排列方法?听说你是林大最聪明的人,请你帮他解决这个问题吧?
Input
输入数据有多组,每组1行,即N,代表学生数,其中1<=N<=15.
Output
输出N个同学的排列方法数对int的取模,每个输出占1行,记得输出要换行啊!
Sample Input
1
2
3
4
Sample Output
1
2
6
24
Hint
多组数据输入用while(scanf("%d",&n)!=EOF)
Source
chenyu

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,ans;
    while(cin>>n)
    {
        ans=1;
        for(int i=2;i<=n;i++)
        {
            ans=ans*i;
        }
        cout<<ans<<endl;
    }
    return 0;
}

求导 (函数题)
Problem:104
Time Limit:1000ms
Memory Limit:65536K
Description
大一的同学必须要注意,刚来林大的第一次考试是不及格最多的,因为大家都放松了警惕,最容易挂科的是高等数学,现在我们一起把数学复习一下。
已知函数f(x)=3x2+2x+4,
则它的导函数可以写成(f(x+h)-f(x))/(x+h-x),即f(x)的导可以表示为:
(f(x+h)-f(x))/h,现在给你x和h值,你会计算它的导数吗?
Input
输入数据有多组,每组1行,每行2个数x和h,这2个数是实数.
Output
按照题中的描述,输出f(x)的导数值,结果保留2位小数,记得用双精度(double)和换行啊!
Sample Input
2 0.1
4 0.1
Sample Output
14.30
26.30
Hint
输入数据多组用while(scanf("%lf%lf",&x,&h)!=EOF),x和h定义成double
Source

#include <bits/stdc++.h>

using namespace std;
double f(double x)
{
      return 3*x*x+2*x+4;
}
int main()
{
     double x,h;
    while(cin>>x>>h)
    {
        printf("%.2lf\n",(f(x+h)-f(x))/(x+h-x));
    }
    return 0;
}

整数–求和
Problem:106
Time Limit:1000ms
Memory Limit:65536K
Description
今年林大来了很多新同学,可他们都不会计算SUM(n) = 1 + 2 + 3 + … + n,你能帮他们算算吗?
Input
有多组数据,每组1行,即n的值。 (1≤n≤65535)
Output
输出sum(n)的值。
注意:sum(n)的结果最大为32位。
Sample Input
2
4
Sample Output
3
10
Hint
Source
陈宇

#include <bits/stdc++.h>

using namespace std;
int main()
{ int n,i,sum;
while(scanf("%d",&n)!=-1)
{ sum=0;
for(i=1;i<=n;i++)
sum=sum+i;
printf("%d\n",sum);
}
return 0;
}

整数–均值
Problem:107
Time Limit:1000ms
Memory Limit:65536K
Description
你会求均值吗?请将给出的数据求平均值~~
Input
输入数据有多组,每行开头是N,代表有N个整数,然后就是这N个整数了!N大于1且小于1000.
Output
输出每行这N个数的均值,保留2位小数。
Sample Input
3 2 1 3
9 1 4 7 2 5 8 3 6 9
Sample Output
2.00
5.00
Hint
Source
陈宇

#include <bits/stdc++.h>
using namespace std;

int main()
{
    double n,a[10000],ans;

    while(cin>>n)
    {
        ans=0;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        for(int i=1;i<=n;i++)
        {
            ans=ans+a[i];
        }
        ans=ans/n;
        printf("%.2lf\n",ans);
    }
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值