Stars Drawing (Easy Edition and Hard Edition)

Problem - 1015E2 - Codeforces 

Sample 1

InputcopyOutputcopy
6 8
....*...
...**...
..*****.
...**...
....*...
........
3
3 4 1
3 5 2

Sample 2

InputcopyOutputcopy
5 5
.*...
****.
.****
..**.
.....
3
2 2 1
3 3 1
3 4 1

Sample 3

InputcopyOutputcopy
5 5
.*...
***..
.*...
.*...
.....
-1

Sample 4

InputcopyOutputcopy
3 3
*.*
.*.
*.*
-1

 

 简单讲,就是给你一个n * m的图问你能否用n * m以内个星星重现它,其中每次放置星星必须按上图所示以星星的形状放置

如果可以输出放置次数

放置星星中心点坐标 星星辐射长度(!=0)

星星可以重叠但是放置个数不能超过n * m 不要求为最优解

 Easy Edition

简单版直接模拟即可

// Problem: F - Stars Drawing (Easy Edition)
// Contest: Virtual Judge - 22练习赛
// URL: https://vjudge.net/contest/575376#problem/F
// Memory Limit: 256 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<string>
#include<cstring>
#include<cmath>
#include<bitset>
#include<sstream>//切割strtream头文件
#include<climits>//INT_MAX文件
#include <utility>
#include<memory>//for unique_ptr shared_ptr
using i64 = int64_t;
using namespace std;
#define int i64
#define endl '\n'
#define AC return 0;
#define WA(x) cout << x << endl;
#define lowbit(x) x & -x
const int maxn = 1e3 + 10;
int n, m, k, d, T = 1, A, B;

template<typename T>void read(T &x) {
    T f = 1;x = 0;char s = getchar();
    while(s < '0' || s > '9') {if(s == '-')f = -1;s = getchar();}
    while(s >= '0' && s <= '9') {x = x * 10 + s - '0';s = getchar();}
    x *= f;
}

template<typename T>void print(T x) {
    if(x < 0) putchar('-'),x = -x;
    if(x > 9) print(x / 10);
    putchar(x % 10 + '0');
    putchar('\n');
}
constexpr int Init(int x)
{
	return x * 2;
}
char ch[maxn][maxn];
vector<pair<int,int>>v;
map<pair<int,int>,int>ans;
bool vis[maxn][maxn];
void check(int x,int y)
{
	int cnt = maxn;
	int num = 0;
	int nx = x,ny = y;
	while(nx >= 1 && ch[--nx][ny] == '*'){num++;}
	cnt = min(cnt,num);num = 0;nx = x;
	while(nx <= n && ch[++nx][ny] == '*'){num++;}
	cnt = min(cnt,num);num = 0;nx = x;
	while(ny >= 0 && ch[nx][--ny] == '*'){num++;}
	cnt = min(cnt,num);num = 0;ny = y;
	while(ny <= m && ch[nx][++ny] == '*'){num++;}
	cnt = min(cnt,num);num = 0;ny = y;
	if(cnt == 0)return;
	v.emplace_back(make_pair(x,y));
	ans[make_pair(x,y)] = cnt;
	vis[x][y] = true;
	for(int i = 1;i <= cnt;i++)
	vis[x][y + i] = vis[x][y - i] = vis[x + i][y] = vis[x - i][y] = true;
}

void solve()
{
	auto x = make_unique<int>();
	cin >> n >> m;
	for(int i = 1;i <= n;i++)
	cin >> ch[i] + 1;
	for(int i = 1;i <= n;i++)
	{
		for(int j = 1;j <= m;j++)
		{
			if(ch[i][j] == '*')
			check(i,j);
		}
	}
	bool is = true;
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= m;j++)
			if(ch[i][j] == '*' && !vis[i][j])is = false;
			
	if(is)
	{
		cout << v.size() << endl;
		for(auto x : v)
			cout << x.first << " " << x.second << " " << ans[make_pair(x.first,x.second)] << endl;
	}
	else cout << -1 << endl;
	
}
 
signed main() {
    cin.tie(0) -> sync_with_stdio(false);
    int T = 1;
   	//read(T);
    while (T--) solve();
    return 0;
}

 Hard Edition

// Problem: F - Stars Drawing (Easy Edition)
// Contest: Virtual Judge - 22练习赛
// URL: https://vjudge.net/contest/575376#problem/F
// Memory Limit: 256 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<string>
#include<cstring>
#include<cmath>
#include<bitset>
#include<sstream>//切割strtream头文件
#include<climits>//INT_MAX文件
#include <utility>
#include<memory>//for unique_ptr shared_ptr
using i64 = int64_t;
using namespace std;
#define int i64
#define endl '\n'
#define AC return 0;
#define WA(x) cout << x << endl;
#define lowbit(x) x & -x
const int maxn = 1e3 + 10;
int n, m, k, d, T = 1, A, B;

template<typename T>void read(T &x) {
    T f = 1;x = 0;char s = getchar();
    while(s < '0' || s > '9') {if(s == '-')f = -1;s = getchar();}
    while(s >= '0' && s <= '9') {x = x * 10 + s - '0';s = getchar();}
    x *= f;
}

template<typename T>void print(T x) {
    if(x < 0) putchar('-'),x = -x;
    if(x > 9) print(x / 10);
    putchar(x % 10 + '0');
    putchar('\n');
}
constexpr int Init(int x)
{
	return x * 2;
}
char ch[maxn][maxn];
vector<pair<int,int>>v;
map<pair<int,int>,int>ans;
bool vis[maxn][maxn];
bool check(int x,int y)
{
	return ch[x][y] == '*';
}
bool check(int x,int y,int k)
{
	return (x - k >= 1) && (x + k <= n) && (y - k >= 1) && (y - k <= m) && check(x - k,y) && check(x + k,y) && check(x,y - k) && check(x,y + k);
}

void solve()
{
	auto x = make_unique<int>();
	cin >> n >> m;
	for(int i = 1;i <= n;i++)
	cin >> ch[i] + 1;
	for(int i = 2;i < n;i++)
	{
		for(int j = 2;j < m;j++)
		{
			if(!check(i,j) || !check(i + 1,j) || !check(i - 1,j) || !check(i,j - 1) || !check(i,j + 1))continue;
			vis[i][j] = true;
			for(k = 1;check(i,j,k);k++)vis[i + k][j] = vis[i - k][j] = vis[i][j + k] = vis[i][j - k] = true;
			v.emplace_back(make_pair(i,j));
			ans[make_pair(i,j)] = k - 1;
		}
	}
	
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= m;j++)
			if(ch[i][j] == '*' && !vis[i][j]){cout << -1 << endl;return;}
	cout << v.size() << endl;
	for(auto x : v)
		cout << x.first << " " << x.second << " " << ans[make_pair(x.first,x.second)] << endl;
	
}
 
signed main() {
    cin.tie(0) -> sync_with_stdio(false);
    int T = 1;
   	//read(T);
    while (T--) solve();
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值