H
来源:互联网 发布:双击屏幕唤醒软件 编辑:程序博客网 时间:2024/06/11 15:30
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?
“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.
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
31 22 32 30
Sample Output
Case 1:2 3-1 -1-1 -1
解题思路;
题意为对于输入的每对坐标寻找另一对行坐标和列坐标都比它大的坐标,如果没有输出-1 ,-1如果有多对则输出行坐标小的,如果行坐标也相同则输出列坐标小的,
代码:
#include <iostream>#include<string>#include<cstring>#include<vector>#include<algorithm>using namespace std;int main(){ int n,i,j,flag; int r[1001]; int c[1001]; int r1[1001]; int c1[1001]; int num=0; while(cin>>n) { num++; if(n==0) break; for(i=0;i<n;i++) {cin>>r[i];cin>>c[i];} for(i=0;i<=n;i++) { r1[i]=c1[i]=400; flag=0; for(j=0;j<=n;j++) { if(r[j]>r[i]&&c[j]>c[i]) { flag=1; if(r1[i]>r[j]) {r1[i]=r[j];c1[i]=c[j]; } if(r1[i]==r[j]&&c1[i]>c[j]) {r1[i]=r[j];c1[i]=c[j];} } } if(flag==0) r1[i]=c1[i]=-1; } cout<<"Case "<<num<<":"<<endl; for(i=0;i<n;i++) {cout<<r1[i]<<" "<<c1[i]<<endl;} cout<<endl; } return 0;}
0 0
- h
- h
- h
- ,h
- h
- h
- H
- h
- h
- h
- H
- h
- H
- H
- h
- H
- H
- h
- 在oschina踩的坑
- Java writer reader与相关练习
- imessage使用一
- Oracle(5)使用profile文件对口令进行管理
- Java实现字符与Unicode互转
- H
- Object类中clone()方法的修饰符为什么是protected
- 《易读》一个模仿网易云音乐UI,Rxjava+Retrofit+dagger2+MVP的开源项目
- 解决卡顿——在WPF中使用多线程更新UI
- AIDL实现进程间通信
- 转:提高系统性能的相关技术
- 利用Document读取和修改数据
- PyTorch 设置使用GPU
- 1x1卷积核作用