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

本文介绍了一个简单的编程问题:在一个大型矩阵中寻找特定路径。对于每个标记的元素,任务是找到一个其行和列都大于当前元素的解决方案。如果存在多个解,则选择行最小的;若仍有多个解,则选择列最小的。若无解则返回特定值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


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<N1000), 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,c300. 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;
}

转载于:https://www.cnblogs.com/oversea201405/p/3766941.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值