您的位置:首页 > 其它

Hello World!

2013-12-17 22:11 218 查看
DescriptionWe 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 whoserow 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?InputThe 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.OutputFor 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
//标程:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct ss{int x,y;}p[1010],dp[1010];bool cmp(ss a,ss b){if(a.x!=b.x) return a.x<b.x;else if(a.y!=b.y) return a.y<b.y;}int main(){//freopen("a.txt","r",stdin);int n,i,k=0,j;while(scanf("%d",&n),n){k++;printf("Case %d:\n",k);for(i=0;i<n;i++){scanf("%d%d",&p[i].x,&p[i].y);dp[i].x=p[i].x, dp[i].y=p[i].y;}sort(p,p+n,cmp);for(i=0;i<n;i++){for(j=0;j<n;j++){if(p[j].x>dp[i].x && p[j].y>dp[i].y){printf("%d %d\n",p[j].x,p[j].y);break;}}if(j==n) printf("-1 -1\n");}printf("\n");}return 0;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: