Wednesday, February 23, 2011


Problem Links:


Unhappy Jinjin
Time Limit: 1000MSMemory Limit: 65536K
Total Submissions: 8014Accepted: 5933
Jinjin is a junior school student. Besides the classes in school, Jinjin's mother also arranges some supplementary classes for her. However, if Jinjin studies for more than eight hours a day, she will be unhappy on that day. On any day she gets unhappy, the more time she studies, the unhappier she will be. Now we got Jinjin's class schedule for the next several days and your task is to find out whether she will be unhappy on these days; if she will be unhappy, on which day she will be the unhappiest.
There may be several test cases. In the first line of each test case, there is an integer N (1 <= N <= 7), which represents the number of days you should analyze. Then there comes N lines, each contains two non-negative integers (each smaller than 10). The first integer represents how many hours Jinjin studies at school on the day, and the second represents how many hours she studies in the supplementary classes on the same day. A case with N = 0 indicates the end of the input, and this case should not be processed.

For each test case, output a line contains a single integer. If Jinjin will
always be happy, the integer should be 0; otherwise, the integer should
be a positive integer K, which means that Jinjin will be the unhappiest
on the K-th day. If the unhappiest day is not unique, just output the
earliest one among these unhappiest days.

Sample Input
5 3
6 2
7 2
5 3
5 4
0 4
0 6
4 4
Sample Output
NOIP 2004


Source Code:

//Thu Feb 24 00:45:51 CST 2011
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

int main(int argc, const char* argv[]) {
    //freopen("", "r", stdin);
    //freopen("output.out", "w", stdout);
    int N;
    while (cin >> N && N) {
        int a, b;
        int max = 0;
        int idx = 0;
        for (int i = 0; i < N; i++) {
            cin >> a >> b;
            if (max < a + b) {
                idx = i + 1;
                max = a + b;
        if (max <= 8)
            cout << 0 << endl;
            cout << idx << endl;
    return 0;

No comments :