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.

示例输入

3
1 2
2 3
2 3 0

示例输出

Case 1:
2 3
-1 -1
-1 -1
#include<iostream>
#include<algorithm>
using namespace std;
struct T
{ int w,l,s;
}a[5010];
bool cmp(T a,T b)
{
if(a.l==b.l)
return a.w<b.w;
return a.l<b.l; }
int main()
{
bool p;
int i,j,n,k=1,m;
while(cin>>n&&n)
{ p=0;
for(i=0;i<n;i++)
{cin>>a[i].l>>a[i].w;a[i].s=i;}
sort(a,a+n,cmp);
// cout<<endl;
cout<<"Case "<<k<<':'<<endl;
k++;
for(j=0;j<n;j++)
{p=0;
for(i=0;i<n;i++)
{if(a[i].s==j)
{
for(m=i+1;m<n;m++)
if(a[m].l>a[i].l&&a[m].w>a[i].w)
{cout<<a[m].l<<' '<<a[m].w<<endl;p=1;break;}
if(p==0)
{cout<<-1<<' '<<-1<<endl;break;} }}
}
cout<<endl;
} return 0;
}

Hello World! 2010年山东省第一届ACM大学生程序设计竞赛的更多相关文章

  1. sdut 2153 Clockwise (2010年山东省第一届ACM大学生程序设计竞赛)

    题目大意: n个点,第i个点和第i+1个点可以构成向量,问最少删除多少个点可以让构成的向量顺时针旋转或者逆时针旋转. 分析: dp很好想,dp[j][i]表示以向量ji(第j个点到第i个点构成的向量) ...

  2. sdut 2159 Ivan comes again!(2010年山东省第一届ACM大学生程序设计竞赛) 线段树+离散

    先看看上一个题: 题目大意是: 矩阵中有N个被标记的元素,然后针对每一个被标记的元素e(x,y),你要在所有被标记的元素中找到一个元素E(X,Y),使得X>x并且Y>y,如果存在多个满足条 ...

  3. 2010年山东省第一届ACM大学生程序设计竞赛 Balloons (BFS)

    题意 : 找联通块的个数,Saya定义两个相连是 |xa-xb| + |ya-yb| ≤ 1 ,但是Kudo定义的相连是 |xa-xb|≤1 并且 |ya-yb|≤1.输出按照两种方式数的联通块的各数 ...

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

    Phone Number Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that if a phone number A is anothe ...

  5. [2011山东省第二届ACM大学生程序设计竞赛]——Identifiers

    Identifiers Time Limit: 1000MS Memory limit: 65536K 题目:http://acm.sdut.edu.cn/sdutoj/problem.php?act ...

  6. Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)

    Alice and Bob Time Limit: 1000ms   Memory limit: 65536K 题目描述 Alice and Bob like playing games very m ...

  7. 2013年山东省第四届ACM大学生程序设计竞赛-最后一道大水题:Contest Print Server

    点击打开链接 2226: Contest Print Server Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 53  Solved: 18 [Su ...

  8. 山东省第四届ACM大学生程序设计竞赛解题报告(部分)

    2013年"浪潮杯"山东省第四届ACM大学生程序设计竞赛排名:http://acm.upc.edu.cn/ranklist/ 一.第J题坑爹大水题,模拟一下就行了 J:Contes ...

  9. [2012山东省第三届ACM大学生程序设计竞赛]——n a^o7 !

    n a^o7 ! 题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2413 Time Lim ...

随机推荐

  1. hadoop深入研究:(七)——压缩

    转载请标明出处:hadoop深入研究:(七)——压缩 文件压缩主要有两个好处,一是减少了存储文件所占空间,另一个就是为数据传输提速.在hadoop大数据的背景下,这两点尤为重要,那么我现在就先来了解下 ...

  2. onkeypress事件.onkeydown事件.onkeyup事件

    onkeypress事件是在按键開始按的时候发生: onkeydown事件是在按键已经按下的时候发生: onkeyup事件是在按键松开(释放)的时候发生.

  3. Loser应该知道的6个残酷人生事实(血泪翻译)

    Loser应该知道的6个残酷人生事实(血泪翻译) - Acfun - 天下漫友是一家 Loser应该知道的6个残酷人生事实(血泪翻译)

  4. RSD和wlwmanifest是什么

    今天小博发现header.php文件里<?php wp_head(); ?>显示有以下的两句代码,因为小博的网站打开速度实在太慢了,换空间怕麻烦,那就只有优化代码了. <link r ...

  5. hdu 5282 Senior&#39;s String 两次dp

    题链:http://acm.hdu.edu.cn/showproblem.php?pid=5282 Senior's String Time Limit: 2000/1000 MS (Java/Oth ...

  6. redhat linux 5上创建本地yum源

    1.挂载光驱 [root@rh5rac1 ~]#mkdir -p /mnt/cdrom [root@rh5rac1 ~]#mount /dev/cdrom /mnt/cdrom 2.将redhat光盘 ...

  7. 【甘道夫】Win7x64环境下编译Apache Hadoop2.2.0的Eclipse小工具

    目标: 编译Apache Hadoop2.2.0在win7x64环境下的Eclipse插件 环境: win7x64家庭普通版 eclipse-jee-kepler-SR1-win32-x86_64.z ...

  8. SQL SERVER IN参数化处理

    方法一. CREATE TABLE [dbo].[Users] ( Id INTEGER IDENTITY(1, 1) PRIMARY KEY , Name NVARCHAR(50) NOT NULL ...

  9. Android中目的地Intent的使用

    一.什么是Intent? Intent的中文意思是目的.在Android中也是“目的”的意思.就是我们要去哪里,从这个activity要前往另一个Activity就需要用到Intent. 示例代码一: ...

  10. Windows Phone开发(42):缓动动画

    原文:Windows Phone开发(42):缓动动画 前面在讨论关键帧动画的时候,我有意把几个带缓动动画的关键帧动画忽略掉,如EasingColorKeyFrame.EasingDoubleKeyF ...