SDNU 1142.Hello World!【山东省第一届ACM】【7月21】

Hello World!

Description

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?

Input

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.

Output

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.

Sample Input

3
1 2
2 3
2 3

0

Sample Output

Case 1:
2 3
-1 -1
-1 -1

依旧省赛题。给出N和点,找出横纵坐标都比当前点大的点。若有多个点,输出找到的第一个点,即横坐标(横坐标相同则为纵坐标)最小的点。一开始想用二维数组存该点是否已标记,确实也这么做了,发现既费空间,又费时间,果然TLE。要用更直接的方法:排序,查找。

正确思路:结构体存点(开两个,防止乱序),排序一个,遍历,输出。代码贴上:

#include<cstdio>
#include<algorithm>
using namespace std;
struct point{
    int x,y;
};
bool cmp(point x,point y){
    if(x.x<y.x)return true;
    else if(x.x==y.x&&x.y<y.y)return true;
    else return false;
}
int main(){
    int N,kase=0;
    while(scanf("%d",&N)==1&&N){
        point p1[1100],p2[1100];
        for(int i=0;i<N;i++){
            scanf("%d %d",&p1[i].x,&p1[i].y);
            p2[i].x=p1[i].x;
            p2[i].y=p1[i].y;
        }
        sort(p2,p2+N,cmp);
        printf("Case %d:\n",++kase);
        for(int i=0;i<N;i++){
            int j=0;
            while((p1[i].x>=p2[j].x||p1[i].y>=p2[j].y)&&j<N)
                j++;
            if(j<N) printf("%d %d\n",p2[j].x,p2[j].y);
            else printf("-1 -1\n");
        }
        printf("\n");
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-11 07:00:05

SDNU 1142.Hello World!【山东省第一届ACM】【7月21】的相关文章

SDNU 1143.Ivan comes again!【山东省第一届ACM】【7月21】

Ivan comes again! Description The Fairy Ivan gave Saya three problems to solve (Problem F). After Saya finished the first problem (Problem H), here comes the second. This is the enhanced version of Problem H. There is a large matrix whose row and col

山东省第一届ACM大学生程序设计竞赛(原题) 回顾 4.18

Phone Number 题目链接:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2151&cid=1172 题意很简单:给出N行电话号码,寻找有没有一串是另一串的前缀,有的话输出No,当然两个一样的也是No 题解:没有前缀0,直接用二维数组存,大循环就行了,用strcmp比较相等.不会超时. Hello World!     题目链接:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=215

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

题目大意: n个点,第i个点和第i+1个点可以构成向量,问最少删除多少个点可以让构成的向量顺时针旋转或者逆时针旋转. 分析: dp很好想,dp[j][i]表示以向量ji(第j个点到第i个点构成的向量)为终点的最大顺时针/逆时针向量数.状态转移方程为 dp[j][i] = max{dp[k][j]+1}. 问题个关键是如何判断2个向量是顺时针还是逆时针. 计算几何用的知识是求叉积和点积,叉积的作用是判断两个向量的左右(顺逆),点积的作用是判断两个向量的前后.举个例子,假设有2个向量v1,v2,‘*

山东省第一届acm程序设计竞赛题解

缺c 计算几何没看 f一个模拟,不想写,难度不大,J,因为时间挺早的,题目都比较简单,没什么难度,组队出个8题还是轻松的 A:水题 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn=1e3+5; 4 string s[maxn]; 5 6 bool judge(string s1,string s2){ 7 if(s1.length()>s2.length())return 1; 8 int len=s1.

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

题意 : 找联通块的个数,Saya定义两个相连是 |xa-xb| + |ya-yb| ≤ 1 ,但是Kudo定义的相连是 |xa-xb|≤1 并且 |ya-yb|≤1.输出按照两种方式数的联通块的各数.思路 : 按照第一种定义方式就只能是上下左右四个位置,而第二种则是周围那8个都是相连的. 1 #include <iostream> 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <queue> 5

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

先看看上一个题: 题目大意是: 矩阵中有N个被标记的元素,然后针对每一个被标记的元素e(x,y),你要在所有被标记的元素中找到一个元素E(X,Y),使得X>x并且Y>y,如果存在多个满足条件的元素,先比较X,选择X最小的那个,如果还是有很多满足条件的元素,再比较Y,选择Y最小的元素,如果不存在就输出两个-1: 分析: 直接暴力就行了 这个题目大意: 这个题是上个题的坚强版,每次会增加或减少一个点,仍然找到一个元素E(X,Y),使得X>x并且Y>y: 最多有200000次操作,每次只

Emergency(山东省第一届ACM程序设计真题+Floyd算法变型)

题目描述 Kudo's real name is not Kudo. Her name is Kudryavka Anatolyevna Strugatskia, and Kudo is only her nickname. Now, she is facing an emergency in her hometown: Her mother is developing a new kind of spacecraft. This plan costs enormous energy but f

我想要得那块牌—记烟台大学第一届&quot;ACM讲堂&quot;

2014年5月23日,烟台大学ACM实验室举办了第一届"ACM讲堂",演讲的主题是"我想要得那块牌",大二和大三的参赛队员以及三位指导老师都进行了演讲. 晚上七点开始,三个多小时的时间,我们经历了一个不平凡的晚上.在讲堂上,倾听着队员们与ACM的点点滴滴,那些曾经的故事,有过喜悦,有过忧伤,有想过放弃,但一直坚持了下来.队友和学长们的讲话真的很令人感动,那些话简单朴素,有些话是平常所不常听到的心里话,有好几次眼泪都在眼眶中打转.这次ACM讲堂对大三的学长们意义重大,

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

Identifiers Time Limit: 1000MS Memory limit: 65536K 题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2163 题目描写叙述 Identifier is an important concept in the C programming language. Identifiers provide names for several language