ACM竞赛-516round4# 题解

一下题解 均由c++语言编写    c语言的话头三行改为一行#include<stdio.h>  把cin cout 输入输出改为scanf printf 格式   欢迎各位参加比赛 吐舌头

                           母牛的故事
有一头母牛,它每年年初生一头小母牛。每头小母牛从第四个年头开始,每年年初也生一头小母牛。请编程实现在第n年的时候,共有多少头母牛?
Input输入数据由多个测试实例组成,每个测试实例占一行,包括一个整数n(0<n<55),n的含义如题目中描述。 
n=0表示输入数据的结束,不做处理。Output对于每个测试实例,输出在第n年的时候母牛的数量。 
每个输出占一行。Sample Input
2
4
5
0
Sample Output
2
4
6

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,i;
    int a[60];
    a[0]=0;
    a[1]=1;
    a[2]=2;
    a[3]=3;
    a[4]=4;
   while(scanf("%lld",&n))
   {
     if(n==0)break;
     if(n<5)
        cout<<a[n]<<endl;
     else
     {
        for(i=5;i<=n;i++)
       {
          a[i]=a[i-1]+a[i-3];
        }
       cout<<a[n]<<endl;
    }
 }
return 0;
}

这一年的母牛数=去年的母牛数+三年前的母牛数;

统计给定的n个数中,负数、零和正数的个数。
Input输入数据有多组,每组占一行,每行的第一个数是整数n(n<100),表示需要统计的数值的个数,然后是n个实数;如果n=0,则表示输入结束,该行不做处理。Output对于每组输入数据,输出一行a,b和c,分别表示给定的数据中负数、零和正数的个数。Sample Input
6 0 1 2 3 -1 0
5 1 2 3 4 0.5
0 
Sample Output
1 2 3
0 0 5

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    double b;ll a,c,d,e;
    while(scanf("%lld",&a))
    {   c=0;d=0;e=0;
        if(a==0)break;
        while(a>0)
        {

            scanf("%lf",&b);
            if(b>0)d++;
            if(b<0)c++;
            if(b==0)e++;

            a--;
        }
        printf("%lld %lld %lld\n",c,e,d);
    }


}
数列的定义如下: 
数列的第一项为n,以后各项为前一项的平方根,求数列的前m项的和。
Input输入数据有多组,每组占一行,由两个整数n(n<10000)和m(m<1000)组成,n和m的含义如前所述。Output对于每组输入数据,输出该数列的和,每个测试实例占一行,要求精度保留2位小数。Sample Input
81 4
2 2
Sample Output
94.73
3.41

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll b,d,e;
    double c,a;
    while(~scanf("%lf %lld",&a,&b))
    {   c=a;
        for(int i=1;i<b;i++)
        {
            a=sqrt(a);
            c+=a;

        }
        printf("%.2lf\n",c);
    }
}

For a positive integer n let's define a function f:

f(n) =  - 1 + 2 - 3 + .. + ( - 1)nn

Your task is to calculate f(n) for a given integer n.

Input

The single line contains the positive integer n (1 ≤ n ≤ 1015).

Output

Print f(n) in a single line.

Example
Input
4
Output
2
Input
5
Output
-3
Note

f(4) =  - 1 + 2 - 3 + 4 = 2

f(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll a,b,c,d;
    scanf("%lld",&a);
    b=a/2;
    c=b-a;
    if(a%2==0)
    printf("%lld",b);
    else printf("%lld",c);



}












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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值