zoukankan      html  css  js  c++  java
  • 高空坠球 【物理】

    7-3 高空坠球(20 分)

    皮球从某给定高度自由落下,触地后反弹到原高度的一半,再落下,再反弹,……,如此反复。问皮球在第n次落地时,在空中一共经过多少距离?第n次反弹的高度是多少?
    输入格式:

    输入在一行中给出两个非负整数,分别是皮球的初始高度和n,均在长整型范围内。
    输出格式:

    在一行中顺序输出皮球第n次落地时在空中经过的距离、以及第n次反弹的高度,其间以一个空格分隔,保留一位小数。题目保证计算结果不超过双精度范围。
    输入样例:

    33 5

    输出样例:

    94.9 1.0

    思路

    模拟这个过程就可以了
    但是要注意 n == 0 的情况
    剩用 –n

    AC代码

    #include <cstdio>
    #include <cstring>
    #include <ctype.h>
    #include <cstdlib>
    #include <cmath>
    #include <climits>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <deque>
    #include <vector>
    #include <queue>
    #include <string>
    #include <map>
    #include <stack>
    #include <set>
    #include <numeric>
    #include <sstream>
    #include <iomanip>
    #include <limits>
    
    #define CLR(a) memset(a, 0, sizeof(a))
    #define pb push_back
    
    using namespace std;
    typedef long long ll;
    typedef long double ld;
    typedef unsigned long long ull;
    typedef pair <int, int> pii;
    typedef pair <ll, ll> pll;
    typedef pair<string, int> psi;
    typedef pair<string, string> pss;
    
    const double PI = 3.14159265358979323846264338327;
    const double E = exp(1);
    const double eps = 1e-30;
    
    const int INF = 0x3f3f3f3f;
    const int maxn = 1e5 + 5;
    const int MOD = 1e9 + 7;
    
    int main()
    {
        long double h;
        ll n;
        cin >> h >> n;
        if (n == 0)
            printf("0.0 0.0
    ");
        else
        {
            long double tot = h;
            while (--n)
            {
                h /= 2;
                tot += 2 * h;
            }
            h /= 2;
            printf("%.1Lf %.1Lf
    ", tot, h);
        }
    }
    
    
    
    
    
    
    
  • 相关阅读:
    Apache Ant自动化脚本
    使用Mybatis Generator结合Ant脚本快速自动生成Model、Mapper等文件的方法
    Maven Pom文件标签详解
    JAVA正则表达式语法大全
    RSA加密算法--Java实现详细案例:
    Java加密技术(一)——BASE64与单向加密算法MD5&SHA&MAC
    Base64算法的使用
    ElasticSearch使用IK中文分词---安装步骤记录
    ElasticSearch Java api 详解_V1.0
    HBase入门
  • 原文地址:https://www.cnblogs.com/Dup4/p/9433204.html
Copyright © 2011-2022 走看看