ACM Sdut 2158 Hello World!(数学题,排序) (山东省ACM第一届省赛C题)
来源:互联网 发布:淘宝店铺装修网站 编辑:程序博客网 时间:2024/06/06 03:41
题目描述
We know thatIvan gives Saya three problems to solve (Problem F), and this is the firstproblem.
“We need a programmer to help us for some projects. If you show us that youor 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 verysimple.”
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 markedelement, return a marked element whose row and column are larger than theshowed element’s row andcolumn respectively. If there are multiple solutions, return the element whoserow is the smallest; and if there are still multiple solutions, return theelement 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 inputconsists 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 rowand 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…), andfor each element’s rowand column, output the result. Your output format should imitate the sampleoutput. Print a blank line after each test case.
示例输入
3
1 2
2 3
2 3
0
示例输出
Case 1:
2 3
-1 -1
-1 -1
/************************************
在一个矩阵中有一些标记元素(行 r 和列 c ),找出比这些元素行,列下标大的标记元素的行和列并输出,如果有多个输出行最小的,行相同输出列最小的
简单的数学题,排序,因为每个元素有两个下标(r,c),以行(r)为主排序,若行(r)相同,则比较列(c)..然后判断一下就行。
**************************************/
Code:
#include <stdio.h>#include<algorithm>#include <string.h>using namespace std;struct Point // 定义一个 元素 (标记) 的结构体。{ int x; int y;}point[1005],p[1005];bool cmp(Point a,Point b){ if(a.x==b.x) return a.y<b.y; return a.x<b.x;}int main(){ int n,count_case = 1,i,j,k; while(scanf("%d",&n)&&n) { for(i = 0;i<n;i++) { scanf("%d%d",&point[i].x,&point[i].y); p[i].x = point[i].x;p[i].y = point[i].y;// 拷贝一份数据 } std::sort(p,p+n,cmp); // 将拷贝数据备份 printf("Case %d:\n",count_case++); for(i = 0;i<n;i++) { j = 0; while((point[i].x>=p[j].x||point[i].y>=p[j].y)&&j<n)// 遍历,如果标记元素 的 x y 比要显示的小 则继续,否则跳出循环 j++; if(j<n) printf("%d %d\n",p[j].x,p[j].y);// 找到了比 标记元素 的 x y 大的元素,输出 else printf("-1 -1\n");// 没找到,输出 -1 -1 } printf("\n"); } return 0;}
- ACM Sdut 2158 Hello World!(数学题,排序) (山东省ACM第一届省赛C题)
- 山东省ACM第一届省赛 Hello world
- 山东省第一届ACM省赛 H SDUT 2158 Hello World!(穷举)
- 山东省第一届ACM省赛 problem c Hello World!
- Sdut 2108 Alice and Bob(数学题)(山东省ACM第四届省赛D题)
- 山东省第一届ACM省赛 C SDUT 2153 Clockwise
- SDUT 2158 Hello World!(第一届山东省赛)
- Hello World! 2010年山东省第一届ACM大学生程序设计竞赛
- [2010山东省第一届ACM大学生程序设计竞赛]——Hello World!
- SDNU 1142.Hello World!【山东省第一届ACM】【7月21】
- 山东省第一届ACM大学生程序设计竞赛 hello world! 水模拟
- 2010年山东省第一届ACM大学生程序设计竞赛:Hello World!
- 山东省第一届ACM省赛 C SDUT 2153 Clockwise(dp+计算几何)
- Sdut 2151 Phone Numbers (山东省ACM第一届省赛题 A)
- 山东省第一届ACM省赛 D SDUT 2154 Shopping
- 山东省第一届ACM省赛 F SDUT 2156 Fairy tale
- 山东省第一届ACM省赛 J SDUT 2160 Jerry Mouse
- 山东省第四届ACM省赛 A SDUT 2603 Rescue The Princess(简单数学题)
- 第十三题 从上往下遍历二叉树
- Win32 框架文档视图(2)
- 如何修改和查看tomcat内存大小
- ghost 小记
- Win32 框架文档视图(3)
- ACM Sdut 2158 Hello World!(数学题,排序) (山东省ACM第一届省赛C题)
- VS2010 CString 转 const char *
- ubuntu12.04.4中在mysql控制台下通过命令设置编码
- The ideal length for everything on the Internet
- struts2实现CRUD(增 删 改 查)
- 原生JS生成动态select下拉框步骤
- Java 将字节数组转化为16进制的多种方案
- 关于查询FileNet PE中用户Inbox信息
- Visual C++ 光标