POJ 2656 Unhappy Jinjin
2015-07-18 21:31
323 查看
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
Sample Output
Hint
Here is a sample solution of this problem using C language:
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
Hint
Here is a sample solution of this problem using C language:
#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 = a + b; maxday = i; } } if (maxvalue <= 8) printf("0\n"); else printf("%d\n", maxday); } return 0; }#include<cstdio> #include<iostream> #include<cstring> #include<map> #include<queue> #include<stack> #include<algorithm> #include<cmath> #include<string> using namespace std; const int maxn=100005; int T,n,m,x,y; int main() { while (cin>>n,n) { int ans=-1,now=0; for (int i=1;i<=n;i++) { scanf("%d%d",&x,&y); if (x+y>max(8,ans)) { ans=x+y; now=i; } } printf("%d\n",now); } return 0; }
相关文章推荐
- android开发之调试技巧
- android开发之调试技巧
- android开发之调试技巧
- android开发之调试技巧 分类: android 学习笔记 2015-07-18 21:30 140人阅读 评论(0) 收藏
- IOS 学习路线
- 号称不会被查水表的通信APP-Telegram
- IOS开发-12.Autoresizing概述
- Android学习笔记之dispatchTouchEvent和OnInterceptTouchEvent和OnTouchEvent三个方法之间的联系...
- SWIFT中获取配置文件路径的方法
- 从 Objective-C 里的 Alloc 和 AllocWithZone 谈起
- IOS __attribute__ ((warn_unused_result))的含义
- [cocos2dx]抽象元素——CCAction动作类
- myeclipse运行applet乱码问题
- Android仿虾米音乐播放器之电话和耳机监听
- Cocos2d-x制作跳棋第四步:胜负判断、AI具体实现及实现特殊组合动作的小技巧
- [cocos2dx]可视元素——CCSprite精灵类
- 联想一体机BIOS设置U盘启动的方法
- [cocos2dx]可视元素——CCLayer图层类
- iOS开发:快速集成支付宝快捷支付
- IOS/Android WebRTC p2p浏览器视频 知识汇总