POJ1003, Hangover

链接:http://poj.org/problem?id=1003

题目很无语。。直觉告诉我这样叠一定会倒掉。。。

懒得算就用了查表,导致内存占用252K。。。好吧,水水更健康~

Memory: 252K    Time: 0MS

#include <iostream>

using namespace std;

double index[276] = {0.500000, 0.833333, 1.083333, 1.283333, 1.450000, 1.592857, 1.717857, 1.828968, 1.928968, 2.019877, 2.103211, 2.180134, 2.251562, 2.318229, 2.380729, 2.439553, 2.495108, 2.547740, 2.597740, 2.645359, 2.690813, 2.734292, 2.775958, 2.815958, 2.854420, 2.891457, 2.927171, 2.961654, 2.994987, 3.027245, 3.058495, 3.088798, 3.118210, 3.146781, 3.174559, 3.201586, 3.227902, 3.253543, 3.278543, 3.302933, 3.326743, 3.349999, 3.372726, 3.394948, 3.416687, 3.437964, 3.458797, 3.479205, 3.499205, 3.518813, 3.538044, 3.556912, 3.575430, 3.593612, 3.611469, 3.629013, 3.646255, 3.663204, 3.679870, 3.696264, 3.712393, 3.728266, 3.743891, 3.759276, 3.774427, 3.789352, 3.804058, 3.818551, 3.832837, 3.846921, 3.860810, 3.874509, 3.888022, 3.901356, 3.914514, 3.927501, 3.940321, 3.952979, 3.965479, 3.977825, 3.990020, 4.002068, 4.013973, 4.025738, 4.037366, 4.048860, 4.060224, 4.071459, 4.082571, 4.093560, 4.104429, 4.115182, 4.125820, 4.136346, 4.146763, 4.157072, 4.167277, 4.177378, 4.187378, 4.197279, 4.207082, 4.216791, 4.226407, 4.235930, 4.245364, 4.254710, 4.263969, 4.273144, 4.282235, 4.291244, 4.300172, 4.309022, 4.317794, 4.326489, 4.335110, 4.343657, 4.352132, 4.360535, 4.368868, 4.377133, 4.385329, 4.393460, 4.401524, 4.409524, 4.417461, 4.425335, 4.433147, 4.440899, 4.448591, 4.456225, 4.463801, 4.471319, 4.478782, 4.486190, 4.493543, 4.500842, 4.508088, 4.515282, 4.522425, 4.529517, 4.536560, 4.543553, 4.550497, 4.557394, 4.564243, 4.571046, 4.577803, 4.584514, 4.591181, 4.597803, 4.604382, 4.610918, 4.617412, 4.623863, 4.630273, 4.636643, 4.642972, 4.649261, 4.655511, 4.661722, 4.667895, 4.674030, 4.680128, 4.686188, 4.692212, 4.698201, 4.704153, 4.710070, 4.715952, 4.721800, 4.727614, 4.733395, 4.739142, 4.744856, 4.750538, 4.756188, 4.761806, 4.767392, 4.772948, 4.778473, 4.783967, 4.789432, 4.794866, 4.800272, 4.805648, 4.810996, 4.816315, 4.821606, 4.826869, 4.832105, 4.837313, 4.842494, 4.847649, 4.852777, 4.857879, 4.862955, 4.868006, 4.873031, 4.878031, 4.883006, 4.887957, 4.892883, 4.897785, 4.902663, 4.907517, 4.912348, 4.917156, 4.921940, 4.926702, 4.931442, 4.936159, 4.940853, 4.945526, 4.950177, 4.954807, 4.959415, 4.964003, 4.968569, 4.973114, 4.977639, 4.982144, 4.986628, 4.991092, 4.995537, 4.999961, 5.004367, 5.008753, 5.013119, 5.017467, 5.021796, 5.026107, 5.030399, 5.034672, 5.038927, 5.043165, 5.047384, 5.051586, 5.055770, 5.059936, 5.064086, 5.068218, 5.072333, 5.076432, 5.080513, 5.084578, 5.088627, 5.092659, 5.096675, 5.100675, 5.104659, 5.108628, 5.112580, 5.116517, 5.120439, 5.124345, 5.128236, 5.132112, 5.135973, 5.139819, 5.143651, 5.147467, 5.151270, 5.155058, 5.158831, 5.162590, 5.166336, 5.170067, 5.173785, 5.177488, 5.181178, 5.184855, 5.188518, 5.192167, 5.195804, 5.199427, 5.203037};

int calcCoins(double input)
{
    int i;
    double minus;

    for (i = 0; i < 276; i++)
    {
        minus = index[i] - input;
        if (minus > 0.0000001)
            break;
    }

    return (i + 1);
}

int main(void)
{
    double input;
    cin >> input;
    while ((input > 0.0000001) || (input < -0.0000001))
    {
        cout << calcCoins(input) << " card(s)" << endl;
        cin >> input;
    }
    return 0;
}

posted on 2012-07-09 23:06  lltctt  阅读(149)  评论(0)    收藏  举报

导航