Hello World!

墨蓝 2022-08-18 02:35 368阅读 0赞

Hello World!

#

Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^

题目描述

We 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 whose row 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?

输入

The 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.

输出

For 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.

示例输入

  1. 3
  2. 1 2
  3. 2 3
  4. 2 3
  5. 0

示例输出

  1. Case 1:
  2. 2 3
  3. -1 -1
  4. -1 -1

提示

来源

2010年山东省第一届ACM大学生程序设计竞赛

示例程序

  1. #include <iostream>
  2. #include<string.h>
  3. #include<algorithm>
  4. using namespace std;
  5. struct point
  6. {
  7. int x;
  8. int y;
  9. };
  10. point p[1005];
  11. point p2[1005];
  12. int N;
  13. bool cmp(point a,point b)
  14. {
  15. if(a.x==b.x) return a.y<b.y;
  16. else return a.x<b.x;
  17. }
  18. void find(point p)
  19. {
  20. int i;
  21. if(p.x>p2[N-1].x && p.y>p2[N-1].y)
  22. {
  23. cout<<"-1 -1"<<endl;
  24. return;
  25. }
  26. for(i=0;i<N;++i)
  27. {
  28. if(p2[i].x>p.x && p2[i].y>p.y)
  29. {
  30. cout<<p2[i].x<<" "<<p2[i].y<<endl;
  31. return;
  32. }
  33. }
  34. cout<<"-1 -1"<<endl;
  35. }
  36. int main()
  37. {
  38. int count_case;
  39. count_case = 1;
  40. int i,j;
  41. while(cin>>N&&N)
  42. {
  43. for(int i = 0;i<N;i++)
  44. cin>>p[i].x>>p[i].y;
  45. memcpy(p2,p,sizeof(p));
  46. sort(p2,p2+N,cmp);
  47. cout<<"Case "<<count_case++<<":"<<endl;
  48. for(i = 0;i<N;i++)
  49. find(p[i]);
  50. cout<<endl;
  51. }
  52. return 0;
  53. }

发表评论

表情:
评论列表 (有 0 条评论,368人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Hello World

    Hello World 一、简述          简单的Hello World程序。(时间久了就会忘,趁着还有印象先记下)     1、C语言:  控制台程序、有窗体

    相关 Hello World

    这是我的第一篇博客,虽然是第一次写博客,但是之前也在微信公众号上写过一些文章(虽然没有阅读量),或多或少对自己产生了一定的帮助。 这些天会考虑将其中一些较为有意义的