标签:
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.
示例输入
示例输出
提示
来源
2010年山东省第一届ACM大学生程序设计竞赛
示例程序
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
using namespace std;
struct node
{
int x;
int y;
}q[10010];
bool v[310][310];
vector<int>p[301];
int main()
{
int n;
int kk = 0;
while(scanf("%d",&n)!=EOF)
{
if(n == 0)
{
break;
}
for(int i=0;i<301;i++)
{
p[i].clear();
}
memset(v,false,sizeof(v));
int maxx = 0;
for(int i=0;i<n;i++)
{
scanf("%d%d",&q[i].x,&q[i].y);
if(q[i].x>maxx)
{
maxx = q[i].x;
}
p[q[i].x].push_back(q[i].y);
}
printf("Case %d:\n",++kk);
int t = 1;
for(int i=0;i<n;i++)
{
int flag = 0;
t = 1;
while(t+q[i].x<=maxx)
{
int maxy = 99999;
for(int j=0;j<p[t+q[i].x].size();j++)
{
if(p[t+q[i].x][j]<maxy && p[t+q[i].x][j]>q[i].y)
{
maxy = p[t+q[i].x][j];
}
}
if(maxy!=99999)
{
flag = 1;
printf("%d %d\n",t+q[i].x,maxy);
break;
}
t++;
}
if(flag == 0)
{
printf("-1 -1\n");
}
}
printf("\n");
}
return 0;
}
SDUT 2158 Hello World!(第一届山东省赛)
标签:
原文地址:http://blog.csdn.net/yeguxin/article/details/45315589