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的更多相关文章

  1. 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 ...

  2. 牛客-https://www.nowcoder.com/acm/contest/96/H

    链接:https://www.nowcoder.com/acm/contest/96/H来源:牛客网 题目描述 今天qwb要参加一个数学考试,这套试卷一共有n道题,每道题qwb能获得的分数为ai,qw ...

  3. UVA10600:ACM Contest and Blackout(次小生成树)

    ACM Contest and Blackout 题目链接:https://vjudge.net/problem/UVA-10600 Description: In order to prepare ...

  4. Kattis - ACM Contest Scoring

    ACM Contest Scoring Our new contest submission system keeps a chronological log of all submissions m ...

  5. Sdut 2164 Binomial Coeffcients (组合数学) (山东省ACM第二届省赛 D 题)

    Binomial Coeffcients TimeLimit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 输入 输出 示例输入 1 1 10 2 9 ...

  6. SDUT 2411:Pixel density

    Pixel density Time Limit: 1000MS Memory limit: 65536K 题目描述 Pixels per inch (PPI) or pixel density is ...

  7. SDUT 2608:Alice and Bob

    Alice and Bob Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Alice and Bob like playing ...

  8. Sdut 2416 Fruit Ninja II(山东省第三届ACM省赛 J 题)(解析几何)

    Time Limit: 5000MS Memory limit: 65536K 题目描述 Haveyou ever played a popular game named "Fruit Ni ...

  9. Sdut 2165 Crack Mathmen(数论)(山东省ACM第二届省赛E 题)

    Crack Mathmen TimeLimit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Since mathmen take security ...

随机推荐

  1. 关于解决读取导入excel某列数字过长的科学计数法格式

    因为 客户 需要导入 虚拟商品的卡号 excel已经是文本形式的单元格格式了 但是 到后台 java代码去获取的时候 仍然是 科学计数法格式 先找到以下资料做参考:http://love-66521. ...

  2. PostgreSQL Replication之第十章 配置Slony(5)

    10.5 给复制添加表和管理的问题 一旦我们增加了此表到系统中,我们可以将它添加到复制设置.这样做有点复杂.首先,我们必须创建我们自己的新表集合并把这个和我们已经有的表合并.因此,过一段时间,我们将有 ...

  3. FB面经prepare: Task Schedule

    每种task都有冷却时间,比如task1执行后,要经过interval时间后才能再次执行,求总共所需时间. 用HashMap保存每一个task的下一次可以开始执行的最早时间 package TaskS ...

  4. Lintcode: Topological Sorting

    Given an directed graph, a topological order of the graph nodes is defined as follow: For each direc ...

  5. [转] asp.net <%%>&<%#%>&<%=%>&<%@%>&<%$%>用法区别

    转自  参考 1.<% %>用来绑定后台代码 如: < % for(int i=0;i<100;i++) { Reaponse.Write(i.ToString()); } % ...

  6. WebDriver:org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms

    今天尝试最新的webDriver与fireFox搭配: 运行代码时出现如下的问题,但是浏览器却可以打开: org.openqa.selenium.firefox.NotConnectedExcepti ...

  7. 关于header跳转之后的乱码问题

    关于header跳转之后的乱码问题 http://www.360doc.com/content/11/0603/19/7052474_121495648.shtml 问题:不同网站的跳转出现乱码,不同 ...

  8. 导出Excel offer2007以上

    package cn.knet.data.untils; import java.awt.Color; import java.io.File; import java.io.FileOutputSt ...

  9. [python] No module named _sysconfigdata_nd

    when setting python environment in Ubuntu13.04, i got this error: ImportError: No module named _sysc ...

  10. ralink网卡驱动的下载地址集合

    linuxMT7612U11/7/2014v3.0.0.1http://cdn-cw.mediatek.com/Downloads/linux/MT7612U_DPO_LinuxSTA_3.0.0.1 ...