codeforces 1015E1&&E2
3 seconds
256 megabytes
standard input
standard output
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 00 are not allowed).
Let's consider empty cells are denoted by '.', then the following figures are stars:
The leftmost figure is a star of size 11, the middle figure is a star of size 22 and the rightmost figure is a star of size 33.
You are given a rectangular grid of size n×mn×m consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from 11 to nn, columns are numbered from 11 to mm. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed n⋅mn⋅m. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes.
In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most n⋅mn⋅m stars.
The first line of the input contains two integers nn and mm (3≤n,m≤1003≤n,m≤100) — the sizes of the given grid.
The next nn lines contains mm characters each, the ii-th line describes the ii-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only.
If it is impossible to draw the given grid using stars only, print "-1".
Otherwise in the first line print one integer kk (0≤k≤n⋅m0≤k≤n⋅m) — the number of stars needed to draw the given grid. The next kk lines should contain three integers each — xjxj, yjyj and sjsj, where xjxj is the row index of the central star character, yjyj is the column index of the centralstar character and sjsj is the size of the star. Each star should be completely inside the grid.
6 8
....*...
...**...
..*****.
...**...
....*...
........
3
3 4 1
3 5 2
3 5 1
5 5
.*...
****.
.****
..**.
.....
3
2 2 1
3 3 1
3 4 1
5 5
.*...
***..
.*...
.*...
.....
-1
3 3
*.*
.*.
*.*
-1
In the first example the output
2
3 4 1
3 5 2
is also correct.
题意:给你一个大小为n*m的图,求其中‘*’的十字架大小
题解:暴力,记得给走过的路打标记
代码如下:
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#define fuck(x) cout<<"["<<x<<"]";
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w+",stdout);
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int maxn = ;
char str[maxn][maxn];
bool vis[maxn][maxn];
int n,m;
struct node {
int x,y,cnt;
}; std::vector<node> v; bool check(int x,int y,int r){
if(x+r>=n||x-r<||y+r>=m||y-r<) return ;
return ;
} int main(){
#ifndef ONLINE_JUDGE
FIN
#endif scanf("%d%d",&n,&m);
for(int i=;i<n;i++){
scanf("%s",str[i]);
} for(int i=;i<n;i++){
for(int j=;j<m;j++){
int cnt=;
if(str[i][j]=='*'){
for(int a=; ;a++){
if(check(i,j,a)){
if(str[i+a][j]=='*'&&str[i-a][j]=='*'&&str[i][j+a]=='*'&&str[i][j-a]=='*'){
cnt++;
vis[i+a][j] = vis[i-a][j] = vis[i][j+a] = vis[i][j-a] = ; //求十字架的长度
vis[i][j] = ;
}else break;
}else break;
}
}
if (cnt != )
v.push_back(node{i+, j+, cnt});
}
} bool ok = ;
for (int i = ; i < n; i++){
for (int j = ; j < m; j++){
if (str[i][j] == '*' && !vis[i][j]){
ok = ;
break;
}
}
} if (!ok){
printf("-1\n"); }else{
printf("%d\n", v.size());
for (int i = ; i < v.size(); i++){
printf("%d %d %d\n", v[i].x, v[i].y, v[i].cnt);
}
} }
codeforces 1015E1&&E2的更多相关文章
- Codeforces 1005 E2 - Median on Segments (General Case Edition)
E2 - Median on Segments (General Case Edition) 思路: 首先我们计算出solve(m):中位数大于等于m的方案数,那么最后答案就是solve(m) - s ...
- Codeforces 1015E1 Stars Drawing (Easy Edition)
题面: 传送门 题目描述: 要求用十字星星来画题目给出的"星"图.如果不能用十字星星来画"星"图,输出-1:如果能,则输出要在图的哪个位置画相应大小的十字星图. ...
- Codeforces 1108E2 Array and Segments (Hard version) 差分, 暴力
Codeforces 1108E2 E2. Array and Segments (Hard version) Description: The only difference between eas ...
- Codeforces Round #535 (Div. 3) E2. Array and Segments (Hard version) 【区间更新 线段树】
传送门:http://codeforces.com/contest/1108/problem/E2 E2. Array and Segments (Hard version) time limit p ...
- codeforces 391E2 (【Codeforces Rockethon 2014】E2)
题目:http://codeforces.com/problemset/problem/391/E2 题意:有三棵树.每棵树有ni个结点,加入两条边把这三棵树连接起来,合并成一棵树.使得合并的树 ...
- CodeForces -Codeforces Round #496 (Div. 3) E2. Median on Segments (General Case Edition)
参考:http://www.cnblogs.com/widsom/p/9290269.html 传送门:http://codeforces.com/contest/1005/problem/E2 题意 ...
- Codeforces Round #584 E2. Rotate Columns (hard version)
链接: https://codeforces.com/contest/1209/problem/E2 题意: This is a harder version of the problem. The ...
- Codeforces Round #567 (Div. 2) E2 A Story of One Country (Hard)
https://codeforces.com/contest/1181/problem/E2 想到了划分的方法跟题解一样,但是没理清楚复杂度,很难受. 看了题解觉得很有道理,还是自己太菜了. 然后直接 ...
- Codeforces Round #617 (Div. 3) String Coloring(E1.E2)
(easy version): 题目链接:http://codeforces.com/contest/1296/problem/E1 题目一句话就是说,两种颜色不同的字符可以相互换位, 问,对这字符串 ...
随机推荐
- 002---Python基本数据类型--字符串
字符串 .caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { border: 1p ...
- 【Java】关于Spring MVC框架的总结
SpringMVC是一种基于Java,实现了Web MVC设计模式,请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将Web层进行职责解耦.基于请求驱动指的就是使用请求-响应模型,框架的 ...
- List中的FindAll用法
在泛型List中查找符合某个字段的全部数据,可以采用如下方式: //1.现将实体数据listList<ADDaAn> objDAList = db.ADDaAns.ToList(); // ...
- idea离线安装lombock插件
技术交流群:233513714 安装过程 1.首先找到插件包 插件包可以在两个地方下载,分别是IDEA的官方插件仓库和GitHub里lombok-intellij-plugin仓库中的release包 ...
- SSM框架学习思维导图
SSM框架学习思维导图 2017年08月11日 20:17:28 阅读数:1141 放上前段时间学习SSM框架以及Spring.SpringMVC.MyBatis的学习结果,输出思维导图一共四幅图.这 ...
- 3招搞定APP注册作弊
在说如何应对之前,易盾先给各位盾友梳理移动端APP可能遇到哪些作弊风险.1. 渠道商刷量,伪造大量的下载量和装机量,但没有新用户注册:2. 对于电商.P2P.外卖等平台,会面临散户或者团队刷子的注册- ...
- Java byte 位移操作 注意事项
转自:http://blog.163.com/pilgrim_yang/blog/static/55631481201111542151582/ Java对byte 的 + - * / >> ...
- Linux初步——常用简单命令
散乱的记录,目前是边学边用,以后有机会再整理 curl命令 发起一个HTTP请求,如:curl "http://www.baidu.com" 加上-I选项查看HTTP协议头的信息, ...
- C++学习002-C++代码中插入汇编语句
在C++中我们有时会遇到使用汇编语言的情况,这时可以在前面加上关键字“_asm”宏. 如下示例 编写环境 :vs2015 int main() { __asm mov al, 0x20; __asm ...
- 使用hibernate连接Oracle时的权限问题
在使用hibernate对象关系映射连接和创建表的时候,会涉及到很多权限问题,有些数据库管理会将权限设的很细,我们可以根据后台日志错误和异常信息作出判断. 比如下图所示这个错误(这是我在给银行投产系统 ...