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. 使用KnockoutJs+Bootstrap实现分页

    [后端人员耍前端系列]KnockoutJs篇:使用KnockoutJs+Bootstrap实现分页   一.引言 由于最近公司的系统需要改版,改版的新系统我打算使用KnockoutJs来制作Web前端 ...

  2. currentstyle和getComputedStyle兼容问题

    currentStyle:获取计算后的样式,也叫当前样式.终于样式. 长处:能够获取元素的终于样式,包含浏览器的默认值,而不像style仅仅能获取行间样式,所以更经常使用到. 注意:不能获取复合样式如 ...

  3. 使用 sphinx 制作简洁而又美观的文档

    使用 sphinx 制作简洁而又美观的文档 使用 sphinx 制作简洁而又美观的文档

  4. [android]APP启动界面——SplashActivity

    概念 当前应用程序在启动的时候都会有一个展示自己公司LOGO和APP名字的界面.这个界面成为SplashActivity. 布局 <? xml version="1.0" e ...

  5. SQL语句查询数据库的触发器、存储过程、视图以及表的SQL语句

    Sql Server数据库用SQL语句查询方法如下: select name from sysobjects where xtype='TR' --所有触发器 select name from sys ...

  6. 啊我V办我偶看篇未改片考i

    http://pan.baidu.com/share/link?shareid=3011665141&uk=338692646&third=15                http ...

  7. java单例模式(线程安全,效率高,双重推断)

    这样的方法,在获取单利的时候,避免了线程锁,导致訪问该方法速度非常慢, 同是,防止了多线程同事房屋该方法就会产生多个实例的问题. 效率高.线程安全. public class TestInstance ...

  8. SEAndroid安全机制中的进程安全上下文关联分析

    前面一篇文章分析了文件安全上下文关联过程.可是在SEAndroid中,除了要给文件关联安全上下文外,还须要给进程关联安全上下文.由于仅仅有当进程和文件都关联安全上下文之后,SEAndroid安全策略才 ...

  9. 创建和关联内容数据库到指定Web应用程序和站点集

    创建和关联内容数据库到指定Web应用程序和站点集         一个Web应用程序不限于使用单个内容数据库.SharePoint同意你关联多个内容数据库到Web应用程序.原因之中的一个是基于内容数据 ...

  10. malloc一次性最大能申请多大内存空间

    受用户态内存地址空间的限制.64 位系统下分配几个 T 不成问题. 著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处.作者:zz matrix链接:http://www.zhihu. ...