当前位置:编程学习 > C/C++ >>

HDOJ4500 小Q系列故事——易做图丝的逆袭(简单模拟) &&腾讯2013编程马拉松第0场第一题

print?/*HDOJ4500 && 腾讯2013编程马拉松第0场第一题
作者:陈佳润
2013-04-14
*/ 
#include<iostream>  
using namespace std; 
int map[22][22]; 
int score[22][22]; 
int main(){ 
    int n,m,i,j,max,mi,mj; 
    //freopen("1.txt","r",stdin);  
    while(scanf("%d%d",&n,&m)!=EOF&&(n!=0||m!=0)){ 
        //初始化      
        for(i=1;i<=n;i++){ 
            for(j=1;j<=m;j++){ 
                cin>>map[i][j]; 
                score[i][j]=0; 
            } 
        } 
        for(i=0;i<=n+1;i++) 
            map[i][0]=map[i][m+1]=0; 
        for(i=0;i<=m+1;i++) 
            map[0][i]=map[n+1][i]=0; 
        //计算  
        for(i=1;i<=n;i++){ 
            for(j=1;j<=m;j++){ 
                if(map[i][j]>0)//如果是正数,则对其有吸引力的是负的,用-  
                    score[i][j]=-map[i-1][j]-map[i+1][j]-map[i][j+1]-map[i][j-1]; 
                else//如果是负数,则对其有吸引力的是正的,用+  
                   score[i][j]=map[i-1][j]+map[i+1][j]+map[i][j+1]+map[i][j-1];         
            } 
        } 
 
        //找出最大的  
        max=-10; 
        mi=1; 
        mj=1; 
        for(i=1;i<=n;i++){ 
            for(j=1;j<=m;j++){ 
                if(score[i][j]>max){ 
                    max=score[i][j]; 
                    mi=i; 
                    mj=j; 
                } 
            } 
            cout<<mi<<" "<<mj<<" "<<max<<endl; 
        } 
    } 
    return 0; 

/*HDOJ4500 && 腾讯2013编程马拉松第0场第一题
作者:陈佳润
2013-04-14
*/
#include<iostream>
using namespace std;
int map[22][22];
int score[22][22];
int main(){
    int n,m,i,j,max,mi,mj;
    //freopen("1.txt","r",stdin);
 while(scanf("%d%d",&n,&m)!=EOF&&(n!=0||m!=0)){
  //初始化   
        for(i=1;i<=n;i++){
            for(j=1;j<=m;j++){
                cin>>map[i][j];
                score[i][j]=0;
            }
        }
        for(i=0;i<=n+1;i++)
            map[i][0]=map[i][m+1]=0;
        for(i=0;i<=m+1;i++)
            map[0][i]=map[n+1][i]=0;
        //计算
        for(i=1;i<=n;i++){
            for(j=1;j<=m;j++){
                if(map[i][j]>0)//如果是正数,则对其有吸引力的是负的,用-
                    score[i][j]=-map[i-1][j]-map[i+1][j]-map[i][j+1]-map[i][j-1];
                else//如果是负数,则对其有吸引力的是正的,用+
                   score[i][j]=map[i-1][j]+map[i+1][j]+map[i][j+1]+map[i][j-1];       
            }
        }

  //找出最大的
        max=-10;
        mi=1;
        mj=1;
        for(i=1;i<=n;i++){
            for(j=1;j<=m;j++){
                if(score[i][j]>max){
                    max=score[i][j];
                    mi=i;
                    mj=j;
                }
            }
            cout<<mi<<" "<<mj<<" "<<max<<endl;
  }
    }
    return 0;
}

 

补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,