2014
11-29

# For

LMY is a mathematics lover. Now LMY likes to play matrix. LMY designs such a matrix problem. 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 original marked 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.
Of course LMY wants YY also like matrix. So she lets YY develop a program to solve the problem. But YY is very busy now. He should learn English for his enrollment examination for Ph.D. students. Could you help YY develop the program?

The input consists of multiple test cases. For each test case, the first line contains only one integer n. n ≤ 1000. Each of the next n lines describes a marked element’s row and column. A marked element’s row and column can be repeatedly showed. There is a blank line between two consecutive test cases.
End of input is indicated by a line containing a zero.

The input consists of multiple test cases. For each test case, the first line contains only one integer n. n ≤ 1000. Each of the next n lines describes a marked element’s row and column. A marked element’s row and column can be repeatedly showed. There is a blank line between two consecutive test cases.
End of input is indicated by a line containing a zero.

5
1 8
5 7
6 9
2 8
3 1

10
7 5
7 5
3 1
9 9
1 4
7 4
2 3
9 5
4 5
3 4

0

Case 1:
6 9
6 9
-1 -1
6 9
5 7

Case 2:
9 9
9 9
4 5
-1 -1
4 5
9 5
3 4
-1 -1
9 9
4 5

#include<iostream>
#include<string.h>
using namespace std;
const int maxn =1010;
struct matrix{
int x,y;
};
matrix ma[maxn];
int flag[maxn];
int main(){
//freopen("in.txt","r",stdin);
for(int n,cases=1;cin>>n && n!=0;cases++){
for(int i=0;i<n;i++)
cin>>ma[i].x>>ma[i].y;
cout<<(cases==1?"":"\n")<<"Case "<<cases<<":\n";
for(int i=0;i<n;i++){
int min,num=0;
memset(flag,0,sizeof(flag));
for(int j=0;j<n;j++){
if(ma[j].x>ma[i].x && ma[j].y>ma[i].y){
flag[j]=1;
num++;
min=j;
}
}
if(num==0)
cout<<"-1 -1\n";
else if(num==1)
cout<<ma[min].x<<" "<<ma[min].y<<"\n";
else{
for(int j=0;j<n;j++){
if(flag[j]==1 && ma[j].x<ma[min].x){
min=j;
}
}
num=0;
for(int j=0;j<n;j++){
if(flag[j]==1 && ma[j].x==ma[min].x){
num++;
flag[j]=2;
}
}
if(num ==1)
cout<<ma[min].x<<" "<<ma[min].y<<"\n";
else{
for(int j=0;j<n;j++){
if(flag[j]==2 && ma[j].y<ma[min].y)
min=j;
}
cout<<ma[min].x<<" "<<ma[min].y<<"\n";
}
}
}
}
}

1. #include <stdio.h>
int main(void)
{
int arr[] = {10,20,30,40,50,60};
int *p=arr;
printf("%d,%d,",*p++,*++p);
printf("%d,%d,%d",*p,*p++,*++p);
return 0;
}

为什么是 20,20,50,40,50. 我觉得的应该是 20,20,40,40,50 . 谁能解释下？

2. Good task for the group. Hold it up for every yeara??s winner. This is a excellent oppotunity for a lot more enhancement. Indeed, obtaining far better and much better is constantly the crucial. Just like my pal suggests on the truth about ab muscles, he just keeps obtaining much better.