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. 1
  1. 3 4
  1. 1 5 3 4
  1. 6 3 3 4
  1. 4 3 2 1

示例输出

  1. Case 1: 7 1 1

每一块的数字等于它周围四个块的和-4*当前块!边界以外块的值=其相邻-1;

  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<string.h>
  4. #include<algorithm>
  5. using namespace std;
  6. int main()
  7. {
  8. int T;
  9. cin>>T;
  10. int a[105][105],bb[105][105];
  11. for(int i=1;i<=T;i++)
  12. {
  13. memset(a,0,sizeof(a));
  14. memset(bb,0,sizeof(bb));
  15. int n,m;
  16. cin>>n>>m;
  17. for(int j=1;j<=n;j++)
  18. for(int k=1;k<=m;k++)
  19. {
  20. cin>>a[j][k];
  21. if(j==1)a[j-1][k]=a[j][k]-1;
  22. if(j==n)a[j+1][k]=a[j][k]-1;
  23. if(k==1)a[j][k-1]=a[j][k]-1;
  24. if(k==m)a[j][k+1]=a[j][k]-1;
  25. }
  26. int maxx=0,mi=0,mj=0;
  27. for(int j=1;j<=n;j++)
  28. {
  29. for(int k=1;k<=m;k++)
  30. {
  31. bb[j][k]=a[j-1][k]+a[j+1][k]+a[j][k-1]+a[j][k+1]-4*a[j][k];
  32. if(bb[j][k]>maxx)
  33. {
  34. maxx=bb[j][k];
  35. mi=j;
  36. mj=k;
  37. }
  38. }
  39. }
  40. printf("Case %d: %d %d %d\n",i,maxx,mi,mj);
  41. }
  42. return 0;
  43. }

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. Java基础之创建窗口——使用边界布局管理器(TryBorderLayout)

    控制台程序. 边界布局管理器最多能在容器中放置5个组件.在这种布局管理器中,可以把组件放在容器的任意一个边界上,也可以把组件放在容器的中心.每个位置只能放置一个组件.如果把组件放置在已被占用的边界上, ...

  2. javascript 函数参数之中的undefined(zz)

    开始看到很多js函数里都带一个undefined的参数,很是疑惑,后来查了查,原来是这样.假如我们定义了一个函数function a(){  if(arg1===undefined) alert(&q ...

  3. objective-c底层: runtime机制

    runtime是oc的真面目.oc底层的一套c语言API. unsigned int count; //获取属性列表 objc_property_t *propertyList = class_cop ...

  4. PostgreSQL单机、同步复制、异步复制性能测试对比

    测试环境: •测试机:PC •内存:8GB •CPU:Intel(R) Core(TM) i5-3450 3.10GHz •硬盘:HDD •数据量:20GB •测试工具:pgbench •Postgr ...

  5. java 获取当前系统系时间

    //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 SimpleDateFo ...

  6. eclipse 导入jdbc4.jar 包

    详细讲解链接 http://wenku.baidu.com/link?url=QUhO2rIL2fYRgOUyd1TQPEgbl0jQr156ioxK5fiwSPm_Tset2okpBEJcO1fmz ...

  7. Spring之我见

    Spring 是什么(1) •Spring 是一个开源框架. •Spring 为简化企业级应用开发而生. 使用 Spring 可以使简单的 JavaBean 实现以前只有 EJB 才能实现的功能. • ...

  8. 机器学习中的范数规则化之(一)L0、L1与L2范数(转)

    http://blog.csdn.net/zouxy09/article/details/24971995 机器学习中的范数规则化之(一)L0.L1与L2范数 zouxy09@qq.com http: ...

  9. RobotFramework 安装配置(一)

    服务器接口的测试框架的选择,最后选中了 RobotFramework ,原因一:能有效的管理测试用例,,支持批量执行,能实现关键字驱动或者数据驱动.原因二:支持测试人员可以使用Python和java创 ...

  10. zw版【转发·台湾nvp系列Delphi例程】HALCON SetLineStyle1

    zw版[转发·台湾nvp系列Delphi例程]HALCON SetLineStyle1 procedure TForm1.Button1Click(Sender: TObject);var img : ...