题目1 : Constellations

时间限制:10000ms

单点时限:1000ms

内存限制:256MB

描述

Recently Little Hi started to like astronomy and downloaded thepictures of K constellations. He wonders how many of them he can spot in thenight?

输入

Line 1: K(1 <= K <= 20), the number of constellations.
K constellation pictures follow. The format of each picture is:
Line 1 of each picture: H and W(5 <= H, W, <= 100), the height and widthof the picture.
Line 2~H+1 of each picture: An H*W matrix of characters representing thepicture of a constellation. Each line contains W characters. '#' for a star and'.' for empty area. There are no more than 20 stars in each constellation.
After K constellations is the sky Little Hi looks to in the night.
Line 1 of sky: N and M(100 <= N, M <= 1000), the size of the sky LittleHi looks to.
Line 2~N of sky: An N*M matrix of characters representing the sky Little Hilooks to. Each line contains M characters. '#' for a star and '.' for emptyarea. There are no more than 5000 stars in the sky.

输出

For each constellation in the Input output "Yes" or"No" indicating whether Little Hi can spot the constellation in thesky. 
All pictures of constellations and the sky Little Hi looks to are in the samedirection so there is no need to rotate the pictures.

提示

A constellation can be spoted if and only if all stars in theconstellation can be matched in the sky. It is allowed that two spotedconstellations share common stars.

样例输入

3

5 5

#....

.....

...#.

.....

.#...

5 5

....#

.....

.....

#....

....#

5 6

.....#

......

#.....

......

....#.

10 10

.......#..

..........

..#.......

..........

......#...

..........

..........

..#.......

......#...

..........

样例输出

No

Yes

Yes

本人菜鸟一枚,水平有限,花了3个小时写的代码,当做是练习,长时间不写代码会生疏。

以下我的C++代码实现,其中难免有不合理的地方,希望大家提出意见。

文件1:constellations.h

#ifndef _CONSTELLATIONS_H_
#define _CONSTELLATIONS_H_class STAR_MAP_CL
{public:STAR_MAP_CL();STAR_MAP_CL(int _iH, int _iW);~STAR_MAP_CL();void InputData();void Initial(int _iH, int _iW);int iW;int iH;char *pData;char **ppPtr;
};class CONSTELLATION_CL : public STAR_MAP_CL
{public:CONSTELLATION_CL();CONSTELLATION_CL(int _iH, int _iW);~CONSTELLATION_CL();
};class SKY_CL : public STAR_MAP_CL
{public:SKY_CL();SKY_CL(int _iH, int _iW);~SKY_CL();bool IsFind(CONSTELLATION_CL clConstellation);
};#endif

文件2:constellations_main.cpp

#include <iostream>#include "constellations.h"using namespace std;STAR_MAP_CL::STAR_MAP_CL():iH(0),iW(0),pData(NULL),ppPtr(NULL)
{return;
}STAR_MAP_CL::STAR_MAP_CL(int _iH, int _iW)
{Initial(_iH,_iW);return;
}STAR_MAP_CL::~STAR_MAP_CL()
{int i;if (NULL != pData){delete pData;}if (NULL != ppPtr){delete ppPtr;}return;
}void STAR_MAP_CL::Initial(int _iH, int _iW)
{int i;iH = _iH;iW = _iW;pData = new char[iH*iW];ppPtr = new char*[iH];for (i=0; i<iH; i++){ppPtr[i]=pData+i*iW;}return;
}void STAR_MAP_CL::InputData()
{int i;for (i=0; i<iH; i++){cin>>ppPtr[i];}return;
}CONSTELLATION_CL::CONSTELLATION_CL()
{
}
CONSTELLATION_CL::CONSTELLATION_CL(int _iH, int _iW):STAR_MAP_CL(_iH,_iW)
{
}
CONSTELLATION_CL::~CONSTELLATION_CL()
{
}SKY_CL::SKY_CL()
{
}
SKY_CL::SKY_CL(int _iH, int _iW):STAR_MAP_CL(_iH,_iW)
{
}
SKY_CL::~SKY_CL()
{
}bool SKY_CL::IsFind(CONSTELLATION_CL clConstellation)
{int i,j,k,m,n;bool bFind;char** ppSub;if (iH<clConstellation.iH || iW<clConstellation.iW){return false;}bFind = true;ppSub = new char*[clConstellation.iH];for (i=0; i<=iH-clConstellation.iH; i++){    for (j=0; j<=iW-clConstellation.iW; j++){for (k=0; k<clConstellation.iH; k++){ppSub[k]=ppPtr[i+k]+j;}for (n=0; n<clConstellation.iH; n++){for (m=0; m<clConstellation.iW; m++){bFind &= (clConstellation.ppPtr[n][m] == ppSub[n][m]);}}if (true == bFind){delete []ppSub;return true;}else{bFind = true;}}}delete []ppSub;return false;
}int main()
{int iN;int _iH,_iW;int i;cin>>iN;CONSTELLATION_CL *pclConstellations;pclConstellations = new CONSTELLATION_CL[iN];for (i=0; i<iN; i++){cin>>_iH>>_iW;pclConstellations[i].Initial(_iW,_iH);pclConstellations[i].InputData();}cin>>_iH>>_iW;SKY_CL clSky(_iH,_iW);clSky.InputData();for (i=0; i<iN; i++){if (true == clSky.IsFind(pclConstellations[i])){cout<<"yes\n";}else{cout<<"no\n";}}return 0;
}

运行结果:

hc@ubuntu:~/Workspace/ms_proj/src$ ./run_constellation 
2
2 2
*#
#*
3 3
**#
#**
*#*
5 5
#****
****#
**#**
*#***
***#*
yes
no

