zoukankan      html  css  js  c++  java
  • Marlin (思维)

    The city of Fishtopia can be imagined as a grid of 44 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1)(1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4,n)(4,n). The second village is located at (4,1)(4,1) and its people love the Salmon pond at (1,n)(1,n).

    The mayor of Fishtopia wants to place kk hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.

    A person can move from one cell to another if those cells are not occupied by hotels and share a side.

    Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?

    Input

    The first line of input contain two integers, nn and kk (3≤n≤993≤n≤99, 0≤k≤2×(n−2)0≤k≤2×(n−2)), nn is odd, the width of the city, and the number of hotels to be placed, respectively.

    Output

    Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".

    If it is possible, print an extra 44 lines that describe the city, each line should have nn characters, each of which is "#" if that cell has a hotel on it, or "." if not.

    Examples

    Input

    7 2
    

    Output

    YES
    .......
    .#.....
    .#.....
    .......
    

    Input

    5 3
    

    Output

    YES
    .....
    .###.
    .....
    .....

    如何去看这个题,可以把他看成关于对称的图形,上下对称和左右对称

    代码:

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #include<set>
    #include<map>
    #include<vector>
    #include<cmath>
    
    const int maxn=3e5+5;
    typedef long long ll;
    using namespace std;
    
    char Map[5][105];
    int n,k;
    void init()
    {
    	for(int t=0;t<4;t++)
    	{
    		for(int j=0;j<n;j++)
    		{
    			Map[t][j]='.';
    		}
    	}
    }
    int main()
    {
    	cin>>n>>k;
    	init();
    	if(k%2==0)
    	{
    		int s=k/2;
    		for(int t=1;t<s+1;t++)
    		{
    			Map[1][t]='#';
    		}
    		for(int t=1;t<s+1;t++)
    		{
    			Map[2][t]='#';
    		}
    		cout<<"YES"<<endl;
    		for(int t=0;t<4;t++)
    		{
    			puts(Map[t]);
    		}
    	}
    	else
    	{
    		int s=n/2;
    		Map[1][s]='#';
    		k--;
    		
    		 for(int t=1;t<n/2;t++)
    		 {
    		 	if(k==0)
    			{
    				break;
    			} 
    			else
    			{
    				
    				Map[1][t]='#';
    				Map[1][n-1-t]='#';
    				k-=2;
    			}
    		 }	
    	     for(int t=1;t<n/2;t++)
    		 {
    		 	if(k==0)
    			{
    				break;
    			} 
    			else
    			{
    				
    				Map[2][t]='#';
    				Map[2][n-1-t]='#';
    				k-=2;
    			}
    		 }	
    		 cout<<"YES"<<endl;
    		 	for(int t=0;t<4;t++)
    		{
    			puts(Map[t]);
    		}
    	}
    	
    	return 0;
    }
  • 相关阅读:
    CMDXP.CMD命令大全
    ASP.NET 页生命周期概述
    使用 ASP.NET 2.0提供的WebResource管理资源
    软件包管理 之 Fedora / Redhat 软件包管理指南
    开源代码分析研究 之 BugNet (2008年1月14日更新 第一章BugNet 简介 已完成)
    软件包管理 之 如何编译安装源码包软件
    硬件管理 之 Linux 硬件管理的基础知识
    软件包管理 之 fedorarpmdevtools 工具介绍
    软件包管理 之 Fedora/Redhat 在线安装更新软件包,yum 篇 ── 给新手指南
    系统引导管理 之 系统引导过程及硬盘分区结构论述
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/10781785.html
Copyright © 2011-2022 走看看