Hello World!
2013-12-17 22:11
218 查看
DescriptionWe know that Ivan gives Saya three problems to solve (Problem F), and this is the first problem.“We need a programmer to help us for some projects. If you show us that you or one of your friends is able to program, you can pass the first hurdle.I will give you a problem to solve. Since this is the first hurdle, it is very simple.”We all know that the simplest program is the “Hello World!” program. This is a problem just as simple as the “Hello World!”In a large matrix, there are some elements has been marked. For every marked element, return a marked element whose row and column are larger than the showed element’s row and column respectively. If there are multiple solutions, return the element whoserow is the smallest; and if there are still multiple solutions, return the element whose column is the smallest. If there is no solution, return -1 -1.Saya is not a programmer, so she comes to you for help.Can you solve this problem for her?InputThe input consists of several test cases.The first line of input in each test case contains one integer N (0<N≤1000), which represents the number of marked element.Each of the next N lines containing two integers r and c, represent the element’s row and column. You can assume that 0<r, c≤300. A marked element can be repeatedly showed.The last case is followed by a line containing one zero.OutputFor each case, print the case number (1, 2 …), and for each element’s row and column, output the result. Your output format should imitate the sample output. Print a blank line after each test case.Sample Input
3
1 2
2 3
2 3
0Sample Output
Case 1:
2 3
-1 -1
-1 -1
//标程:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct ss{int x,y;}p[1010],dp[1010];bool cmp(ss a,ss b){if(a.x!=b.x) return a.x<b.x;else if(a.y!=b.y) return a.y<b.y;}int main(){//freopen("a.txt","r",stdin);int n,i,k=0,j;while(scanf("%d",&n),n){k++;printf("Case %d:\n",k);for(i=0;i<n;i++){scanf("%d%d",&p[i].x,&p[i].y);dp[i].x=p[i].x, dp[i].y=p[i].y;}sort(p,p+n,cmp);for(i=0;i<n;i++){for(j=0;j<n;j++){if(p[j].x>dp[i].x && p[j].y>dp[i].y){printf("%d %d\n",p[j].x,p[j].y);break;}}if(j==n) printf("-1 -1\n");}printf("\n");}return 0;}
相关文章推荐
- 代码分析二:泛型方法与反射
- HDU1527:取石子游戏(威佐夫博弈)
- 浅谈 Facade 模式
- 如果让Visual Studio 多个相关联的文件形成树形结构?
- 阔别三十天后每天一博客卷土重来——互动交流新思路(中)
- Python 处理数据库返回结果
- 数字逻辑复习第一天
- attachEvent、addEventListener、detachEvent、removeEventListener
- FusionCharts 使用手记
- icmpv6 checksum
- java 集合一个键对应多个值
- flex myeclipse安装.
- read方法读文件
- 回调、匿名函数、闭包在PHP中的应用
- Javascript浅谈之引用类型
- java里的MouseLisetener接口的使用过程==========需要用组件是来注册侦听器
- 阅读原著
- 创建和使用动态链接库 (C++)
- 中国天气网城市代码(JSON)获取实现(二)
- 从检测数据中获取一条最新的数据作为最终结果