POJ-1003&1004

这两题比较简单,就不做分析了,描述下题目,就上代码吧。

【题目描述】

1003,其实就是求这个方程的最小n:1/2 + 1/3 + 1/4 + ... + 1/(n + 1) >= c;

1004,其实就是算个平均数,直接除12

【附:完整代码】

1003题:

/*
POJ-1003 Hangover
*/
#include <iostream>
using namespace std;

int main()
{
    double c;
    while(cin>>c)
    {
        if (c == 0.00)
            break;

        int n = 2;
        double sum = 0.0;
        while (true)
        {
            sum += 1.0 / (double)n;

            if (sum >= c)
            {
                cout<<n-1<<" card(s)"<<endl;
                break;
            }
            n++;
        }

    }

    return 0;
}

1004题:

/*
* POJ-1004 Financial Management
*/
#include <iostream>
using namespace std;

int main()
{
    double sum = 0.0;
    for (int month(1); month <= 12; month++)
    {
        double money;
        cin>>money;

        sum += money;
    }

    cout<<"$"<<sum/12.0<<endl;

    return 0;
}
时间: 2024-07-29 03:34:44

POJ-1003&1004的相关文章

poj 1003:Hangover(水题,数学模拟)

Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 99450   Accepted: 48213 Description How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We're as

SOJ 1002/1003/1004 大整数相加/相乘/相除

三个题目分别考察大整数相加相乘相除运算.如果按照传统算法是取一个长数组,之后进行模拟或者FFT来进行运算.但是相对繁琐. 后来昨天的青岛区域赛网赛1001,用到了JAVA的BigDecimal,于是反过来想到了这几个题目.用JAVA写了以后果然很简单. 1002:大数相加: AC代码: import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { // TO

URAL 1003,1004

1003: 并查集在处理矛盾关系的应用,讲的比较好的题解 #include <map> #include <set> #include <list> #include <queue> #include <stack> #include <cmath> #include <ctime> #include <vector> #include <bitset> #include <cstdio>

2016&quot;百度之星&quot; - 测试赛(热身,陈题)1001,1002,1003,1004

1001.大搬家 Accepts: 515 Submissions: 2005 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Description 近期B厂组织了一次大搬家,所有人都要按照指示换到指定的座位上.指示的内容是坐在位置ii上的人要搬到位置jj上.现在B厂有NN个人,一对一到NN个位置上.搬家之后也是一一对应的,改变的只有位次. 在第一次搬家后,度度熊由

poj 1003 Hangover

#include <iostream> using namespace std; int main() { double len; while(cin >> len && len) { double sum = 0.0; double i = 1.0; int n = 2; while(sum < len) { sum += i/n; ++n; } cout << n-2 << " card(s)" <<

[POJ] #1003# 487-3279 : 桶排序/字典树(Trie树)/快速排序

一. 题目 487-3279 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 274040   Accepted: 48891 Description Businesses like to have memorable telephone numbers. One way to make a telephone number memorable is to have it spell a memorable word or

POJ 1003 Hangover&amp;&amp;NYOJ 156 Hangover【数学题】

计算1+1/2+1/3+++1/n Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 104558   Accepted: 50926 Description How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a car

[POJ] #1003# Hangover : 浮点数运算

一. 题目 Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 116593   Accepted: 56886 Description How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (W

Hangover POJ - 1003

How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We're assuming that the cards must be perpendicular to the table.) With two cards you can make the top card overha

POJ 1003 Max Sum

Max Sum Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14. Input The first line of the input