POJ 2656

Unhappy Jinjin

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10819   Accepted: 7916

Description

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.

Input

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.

Output

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

7
5 3
6 2
7 2
5 3
5 4
0 4
0 6
1
4 4
0

Sample Output

3
0

CODE:
#include <iostream>
#include <cstdio>
#include <cstring>
#define REP(i, s, n) for(int i = s; i <= n; i ++)
#define REP_(i, s, n) for(int i = n; i >= s; i --)

using namespace std;

int main(){
    int n;
    while(scanf("%d", &n) != EOF){
        if(n == 0) break;
        int a, b, mx = 0, mxd;
        REP(i, 1, n){
            scanf("%d%d", &a, &b);
            if(a + b > mx){
                mx = a + b; mxd = i;
            }
        }
        if(mx > 8) printf("%d\n", mxd);
        else printf("0\n");
    }
    return 0;
}
				
时间: 2024-10-10 06:30:38

POJ 2656的相关文章

POJ 2656 Unhappy Jinjin(水题)

[题意简述]:找到两数之和最大的那一天. [分析]:这个....代码就贴在题目下啊. #include <stdio.h> int main(){ while(1) { int i, n; int maxday, maxvalue = -1; scanf("%d", &n); if (n == 0) break; for (i = 1; i <= n; i++) { int a, b; scanf("%d%d", &a, &

poj 2656 Unhappy Jinjin

#include <stdio.h> int main() { while(1) { int i, n; int maxday, maxvalue = -1; scanf("%d", &n); if (n == 0) break; for (i = 1; i <= n; i++) { int a, b; scanf("%d%d", &a, &b); if (a + b > maxvalue) { maxvalue =

POJ 3449 Geometric Shapes --计算几何,线段相交

题意: 给一些多边形或线段,输出与每一个多边形或线段的有哪一些多边形或线段. 解法: 想法不难,直接暴力将所有的图形处理成线段,然后暴力枚举,相交就加入其vector就行了.主要是代码有点麻烦,一步一步来吧. 还有收集了一个线段旋转的函数. Vector Rotate(Point P,Vector A,double rad){ //以P为基准点把向量A旋转rad return Vector(P.x+A.x*cos(rad)-A.y*sin(rad),P.y+A.x*sin(rad)+A.y*co

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

POJ 2195 Going Home 最小费用最大流 尼玛,心累

D - Going Home Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2195 Appoint description: Description On a grid map there are n little men and n houses. In each unit time, every little man can mo

POJ - 3186 Treats for the Cows (区间DP)

题目链接:http://poj.org/problem?id=3186 题意:给定一组序列,取n次,每次可以取序列最前面的数或最后面的数,第n次出来就乘n,然后求和的最大值. 题解:用dp[i][j]表示i~j区间和的最大值,然后根据这个状态可以从删前和删后转移过来,推出状态转移方程: dp[i][j]=max(dp[i+1][j]+value[i]*k,dp[i][j-1]+value[j]*k) 1 #include <iostream> 2 #include <algorithm&

POJ 2533 - Longest Ordered Subsequence(最长上升子序列) 题解

此文为博主原创题解,转载时请通知博主,并把原文链接放在正文醒目位置. 题目链接:http://poj.org/problem?id=2533 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN) be any sequence (ai1, ai2, ..., aiK)

POJ——T2271 Guardian of Decency

http://poj.org/problem?id=2771 Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5932   Accepted: 2463 Description Frank N. Stein is a very conservative high-school teacher. He wants to take some of his students on an excursion, but he is

POJ——T2446 Chessboard

http://poj.org/problem?id=2446 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18560   Accepted: 5857 Description Alice and Bob often play games on chessboard. One day, Alice draws a board with size M * N. She wants Bob to use a lot of c