SDUT 2409:The Best Seat in ACM Contest
The Best Seat in ACM Contest
Time Limit: 1000MS Memory limit: 65536K
题目描述
Cainiao is a university student who loves ACM contest very much. It is a festival for him once when he attends ACM Asia Regional Contest because he always can find some famous ACMers there.
Cainiao attended Asia Regional Contest Fuzhou Site on November 20, 2011. After he got seat map, he wanted to know which seat is the best one.
Cainiao have joined so many QQ Group about ACM/ICPC that he is almost familiar with the strength of each team. In his mind, the value of a seat is defined as following:
1. Strength of each team can be expressed as a positive integer.
2. The value of a seat is related to the adjacent seat (up/down/left/right, only four directions being considering).
3. For an adjacent seat, if the strength of this team is stronger than yours, the absolute value of difference of two teams should be added to your seat, otherwise, the absolute value of difference should be subtracted from your seat.
4. If the adjacent seat is empty (which means you are located at the most left/right/up/down), the value of your seat should be subtracted 1.
5. The best one in a contest is the seat that has the highest value.
6. The initial value of the seat is ZERO.
For example, there are 12 ( 3 X 4 ) teams in a contest, the strength of each team is as figure (a), and then you can calculate the value of each seat as figure (b).
输入
Input contain a positive integer T( T <=50 ) in the first line, which means T cases.
The first line of each case contains two positive integers N and M (3 <= N, M <= 20) which means the row and column number of the teams, then N rows following, each line contains M positive integers that represent the strengths of the teams.
输出
For each case, first output the case number, and then output the value and row number and column number of the best seat in one line for each case.
If there are multiple solutions for one case, you should output the seat whose row number is largest and only output the seat whose column number is largest if still overlapping.
示例输入
1
3 4
1 5 3 4
6 3 3 4
4 3 2 1
示例输出
Case 1: 7 1 1
每一块的数字等于它周围四个块的和-4*当前块!边界以外块的值=其相邻-1;
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
int T;
cin>>T;
int a[105][105],bb[105][105];
for(int i=1;i<=T;i++)
{
memset(a,0,sizeof(a));
memset(bb,0,sizeof(bb));
int n,m;
cin>>n>>m;
for(int j=1;j<=n;j++)
for(int k=1;k<=m;k++)
{
cin>>a[j][k];
if(j==1)a[j-1][k]=a[j][k]-1;
if(j==n)a[j+1][k]=a[j][k]-1;
if(k==1)a[j][k-1]=a[j][k]-1;
if(k==m)a[j][k+1]=a[j][k]-1;
}
int maxx=0,mi=0,mj=0;
for(int j=1;j<=n;j++)
{
for(int k=1;k<=m;k++)
{
bb[j][k]=a[j-1][k]+a[j+1][k]+a[j][k-1]+a[j][k+1]-4*a[j][k];
if(bb[j][k]>maxx)
{
maxx=bb[j][k];
mi=j;
mj=k;
}
}
}
printf("Case %d: %d %d %d\n",i,maxx,mi,mj);
}
return 0;
}
SDUT 2409:The Best Seat in ACM Contest的更多相关文章
- Sdut 2409 The Best Seat in ACM Contest(山东省第三届ACM省赛 H 题)(模拟)
题目描述 Cainiao is a university student who loves ACM contest very much. It is a festival for him once ...
- 牛客-https://www.nowcoder.com/acm/contest/96/H
链接:https://www.nowcoder.com/acm/contest/96/H来源:牛客网 题目描述 今天qwb要参加一个数学考试,这套试卷一共有n道题,每道题qwb能获得的分数为ai,qw ...
- UVA10600:ACM Contest and Blackout(次小生成树)
ACM Contest and Blackout 题目链接:https://vjudge.net/problem/UVA-10600 Description: In order to prepare ...
- Kattis - ACM Contest Scoring
ACM Contest Scoring Our new contest submission system keeps a chronological log of all submissions m ...
- Sdut 2164 Binomial Coeffcients (组合数学) (山东省ACM第二届省赛 D 题)
Binomial Coeffcients TimeLimit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 输入 输出 示例输入 1 1 10 2 9 ...
- SDUT 2411:Pixel density
Pixel density Time Limit: 1000MS Memory limit: 65536K 题目描述 Pixels per inch (PPI) or pixel density is ...
- SDUT 2608:Alice and Bob
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Alice and Bob like playing ...
- Sdut 2416 Fruit Ninja II(山东省第三届ACM省赛 J 题)(解析几何)
Time Limit: 5000MS Memory limit: 65536K 题目描述 Haveyou ever played a popular game named "Fruit Ni ...
- Sdut 2165 Crack Mathmen(数论)(山东省ACM第二届省赛E 题)
Crack Mathmen TimeLimit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Since mathmen take security ...
随机推荐
- 参数db_ultra_safe
db_ultra_safe参数设置控制保护级别的其它参数的默认值 可以取的值有:off.data_only.data_and_index.默认值是off -off:不影响db_block_checki ...
- display:flex 多栏多列布局
转自:http://www.360doc.com/content/14/0811/01/2633_400926000.shtml display:flex 多栏多列布局浏览器支持情况:火狐直接支持w3 ...
- java mock
一篇文章: 5分钟了解Mockito 一.什么是mock测试,什么是mock对象? 先来看看下面这个示例: 从上图可以看出如果我们要对A进行测试,那么就要先把整个依赖树构建出来,也就是BCDE的实例. ...
- Java相对路径读取文件
不管你是新手还是老鸟,在程序中读取资源文件总会遇到一些找不到文件的问题,这与Java底层的实现有关,不能算bug,只要方法得当,问题还是可以解决的. 项目的文件夹结构: repathtest ├─sr ...
- Java基础(34):Java中基本数据类型的包装类(主要为了不同数据类型之间更方便的进行转换)(Wrapper类)
相信各位小伙伴们对基本数据类型都非常熟悉,例如 int.float.double.boolean.char 等.基本数据类型是不具备对象的特性的,比如基本类型不能调用方法.功能简单...,为了让基本数 ...
- 如何为 Eclipse 中的 Java 源文件设置为 UTF-8 默认编码(转)
要让一个 Java 源文件打开时编码格式为 UTF-8,需要做2件事情: 1)设置Java 源文件的默认编码格式为UTF-8: 2)设置workspace的编码格式为UTF-8. 相应设置如下: 设置 ...
- Java用native2ascii命令做unicode编码转换
背景:在做Java开发的时候,常常会出现一些乱码,或者无法正确识别或读取的文件,比如常见的validator验证用的消息资源(properties)文件就需要进行Unicode重新编码.原因是java ...
- length() 和 size()
length() 和 size() ==>length() 是针对数组字符串说的 size() 是针对 泛型集合的
- mac工具-解析json visualJSON和JSON Accelerator这两款工具
- Listview和Gridview自定义分割线
1,ListView和GridView中的每一个条目都有分割线,属性android:footerDividersEnabled表示是否显示分割线,默认是为true,即可见.可以自定义的设置分割线的颜色 ...