ACM Sdut 2158 Hello World!(数学题,排序) (山东省ACM第一届省赛C题)
题目描述
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题)的更多相关文章
- 山东省第七届省赛 D题:Swiss-system tournament(归并排序)
Description A Swiss-system tournament is a tournament which uses a non-elimination format. The first ...
- 山东省第六届省赛 H题:Square Number
Description In mathematics, a square number is an integer that is the square of an integer. In other ...
- Sdut 2164 Binomial Coeffcients (组合数学) (山东省ACM第二届省赛 D 题)
Binomial Coeffcients TimeLimit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 输入 输出 示例输入 1 1 10 2 9 ...
- Sdut 2165 Crack Mathmen(数论)(山东省ACM第二届省赛E 题)
Crack Mathmen TimeLimit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Since mathmen take security ...
- Sdut 2151 Phone Numbers (山东省ACM第一届省赛题 A)
题目描述 We know thatif a phone number A is another phone number B's prefix, B is not able to becalled. ...
- Greatest Number 山东省第一届省赛
Greatest Number Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Saya likes math, because ...
- 山东省第六届省赛 BIGZHUGOD and His Friends II(赛瓦定理)
Description BIGZHUGOD and his three friends are playing a game in a triangle ground. The number of B ...
- ACM学习历程—HDU 5446 Unknown Treasure(数论)(2015长春网赛1010题)
Problem Description On the way to the next secret treasure hiding place, the mathematician discovere ...
- ACM学习历程——HDU5017 Ellipsoid(模拟退火)(2014西安网赛K题)
---恢复内容开始--- Description Given a 3-dimension ellipsoid(椭球面) your task is to find the minimal distanc ...
随机推荐
- ASP.NET中设置一个定时器来定时更新 转
asp.net 定时器 比较少用, 中国红木网这是一个相当实用的功能,有了RSS博客镜像,就不需要在多处同时发布博客日志了.比如你同时在新浪上有自己的博客,又同时有自己的个人博客站点,那么你只需要在 ...
- Linux中如何新建用户
对于一般用户来说,主目录(home directory)是硬盘上唯一可以原来写东西的地方.一般的路径名是/home/login_user_name. 主目录用于存储各种用户文件:设置文件,程序配置文件 ...
- Linq中Take、TakeWhile、Skip、SkipWhile的比较(转)
参考文章:http://blog.csdn.net/lxfzgg/article/details/20534281 Take() , , , , , , , , , }; ); //从第一个元素开始, ...
- FairScheduler的任务调度机制——assignTasks(续)
上一篇文章浅析了FairScheduler的assignTasks()方法,介绍了FairScheduler任务调度的原理.略过了最后一步通过JobScheduler获取Task时调用JobInPro ...
- 如何把select出来的一列数据放在第一个单元格
有如下表: STORE_ID | CUSTOMER_ID S001 | C001 S001 | C002 能不能把上表SELECT出来变成下面这种形式: ...
- Linux下l2tp客户端xl2tpd的安装配置
1.下载xl2tp http://pkgs.org/search/?query=xl2tp&type=smart选择相应的版本进行下载 2.安装xl2tp和ppp yum install xl ...
- 使用泛型简单封装NGUI的ScrollView实现滑动列表
懒,是老毛病了,周末跑了半马,跑完也是一通累,好久没锻炼了..也是懒的,有时都懒的写博客..最近看到项目中各种滑动列表框,本着要懒出水平来的原则,决定花点时间简单处理下(暂时未做列表太多时的优化):1 ...
- (转)tar 解压缩命令
tar -c: 建立压缩档案-x:解压-t:查看内容-r:向压缩归档文件末尾追加文件-u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个.下面的 ...
- asp.net mvc 两级分类联动方法示例
前台视图代码 <%:Html.DropDownList("AwardClassMainID","请选择")%> <%:Html.DropDow ...
- JavaBean中DAO设计模式介绍(转)
一.信息系统的开发架构 客户层-------显示层-------业务层---------数据层---------数据库 1.客户层:客户层就是客户端,简单的来说就是浏览器. 2.显示层:JSP/Ser ...