微软苏州校招1月3日在线编程题1——constellations相关推荐

  1. 微软2023校招8月26日即将截止!没有完成投递的小伙伴抓紧啦!

    微软2023校招8月26日截止,还没找到内推的23届同学可以发邮件到592786579@qq.com 网申时间:2022 / 8 / 1 - 2022 / 8 / 26 官网投递链接: https:/ ...

  2. 完美世界校招在线笔试题-互联网Java(11月1日)编程题

    一.题目 考试题目数为n,每道题只有做和不做.每道题都有不同难度,且每道题都各自分值及完成所需时间.现在计算在给定的时间m内,做题的最大得分. 输入: 第一行 :n 代表题目数 第二行:n个题目,每道 ...

  3. 11月11日在线研讨会预热 | ODX诊断数据库转换工具 — VDC(ODX)

    11月11日在线研讨会预热 | ODX诊断数据库转换工具 - VDC(ODX) 概述 INTEWORK-VDC(ODX)(Vehicle Database Convertor) 是将恒润诊断调查问卷转 ...

  4. 9月13号魔兽服务器维护,魔兽世界9月13日在线修正 魔兽世界9月13日更新了什么...

    魔兽世界9月13日在线修正.主要是死亡骑士改动,艾泽拉斯之心调整,另外修复了史诗纯净圣母的BUG,下面就一起来看看魔兽世界9月13日更新了什么吧. 职业 死亡骑士 邪恶 最后的惊喜不再获得两次精通:恐 ...

  5. 微软将在 6 月 24 日的活动中推出重新设计的 Windows 10

    Windows 10 重新设计 一项重大的 Windows 10 重新设计正在进行中,微软用户将在本月一睹"下一代 Windows"的风采. 微软将在6月24日推出其主要的Wind ...

  6. 服务器临时维护 开启另行通知,倩女幽魂手游6月23日在线维护公告内容介绍

    为了玩家更好的游戏体验,本周起将通过在线维护的方式投放每周更新内容.如特殊情况需停服维护(包括但不限于合服.月度版本更新.服务器临时维护等),将另行公告通知.祝全体玩家游戏愉快! 本周在线更新内容如下 ...

  7. 9月2日在线研讨会 | 基于TESSY的测试用例自动化评估与优化

    9月2日在线研讨会 | 基于TESSY的测试用例自动化评估与优化 针对软件白盒测试,ISO26262标准的Part 6部分给出了具体要求说明,包括测试的前提条件.推荐测试方法.工作产品等,随着各大整车 ...

  8. 王者服务器维护结束2020331,S19荣耀进阶战令的星元部件是哪一位英雄的 王者荣耀2020年3月31日每日一题答案 - 找游戏手游网...

    版本:v1.52.1.37 类型:MOBA跑酷大小:1.98 GB评分:9.2 标签: moba 腾讯游戏 塔防 竞技游戏 角色扮演 联机对战 立即下载 S19荣耀进阶战令的星元部件是哪一位英雄的?这 ...

  9. 【使用switch语句】 用C语言编程实现输入年、月、日,编程求这一日是该年中的第几天。

    问题:实现输入年.月.日,编程求这一日是该年中的第几天. 分析,解决: 1.首先定义年,月,日 2.输入年月日(注意scanf里有逗号),switch语句中的意思是看你输入几月份,然后再按照几日进行加 ...

最新文章

  1. ORACLE之SPFILE与PFILE
  2. POJ 2240 Arbitrage
  3. 带圆圈大小的散点图_Python数据可视化,Matplotlib绘制“散点图”的两种方法!...
  4. UISlider 滑块控件—IOS开发
  5. java 整数相等,为什么Java不会看到整数是相等的?
  6. Linux C语言:用零拷贝技术实现TCP代理(源代码+测试服务端客户端代码)
  7. 记录贴:阿里云 ECS服务器CentOS系统 搭建 Hexo 博客详细教程
  8. 新浪邮箱下载的都是php,为什么我用新浪邮箱以及手机号码注册的支付宝能够登陆,但是用163邮箱的支付宝登陆数据库就会报错...
  9. 什么是NAT技术与代理服务器
  10. 锁仓怎么解_锁仓后解锁技巧
  11. css 的rgba属性
  12. 《谋圣鬼谷子》曝片花 徐麒雯饰演“姮娥”
  13. 成都购房:2019年成都限购限贷政策
  14. 如何连接局域网_手机画面如何投屏到电视、盒子、投影仪?
  15. python技术面试题(十一)
  16. ACP敏捷知识点汇总
  17. Android Studio从gthub上导入新项目的时候,R文件丢失的问题
  18. centos7针对xfs文件系统缩小home目录并动态扩容根目录
  19. 三种登录形式的实现—永久登录、每次进入页面登录、设置登录有效期
  20. 滚动穿透及IOS惯性滚动究极解决方案

热门文章

  1. RHCE6.0那点事----仅供参考
  2. C++中四种类型转换运算符的使用方法
  3. android 环境一键,一键切换Android应用环境(Environment Switcher)
  4. 安卓android获取存储路径,Android系统的手机文件夹目录详解
  5. 微信考勤签到 php,【投稿】微信签到打卡领积分源码,每日积分签到
  6. 804计算机专业综合,2021南开大学804通信综合基础考试范围(大纲)和参考书目...
  7. 汽车自动泊车辅助系统APA(上)
  8. 第一章 数据结构与算法-前言
  9. 学计算机专业异构超算,中国科学技术大学超级计算中心
  10. 【解决方案】摄像机户外直播能在哪些地方运用?团建/项目启动会/户外婚礼等户外直播方案介绍