sdut 2158:Hello World!(第一届山东省省赛原题,水题,穷举)
Hello World!
Time Limit: 1000MS Memory limit: 65536K
题目描述
“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 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.
输出
示例输入
3
1 2
2 3
2 3 0
示例输出
Case 1:
2 3
-1 -1
-1 -1
提示
来源
简单题,穷举即可。
代码:
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
int n;
int Count =;
while(cin>>n){
if(n==) break;
int a[][]={};
int r[]={};
int c[]={};
int MaxR=,MaxC=;
for(int i=;i<=n;i++){
cin>>r[i]>>c[i];
a[r[i]][c[i]] = ;
if(r[i]>MaxR)
MaxR = r[i];
if(c[i]>MaxC)
MaxC = c[i];
}
cout<<"Case "<<Count++<<':'<<endl;
for(int i=;i<=n;i++){
int R = r[i],C = c[i];
int j,k;
if(R+>MaxR || C+>MaxC){
cout<<-<<' '<<-<<endl;
continue;
}
for(j=R+;j<=MaxR;j++)
for(k=C+;k<=MaxC;k++)
if(a[j][k]==)
goto label;
label:
if(j>MaxR && k>MaxC)
cout<<-<<' '<<-<<endl;
else
cout<<j<<' '<<k<<endl;
}
cout<<endl;
}
return ;
}
Freecode : www.cnblogs.com/yym2013
sdut 2158:Hello World!(第一届山东省省赛原题,水题,穷举)的更多相关文章
- sdut 2154:Shopping(第一届山东省省赛原题,水题)
Shopping Time Limit: 1000MS Memory limit: 65536K 题目描述 Saya and Kudo go shopping together.You can ass ...
- sdut 2152:Balloons(第一届山东省省赛原题,DFS搜索)
Balloons Time Limit: 1000MS Memory limit: 65536K 题目描述 Both Saya and Kudo like balloons. One day, the ...
- sdut 2153:Clockwise(第一届山东省省赛原题,计算几何+DP)
Clockwise Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Saya have a long necklace with ...
- sdut 2163:Identifiers(第二届山东省省赛原题,水题)
Identifiers Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Identifier is an important c ...
- sdut 2159:Ivan comes again!(第一届山东省省赛原题,STL之set使用)
Ivan comes again! Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 The Fairy Ivan gave Say ...
- sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)
The Android University ACM Team Selection Contest Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里 ...
- sdut 2165:Crack Mathmen(第二届山东省省赛原题,数论)
Crack Mathmen Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Since mathmen take securit ...
- sdut 2610:Boring Counting(第四届山东省省赛原题,划分树 + 二分)
Boring Counting Time Limit: 3000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 In this problem you a ...
- sdut 2411:Pixel density(第三届山东省省赛原题,字符串处理)
Pixel density Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Pixels per inch (PPI) or pi ...
随机推荐
- windows 磁盘加密
windows 磁盘加密 CreateTime--2018年4月25日18:37:45 Author:Marydon 以win10为例 选中磁盘-->你会发现上面的管理BitLocker是置 ...
- 利用端口映射解决:拥有公网IP有限,内网需要访问因特网
动态端口映射: 内网中的一台电脑要访问新浪网,会向NAT网关发送数据包,包头中包括对方(就是新浪网)IP.端口和本机IP.端口,NAT网关会把本机IP.端口替换成自己的公网IP.一个未使用的端口, ...
- Android系统示例之ActionBarCompat
导入工程ActionBarCompat时,出现错误.从其他工程下拷贝project.propertiest文件过来,问题仍在.拷贝后需要重启Eclipse才解决.问题如下: [2013-07-03 1 ...
- Android程序完全退出
有几个activity,有一需求是在一个activityA点击back键退出系统而不是跳到之前的activity 首先想到的是清空activityA的堆栈,使用intent.setFlag ...
- MPEG-4 压缩编码标准
文章转自:http://www.cnblogs.com/CoderTian/p/8477021.html 1.MPEG-4标准概述 与MPEG1和MPEG2标准相比,MPEG-4 更加注重多媒体系统的 ...
- redis骚操作
1.批量删除key redis-cli -h 127.0.0.1 -p 6379 -n 2 -a sdongpo123 keys '*form_id*' | xargs redis-cli -h 12 ...
- Python partition() 方法
描述 Python partition() 方法用来根据指定的分隔符将字符串进行分割. 如果字符串包含指定的分隔符,则返回一个3元的元组,第一个为分隔符前面的子字符串,第二个为分隔符本身,第三个为分隔 ...
- Hive 指定分隔符,将表导出到本地
hive表的数据源有四种: hbase hdfs 本地 其他hive表 而hive表本身有两种: 内部表和外部表. 而hbase的数据在hive中,可以建立对应的外部表(参看hive和hbase整合) ...
- spring in action 8.1 使用Spring web flow
一.说明 Spring Web Flow是spring MVC的扩展,它支持基于流程的应用程序,他将流程的定义和实现流程行为的类和视图分离开来. 1.1 spring中配置web flow,目前需要在 ...
- blender, knife工具
点击Knife按钮开始切割,MLB在边上确认分割点,return键完成切割,MRB取消切割(这些在窗口下面的信息提示栏中都有写,如图中如示).