本文主要是介绍1496 E. Garden of the Sun(构造+思维),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目:https://codeforc.es/contest/1496/problem/E
题解参考:大佬
题解说明:认真读题,最开始任意两个'X'之间没有共同边和角,所以不存在情况
所以遇到j%3==p&&j+2<=n&&(c[i][j+1]=='X'||c[i][j+2]=='X')时直接令c[i][j+1]==c[i][j+2]==‘X'就到达了连接的目的。
总结:别害怕。cf能300+人做出来就说明我完全可能做出来(多想想)。
代码:
#include <bits/stdc++.h>#define ll long long
#define pi acos(-1)
#define pb push_back
#define mst(a, i) memset(a, i, sizeof(a))
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define rep(i, a, n) for (ll i = a; i <= n; i++)
#define per(i, n, a) for (ll i = n; i >= a; i--)
#define dbg(x) cout << #x << "===" << x << endl
#define dbgg(l, r, x) \for (ll i = l; i <= r; i++) cout << x[i] << " "; \cout << "<<<" << #x << "\n"
//多动脑,少动笔
using namespace std;template <class T>
void read(T &x) {T res = 0, f = 1;char c = getchar();while (!isdigit(c)) {if (c == '-') f = -1;c = getchar();}while (isdigit(c)) res = (res << 3) + (res << 1) + c - '0', c = getchar();x = res * f;
}
void Printf(ll x) {if (x < 0) putchar('-'), x = -x;if (x > 9) Printf(x / 10);putchar(x % 10 + '0');
}
void print(ll x, char c) { Printf(x), putchar(c); }
const ll maxn = 5e2 + 10;
const ll mod = 1e9 + 7;
const ll inf = 1e9;ll n, m, p;
char c[maxn][maxn];
void PPrint() {// cout << ">>>>>>\n";rep(i, 1, n) {rep(j, 1, m) { putchar(c[i][j]); }puts("");}
}
int main() {// freopen("testdata.in","r",stdin);// freopen("testout.out","w",stdout);ll TT = 1;read(TT);while (TT--) {read(n), read(m);if (m % 3 == 0)p = 2;elsep = 1;// dbg(p);rep(i, 1, n) {rep(j, 1, m) {cin >> c[i][j];if (j % 3 == p) c[i][j] = 'X';// if(j%3==p) putchar('X');// else putchar(c[i][j]);}// puts("");}// PPrint();rep(j, 1, m) {if (j % 3 != p) continue;if (j + 2 > m) break;bool f = false;rep(i, 1, n) {if (c[i][j + 1] == 'X' || c[i][j + 2] == 'X') {c[i][j + 1] = c[i][j + 2] = 'X';f = true;break;}}if (!f) c[1][j + 1] = c[1][j + 2] = 'X';}PPrint();}return 0;
}
这篇关于1496 E. Garden of the Sun(构造+思维)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!