网宿科技杯厦大第十届校赛 A题 1480.十

本文详细介绍了如何整理比赛时现场敲写的混乱代码,并使用递归方法解决字符串数据输入过程中的重叠(扩散)问题。通过提供模板代码和实例解析,帮助读者理解并解决类似问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

由于比赛时,现场敲的代码比较乱,这是整理过的版本;模拟题,注意一下字符串数据的输入,用递归求解重叠(扩散)的部分。

//模板开始   
#include <string>      
#include <vector>      
#include <algorithm>      
#include <iostream>      
#include <sstream>      
#include <fstream>      
#include <map>      
#include <set>      
#include <cstdio>      
#include <cmath>      
#include <cstdlib>      
#include <ctime>   
#include<iomanip>   
#define SZ(x) (int(x.size()))   
using namespace std;   
  
int toInt(string s){   
    istringstream sin(s);    
    int t;    
    sin>>t;    
    return t;   
}   
template<class T> string toString(T x){   
    ostringstream sout;    
    sout<<x;    
    return sout.str();   
}   
typedef long long int64;   
int64 toInt64(string s){   
    istringstream sin(s);    
    int64 t;    
    sin>>t;   
    return t;   
}   
template<class T> T gcd(T a, T b){    
    if(a<0)    
        return gcd(-a, b);   
    if(b<0)    
        return gcd(a, -b);   
    return (b == 0)? a : gcd(b, a % b);   
}   
//模板结束(通用部分)   
  
//厦大校赛现场赛(网宿科技杯厦大第十届校赛)
//A题、1480.十
  
#define MAX_ROW 205   
#define MAX_COLUMN 205   
  
int panduan(char tuAn[][205], int i, int j, int index, int n, int m, int count)   
{   
    if(index + i >= n || i - index <= -1 || j + index >= m || j - index <= -1)   
    {   
        return count;         
    }   
    if(tuAn[i - index][j] == '*' && tuAn[i + index][j] == '*' && tuAn[i][j - index] == '*' && tuAn[i][j + index] == '*')   
    {   
        count++;      
        count = panduan(tuAn, i, j, index + 1, n, m, count);   
        return count;   
    }   
    else  
    {   
        return count;
    }   
}   
  
int main()   
{   
    ifstream ifs("shuju.txt", ios::in);   
    int n, m;   
    //ifs>>n>>m;   
    cin>>n>>m;   
    char tuAn[MAX_ROW][MAX_COLUMN];   
	int count;    
    //ifs.getline(tuAn[0], 204);   
    //cin.getline(tuAn[0], 204);   
    //ifs.ignore();   
    cin.ignore(204, '\n');   
    for(int k = 0; k < n; k++)   
    {   
        //ifs.getline(tuAn[k], 204);   
        cin.getline(tuAn[k], 205);   
    }   
    //cout<<n<<m<<endl;   
    /*for(int k = 0; k < n; k++)  
    {  
        cout<<tuAn[k]<<endl;  
    }*/  
  
    count = 0;    
    int i;   
    int j;   
    for(i = 1; i < n - 1; i++)   
    {   
        for(j = 1; j < m - 1; j++)   
        {   
            if(tuAn[i][j] == '*')   
            {   
                int index = 1;   
                count = panduan(tuAn, i, j, index, n, m, count);  
            }
        }   
    }   
    cout<<count<<endl;   
    return 0;   
}


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值