暑期个人赛--第一场--D
来源:互联网 发布:mac os 10.95官方原版 编辑:程序博客网 时间:2024/06/05 05:09
D. BLOCKS 2014新生暑假个人排位赛01
时间限制 1000 ms 内存限制 65536 KB
题目描述
给定一个
输入格式
有多组数据,EOF结束。
输出格式
每行对应一个answer
输入样例
6 8.....#.###.....###.....#.......##......##..#...#6 8.....#.###.....####...##.......###.....##..#...#
输出样例
There are 5 ships.So Sad
赛中提交:T
赛后ac:Y
题目大意:在矩阵里面找出独立的由#组成的区域个数
思路:
裸的广搜
赛中为何不过:
真心不懂- -赛后直接复制赛中提交的再提交一次一样的就过了
代码如下
#include "iostream"#include "string.h"#include "stdio.h"#include "stdlib.h"#include "math.h"#include "string"#include "vector"#include "list"#include "map"#include "queue"#include "stack"#include "bitset"#include "algorithm"#include "numeric"#include "functional" using namespace std;typedef pair<int ,int > P; int n,m;int u,d,l,r,counta,countaa;char c[1005][1005];int vis[1005][1005];int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1}; void bfs(int bx,int by){ P p,tempt; queue<P> que; tempt.first=bx,tempt.second=by; que.push(tempt); vis[bx][by]=1; while(que.size()){ int x,y; counta+=1; tempt=que.front(); que.pop(); x=tempt.first,y=tempt.second; //printf("\n\nque.size()=%d 取%d %d\n",que.size(),x,y); l=min(y,l); r=max(y,r); u=max(x,u); d=min(x,d); //printf("上%d下%d左%d右%d\n",u,d,l,r); for(int i=0;i<4;i+=1){ int nx=x+dx[i],ny=y+dy[i]; if(nx>=0&&ny>=0&&nx<n&&ny<m&&c[nx][ny]!='.'&&vis[nx][ny]==0){ tempt.first=nx,tempt.second=ny; que.push(tempt); vis[nx][ny]=1; } } }} int main(){ while(scanf("%d %d",&n,&m)!=EOF){ getchar(); int F=0; countaa=0; memset(vis,0,sizeof(vis)); for(int i=0;i<n;i+=1){ for(int j=0;j<m;j+=1){ scanf("%c",&c[i][j]); } getchar(); } for(int i=0;i<n;i+=1){ bool flag=0; for(int j=0;j<m;j+=1){ // printf("(%d,%d)",i+1,j+1); if(!vis[i][j]&&c[i][j]=='#'){ u=d=i; r=l=j; counta=0; bfs(i,j); if(counta!=(u-d+1)*(r-l+1)){ F=1; //printf("hhhhh(u%d-d%d+1)*(r%d-l%d+1)=%d counta=%d\n",u,d,r,l,(u-d+1)*(r-l+1),counta); break; } else{ countaa+=1; } } //printf("dfasfd%d %d\n",i+1,j+1); } if(F){ // printf("\n\ncome and eat shit\n\n"); break; } } if(F){ printf("So Sad\n"); } else{ printf("There are %d ships.\n",countaa); } } return 0;}
0 0
- 暑期个人赛--第一场--D
- 暑期个人赛第一场
- 暑期个人赛--第五场--D
- 暑期个人赛--第三场--D
- 暑期个人赛--第二场--D
- 暑期个人赛--第八场--D
- 暑期个人赛--第一场--E
- 暑期个人赛--第一场--A -
- 暑期个人赛--第一场--B
- 暑期个人赛--第一场--C
- 暑期个人赛--第二场--D--every SG(重)
- 暑期个人赛--第四场--D(待A)
- 中石油 暑期集训个人赛第一场 题解
- 暑期个人赛第二场
- 暑期个人赛--第六场--D(包含手写邻接链表模板~!!)
- 暑期个人赛--第七场--D(复习~!含静态邻接链表)
- 暑期个人赛--第三场--B
- 暑期个人赛--第三场--A
- C++项目——人数不定的工资类
- printf 的串口输入重定向
- getRequestDispatcher 和sendRedirect区别2
- IBM raid相关操作
- OCP 1Z0 053 194
- 暑期个人赛--第一场--D
- Mysql的varchar(20)到底可以存储多少个中文字符
- 字符串的比较——strcmp
- 2014 Multi-University Training Contest 1/HDU4861_Couple doubi(数论/规律)
- poj-2531
- 【学习记录】面向对象的基础概念
- 编辑器Sublime Text安装配置
- 【git】warning: LF will be replaced by CRLF | fatal: CRLF would be replaced by LF
- Android监听apk的添加、安装、改变、替换、卸载