zoukankan      html  css  js  c++  java
  • 水题一大片

    Problem A: Eming

    Time Limit: 1 Sec   Memory Limit: 32 MB
    Submit: 28   Solved: 24
    [ Submit][ Status][ Web Board] [ Edit]

    Description

    Eming is a contest hold by WHUACM training team. The aim is to select new members of the team. 

    Usually, the first problem is a very simple problem such as “a+b problem”. But this time, Xioumu is tired of this kind of problem, he decide to solve “a and b problem”.

    Give you the result of a + b and a^2 – b^2, please output the result of a and b.

     

    Input

    There are several test cases. For each case there are two double numbers indicating a+b and a^2-b^2. You may assume that a+b will not be zero.

     

    Output

    For each case please output the result of a and b in one line, rounded to 2 decimal places.

     

    Sample Input

    3 -3

    Sample Output

    1.00 2.00

    HINT

    思路:简单题,直接A
    代码:
    #include<iostream>
    #include<stdio.h>
    using namespace std;
    int main()
    {
        float x,y;
        while(scanf("%f",&x)!=EOF)
        {
            scanf("%f",&y);
            float c=y/x;
            printf("%.2f %.2f
    ",(x+c)*0.5,(x-c)*0.5);
        }
        return 0;
    }
    

    Problem B: Arithmetic Progression

    Time Limit: 1 Sec   Memory Limit: 32 MB
    Submit: 54   Solved: 24
    [ Submit][ Status][ Web Board] [ Edit]

    Description

    “In mathematics, an arithmetic progression (AP) or arithmetic sequence is a sequence of numbers such that the difference between the consecutive terms is constant. For instance, the sequence 5, 7, 9, 11, 13, … is an arithmetic progression with common difference of 2.”

    Wikipedia

     

    This is a quite simple problem, give you the sequence, you are supposed to find the length of the longest consecutive subsequence which is an arithmetic progression.

     

    Input

    There are several test cases. For each case there are two lines. The first line contains an integer number N (1 <= N <= 100000) indicating the number of the sequence. The following line describes the N integer numbers indicating the sequence, each number will fit in a 32bit signed integer.

     

    Output

    For each case, please output the answer in one line.

     

    Sample Input

    61 4 7 9 11 14

    Sample Output

    3

    HINT

    思路:求最大等差数列长度,想清楚就可以做了。
    代码:
    #include<iostream>
    #include<stdio.h>
    #include<cstring>
    using namespace std;
    #define MAX 100005
    unsigned short num[MAX];
    unsigned short tnum[MAX];
    bool bnum[MAX];
    int main()
    {
        int n,i;
        while(scanf("%d",&n)!=EOF)
        {
            int m=-1,count=1,t=0,maxlong=0;
            for(i=1;i<=n;i++)
                scanf("%d",&num[i]);
            memset(tnum,0,sizeof(tnum));
            memset(bnum,0,sizeof(bnum));
            for(i=1;i<n;i++)
            {
                int temp=num[i+1]-num[i];
                //cout<<"temp="<<temp<<endl;
                if(temp==m)
                {
                    count++;
                    //cout<<"count="<<count<<endl;
                }
                else
                {
                    if(tnum[m]<count&&m!=-1)
                    {
                        bool f=true;
                        for(int j=1;j<=MAX;j++)
                            if(tnum[j]==count)
                                f=false;
                        tnum[m]=count;
                        if(f)
                        {
                            //cout<<m<<endl;
                            bnum[m]=true;
                        }
                    }
                    m=temp;
                    count=1;
                }
            }
            for(i=1;i<=MAX;i++)
            {
                //printf("%d  ",tnum[i]);
                if(maxlong<tnum[i])
                    maxlong=i;
                if(maxlong==tnum[i])
                    if(bnum[i])
                        maxlong=i;
            }
            //printf("
    ");
            printf("%d
    ",maxlong);
        }
    	return 0;
    }
    

    Problem E: Function

    Time Limit: 1 Sec   Memory Limit: 32 MB
    Submit: 52   Solved: 26
    [ Submit][ Status][ Web Board] [ Edit]

    Description

    Define a function f(n)=(f(n-1)+1)/f(n-2). You already got f(1) and f(2). Now, give you a number m, please find the value of f(m). 

     

    Input

    There are several test cases. Each case contains three integers indicating f(1), f(2) and m ( 1 <= f(1), f(2), m <= 1000,000,000). 

     

    Output

    For each case, please output the value of f(m), rounded to 6 decimal places. 

     

    Sample Input

    1 1 3

    Sample Output

    2.0000

    HINT

    思路:想啊想,看啊看,哇塞,数据怎么这么大o(╯□╰)o,1000000000,用数组都保存不了,怎么办?
    少年,不会做的还是试一试吧,你会发现惊喜的,最后发现所给数据是五个一循环,屌爆了,有木有!!!
    代码:
    #include<iostream>
    #include<stdio.h>
    using namespace std;
    double x=1,y=1;
    double function(int m)
    {
        if(m==1)
            return x;
        if(m==2)
            return y;
        else
            return (function(m-1)+1)/function(m-2);
    }
    int main()
    {
        //freopen("test.in", "r", stdin);
        //freopen("test.out", "w", stdout);
        int m;
        while(scanf("%lf",&x)!=EOF)
        {
            scanf("%lf%d",&y,&m);
            if(m%5==0)
                printf("%.6lf
    ",function(5));
            else
                printf("%.6lf
    ",function(m%5));
        }
    	return 0;
    }
    

    PS:暑假第一场训练,水题就这么多吧。
  • 相关阅读:
    jquery.stop()停止动画
    字符串转义
    CSS规范 (命名)- 分类方法
    inline-block 间距
    jquery中offset(),position()
    PHP把数组转换为JSON字符串
    json对象
    C#-静态实例
    C#-readonly与const区别
    SQL-事务隔离级别与锁
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3181727.html
Copyright © 2011-2022 走看看