zoukankan      html  css  js  c++  java
  • 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 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.

    示例输入

    13 41 5 3 46 3 3 44 3 2 1

    示例输出

    Case 1: 7 1 1

    提示

     

    来源

    2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛

    /**************
    简单的模拟题,因为粗心被弄得WA了好多次。。
    题意很简单,不说了。
    我的解法:求 f[i][j] 时,用 num[i][j]上下左右四个方向元素的和 减去 4*num[i][j];
    考虑到边界,只需要把 num[i][j]-1的6给边界的给外面一行/列  就OK了。
    *********************/
    Code:
    #include <iostream>
    #include<string.h>
    #include<stdio.h>
    using namespace std;
    const int MAX = 30;
    int num[MAX][MAX];
    int figure[MAX][MAX];
    int main()
    {
        int t,m,n,i,j,h;
        cin>>t;
        for(h = 1;h<=t;h++)
        {
            cin>>m>>n;
            memset(num,0,sizeof(num));
            memset(figure,0,sizeof(figure));
            for(i = 1;i<=m;i++)
                for(j = 1;j<=n;j++)
                {
                    cin>>num[i][j];
                }
            /// 边界处理
            for(i = 1;i<=m;i++)
            {
                num[i][0] = num[i][1]-1;
                num[i][n+1] = num[i][n]-1;
            }
            for(i = 1;i<=n;i++)
            {
                num[0][i] = num[1][i]-1;
                num[m+1][i] = num[m][i]-1;
            }
            for(i = 1;i<=m;i++)
            {
                for(j = 1;j<=n;j++)
                {
                    int sum = num[i+1][j] + num[i-1][j] + num[i][j+1] + num[i][j-1];///  思路中代码实现
                    figure[i][j] = sum - num[i][j]*4;
                }
            }
            int ans = -99999999,r,c;
            for(i = 1;i<=m;i++)
            {
                for(j = 1;j<=n;j++)
                {
                    if(ans<figure[i][j])
                    {
                        ans = figure[i][j];
                        r = i;c = j;
                    }
                }
            }
            cout<<"Case "<<h<<": "<<ans<<" "<<r<<" "<<c<<endl;
        }
        return 0;
    }
     
    
    
    
    /**************************************
    	Problem id	: SDUT OJ 2409 
    	User name	: CY_ 
    	Result		: Accepted 
    	Take Memory	: 476K 
    	Take Time	: 0MS 
    	Submit Time	: 2014-04-28 09:27:04  
    **************************************/
    




  • 相关阅读:
    树的子结构(剑指offer_26)
    合并两个排序的链表(剑指offer_25)
    反转链表(剑指offer_24)多看多思多想
    链表中环的入口结点(剑指offer_23)
    链表中倒数第k个节点
    调整数组顺序使奇数位于偶数前面(剑指offer_21)
    表示数值的字符串(剑指offer_20)
    1676. 跳石头
    1670. 回合制游戏
    1667. 区间统计(回顾)
  • 原文地址:https://www.cnblogs.com/gray1566/p/3704288.html
Copyright © 2011-2022 走看看