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 题目一句话就是说,两种颜色不同的字符可以相互换位, 问,对这字符串 ...
随机推荐
- 完全数--Python
如果一个数恰好等于它的因子之和,则称该数为“完全数” [1] .各个小于它的约数(真约数,列出某数的约数,去掉该数本身,剩下的就是它的真约数)的和等于它本身的自然数叫做完全数(Perfect num ...
- 分享一个工作中遇得到的sql(按每天每人统计拖车次数与小修次数)
查询每人每天的数据 首先先建表 CREATE TABLE `user` ( `name` ) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CR ...
- Spark 实践
1.1 避免使用 GroupByKey 让我们看一下使用两种不同的方式去计算单词的个数,第一种方式使用 reduceByKey, 另外一种方式使用 groupByKey: val words = ...
- 读取hbase数据到mysql
先写一个自己的MyRecordWriter类 extends RecordWriter package calllog; import java.io.IOException; import java ...
- 玩转VIM之将Vim全副武装
玩转VIM之将Vim全副武装 懒癌末期的我貌似很久没有写博客了,已经欠了多少篇在计划中的博客我已然不好意思说了.好了,言归正传,在前三篇介绍了Vim作为代码编辑器之后可能会有人说,要学习那么多指令真的 ...
- 「学习记录」《数值分析》第三章计算实习题(Python语言)
第三题暂缺,之后补充. import matplotlib.pyplot as plt import numpy as np import scipy.optimize as so import sy ...
- flask_sqlalchemy中db.session是如何保持请求间独立的--源码阅读笔记
本文主要是为了验证两个问题: flask处理请求时通过新建线程.进程.协程的区别(顺带一提) flask_sqlalchemy是如何使用db.session使多个请求中保函的改变同一个表的sql操作不 ...
- 51单片机实现外部中断0-F
#include< reg51.h> #define uint unsigned int #define uchar unsigned char sfr P0M0 = 0x94; sfr ...
- Python不同进制之间的转换
不同的进制 二进制 0b101 以数字0和字母b打头的表示二进制数 如果出现大于等于2的数 会抛出SyntaxError异常 八进制 0711 以数字0打头的数字表示八进制数 如果出现大于 ...
- OpenCV彩色图像转灰度图
核心函数cvSplit(). #include<cv.h> #include<highgui.h> int main(int argc, char** argv) { IplI ...