The Best Seat in ACM Contest
来源:互联网 发布:最新经典网络语言大全 编辑:程序博客网 时间:2024/04/29 09:56
比赛简单题
1、点击打开链接
2、.题目:
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.
输入
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.
示例输入
13 41 5 3 46 3 3 44 3 2 1
示例输出
Case 1: 7 1 1
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int a[25][25];int b[25][25];struct node{ int s; int x; int y;} c[410];int cmp(node a,node b){ if(a.s!=b.s) return a.s>b.s; else if(a.x!=b.x) return a.x>b.x; else return a.y>b.y;}int main(){ int t,n,m; scanf("%d",&t); for(int cas=1; cas<=t; cas++) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); scanf("%d%d",&n,&m); for(int i=1; i<=n; i++) { for(int j=1; j<=m; j++) scanf("%d",&a[i][j]); } int k=0; for(int i=1; i<=n; i++) { for(int j=1; j<=m; j++) { if((i==1&&j==1)||(i==1&&j==m)||(i==n&&j==1)||(i==n&&j==m)) { b[i][j]--; } if(i==1||i==n||j==1||j==m) b[i][j]--; if((a[i-1][j]>a[i][j])&&i-1>=1) b[i][j]+=(a[i-1][j]-a[i][j]); if((a[i-1][j]<a[i][j])&&i-1>=1) b[i][j]+=(a[i-1][j]-a[i][j]); if((a[i+1][j]>a[i][j])&&i+1<=n) b[i][j]+=(a[i+1][j]-a[i][j]); if((a[i+1][j]<a[i][j])&&i+1<=n) b[i][j]+=(a[i+1][j]-a[i][j]); if((a[i][j-1]>a[i][j])&&j-1>=1) b[i][j]+=(a[i][j-1]-a[i][j]); if((a[i][j-1]<a[i][j])&&j-1>=1) b[i][j]+=(a[i][j-1]-a[i][j]); if((a[i][j+1]>a[i][j])&&j+1<=m) b[i][j]+=a[i][j+1]-a[i][j]; if((a[i][j+1]<a[i][j])&&j+1<=m) b[i][j]+=a[i][j+1]-a[i][j]; c[k].s=b[i][j]; c[k].x=i; c[k].y=j; k++; } } sort(c,c+k,cmp); printf("Case %d: %d %d %d\n",cas,c[0].s,c[0].x,c[0].y); } return 0;}/*13 41 5 3 46 3 3 44 3 2 1*/
- [ACM]The Best Seat in ACM Contest
- 省赛 The Best Seat in ACM Contest
- The Best Seat in ACM Contest
- The Best Seat in ACM Contest
- The Best Seat in ACM Contest
- sdut2409 The Best Seat in ACM Contest
- 第三届山东省ACM The Best Seat in ACM Contest
- SOJ 2409 The Best Seat in ACM Contest (BFS)
- SDUT 2409:The Best Seat in ACM Contest
- [2012山东省第三届ACM大学生程序设计竞赛]——The Best Seat in ACM Contest
- [2012山东ACM省赛] The Best Seat in ACM Contest (模拟)
- Sdut 2409 The Best Seat in ACM Contest(山东省第三届ACM省赛 H 题)(模拟)
- 山东省第三届ACM竞赛 The Best Seat in ACM Contest
- 山东省第三届ACM省赛题——The Best Seat in ACM Contest(模拟)
- 2013山东省第三届ACM省赛 The Best Seat in ACM Contest
- 山东省第三届ACM大学生程序设计竞赛 The Best Seat in ACM Contest
- The Best Seat in ACM Contest--12年山东省赛(广搜)需要记录数组
- 2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛:The Best Seat in ACM Contest
- 如何成为强大的程序员?
- UML类图几种关系的总结
- Hadoop源代码分析(完整版)
- 深入Android —— 架构和学习
- eclipse项目导入jar包
- The Best Seat in ACM Contest
- linux下 which whereis locate 和find 命令
- 如何检测C/C++程序内存泄露
- 巴菲特后期理念(1)
- TOMCAT 基本管理
- Dom4j 使用简介
- 例题1:勇士斗恶龙
- 买房和租房 买车和打车 郎咸平告诉你区别在那里,不亏是著名经济学家!
- VS 2008中的jQuery Intellisense