日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

[2012山东ACM省赛] The Best Seat in ACM Contest (模拟)

發(fā)布時(shí)間:2023/12/20 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [2012山东ACM省赛] The Best Seat in ACM Contest (模拟) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

The Best Seat in ACM Contest

Time Limit: 1000ms?? Memory limit: 65536K??有疑問(wèn)?點(diǎn)這里^_^

題目描述

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

提示

來(lái)源

2012年"浪潮杯"山東省第三屆ACM大學(xué)生程序設(shè)計(jì)競(jìng)賽

?

解題思路:

按照題意說(shuō)明模擬一下,計(jì)算各個(gè)座位的分值,輸出分值最大的值,行號(hào),列號(hào),因?yàn)橐笕绻卸鄠€(gè)相同的最大值,輸出行最大,所以最后遍歷數(shù)組時(shí),要max<=小于等于號(hào)。

代碼:

#include <iostream> #include <string.h> using namespace std;int s[30][30];//存座位power int d[30][30];//存分值int main() {int t;cin>>t;int c=1;int n,m;while(t--){memset(d,0,sizeof(d));cin>>n>>m;for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){cin>>s[i][j];}for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){if(i-1<1)//上面d[i][j]--;else if(s[i][j]<s[i-1][j])d[i][j]+=(s[i-1][j]-s[i][j]);elsed[i][j]-=(s[i][j]-s[i-1][j]);if(i+1>n)//下面d[i][j]--;else if(s[i][j]<s[i+1][j])d[i][j]+=(s[i+1][j]-s[i][j]);elsed[i][j]-=(s[i][j]-s[i+1][j]);if(j-1<1)//左邊d[i][j]--;else if(s[i][j]<s[i][j-1])d[i][j]+=(s[i][j-1]-s[i][j]);elsed[i][j]-=(s[i][j]-s[i][j-1]);if(j+1>m)//右邊d[i][j]--;else if(s[i][j]<s[i][j+1])d[i][j]+=(s[i][j+1]-s[i][j]);elsed[i][j]-=(s[i][j]-s[i][j+1]);}int rr,cc;//行,列int max=0;for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){if(max<=d[i][j])//注意這里是小于等于{max=d[i][j];rr=i;cc=j;}}cout<<"Case "<<c++<<": "<<max<<" "<<rr<<" "<<cc<<endl;}return 0; }


?

轉(zhuǎn)載于:https://www.cnblogs.com/sr1993/p/3697747.html

總結(jié)

以上是生活随笔為你收集整理的[2012山东ACM省赛] The Best Seat in ACM Contest (模拟)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。