• C


    https://vjudge.net/problem/HDU-6879

    题意:

    给定S,r,c

    构造一个r行c列的阵列。

    对于没有炸弹的位置的数值为位置附近8个位置炸弹总数

    保证炸弹总数S

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<bitset>
    #include<cassert>
    #include<cctype>
    #include<cmath>
    #include<cstdlib>
    #include<ctime>
    #include<deque>
    #include<iomanip>
    #include<list>
    #include<map>
    #include<queue>
    #include<set>
    #include<stack>
    #include<vector>
    #include <vector>
    #include <iterator>
    #include <utility>
    #include <sstream>
    #include <limits>
    #include <numeric>
    #include <functional>
    using namespace std;
    #define gc getchar()
    #define mem(a) memset(a,0,sizeof(a))
    #define debug(x) cout<<"debug:"<<#x<<" = "<<x<<endl;
    
    #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    typedef long long ll;
    typedef unsigned long long ull;
    typedef long double ld;
    typedef pair<int,int> pii;
    typedef char ch;
    typedef double db;
    
    const double PI=acos(-1.0);
    const double eps=1e-6;
    const int inf=0x3f3f3f3f;
    const int maxn=1e5+10;
    const int maxm=100+10;
    const int N=1e6+10;
    const int mod=1e9+7;
    
    
    const int dir[8][2] = {1, 0, 0, 1, -1, 0, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
    map< int, vector< vector<char> > > M;
    int n = 0;
    int main()
    {
        srand((int) time(0));
        int T = 0;
        cin >> T;
        int random = 0;
        int chg = 0;
        
        for (int I = 1; I<=50000;I++)
    	{
            random = (rand() % 25) + 1;
            chg = (rand() % 25) + 1;
            vector< vector<char> > A(random, vector<char>(chg));
            for(int i = 0;i<random;i++)
    		{
                for(int j = 0;j<chg;j++)
    			{
    				if((rand()%2))
    				{
    					A[i][j] = 'X';
    				}
    				else
    				{
    					A[i][j] = '.';
    				}
                    
                }
            }
            random = A.size();
    	    chg = A[0].size();
    	    int S = 0;
    	    for(int i = 0;i<random;i++)
    		{
    	        for(int j = 0;j<chg;j++)
    			{
    	            if (A[i][j] == '.')
    				{
    	                int counter = 0;
    	                for (int L = 0;L<8;L++)
    					{
    	                    int dx = i + dir[L][0];
    	                    int dy = j + dir[L][1];
    	                    if ( (dx >= 0 && dx <= random-1) && (dy >= 0 && dy <= chg-1) )
    						{
    							if(A[dx][dy] == 'X')
    							{
    								counter++;
    							}
    	                    }
    	                }
    	                S += counter;
    	            }
    	        }
    	    }
            M[S] = A;
        }
    
        while(T--)
    	{
            cin >> n;
            vector< vector<char> > A = M[n];
    
            random = A.size();
            chg = A[0].size();
            cout << random << " " << chg << endl;
            for (int i = 0;i<random;i++)
    		{
                for (int j = 0;j<chg;j++)
    			{
                    cout << A[i][j];
                    if(j == chg - 1) cout << endl;
                }
            }
        }
        return 0;
    }
    

      

  • 相关阅读:
    设计模式之抽象工厂模式
    MQ任意延时消息(三)基于服务端实现
    MQ任意延时消息(二)基于客户端实现
    MQ任意延时消息(一)实现原理概述
    sqlyog报错2058
    base标签的作用
    相对路径和绝对路径的解释
    自定义Tomcat部署目录
    常用正则表达式
    接口的结构定义
  • 原文地址:https://www.cnblogs.com/SutsuharaYuki/p/13562233.html
Copyright © 2020-2023  润新知