ppm(P3)ใใppm(P2)ใธใฎๅคๆใใใ
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define loop for(;;)
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;
#define inf (1e9)
template<class S, class T> inline
ostream& operator<<(ostream&os, pair<S,T> p) {
os << '(' << p.first << ", " << p.second << ')';
return os;
}
template<class T> inline
ostream& operator<<(ostream&os, vector<T> v) {
if (v.size() == 0) {
os << "(empty)";
return os;
}
os << v[0];
for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
return os;
}
template<class T> inline
istream& operator>>(istream&is, vector<T>&v) {
rep (i, v.size()) is >> v[i];
return is;
}
template<class S, class T, class U> inline
ostream& operator<<(ostream&os, tuple<S, T, U> t) {
return os << '(' << get<0>(t) << ", " << get<1>(t)
<< ", " << get<2>(t) << ')';
}
using vi = vector<int>;
using vvi = vector<vi>;
void display(string format, int w, int h, int c, vvi gray) {
cout << format << endl;
cout << w << ' ' << h << endl;
cout << c << endl;
rep (i, h) {
rep (j, w) {
cout << min(c, max(0, gray[i][j]));
cout << (j%15==14 ? '\n' : ' ');
}
cout << endl;
}
}
int main(int argc, char*argv[]) {
string format; cin >> format;
int w, h; cin >> w >> h;
int area = w * h;
int c; cin >> c;
vector<vvi> cols(3, vvi(h, vi(w)));
rep (i, h) {
rep (j, w) {
cin
>> cols[0][i][j]
>> cols[1][i][j]
>> cols[2][i][j];
rep (k, 3) cols[k][i][j] = c - cols[k][i][j];
}
}
// embossing
const int D = 4;
rep (k, 3) {
rep (i, h) {
rep (j, w) {
int max_c = 0;
int min_c = c;
for (int dx = -D; dx <= D; ++dx) {
for (int dy = -D; dy <= D; ++dy) {
int x = i + dx;
int y = j + dy;
if (x < 0 or y < 0 or x >= h or y >= w) continue;
max_c = max(max_c, cols[k][x][y]);
min_c = min(min_c, cols[k][x][y]);
}
}
int mid_c = (max_c + min_c) / 2;
for (int dx = -D; dx <= D; ++dx) {
for (int dy = -D; dy <= D; ++dy) {
int x = i + dx;
int y = j + dy;
if (x < 0 or y < 0 or x >= h or y >= w) continue;
int c = cols[k][x][y];
cols[k][x][y] = c < mid_c ? 0 : c;
}
}
} } }
cerr << "embossing: done" << endl;
vvi gray(h, vi(w, c));
rep (k, 3) { // random walk for-each color
int x = rand() % h,
y = rand() % w;
rep (_, area/2) {
const int D = 10;
int dx, dy,
x2, y2;
rep (__, 10) {
dx = rand() % (2*D+1) - D;
dy = rand() % (2*D+1) - D;
x2 = max(0, min(h - 1, x + dx));
y2 = max(0, min(w - 1, y + dy));
if (x == x2 and y == y2) continue;
if (cols[k][x2][y2] > rand()%c) break;
}
{ // draw a line
int weight = (cols[k][x2][y2] + cols[k][x][y]) / 10;
for (int d = 0; d <= D; ++d) {
int xi = x + d * (x2 - x) / D;
int yi = y + d * (y2 - y) / D;
gray[xi][yi] -= weight;
cols[k][x][y] -= weight;
}
}
x = x2; y = y2;
}
}
display("P2", w, h, c, gray);
return 0;
}
้ญ้ฃใใจใใ่ก็บใ็ฎใฎๅฝใใใซใใๆ
้ญใฏไฝใฎใใใซ็ใใฆใใใฎใ ใใใจ็ๅฃใซ่ใใใฎใ่ฆใใฆใใ
ใใใฏใใฃใใจใใใๅจฏๆฅฝใจใใฆใฎใ็ฉ็ใ
ไบบ้ใฎ้ฝๅใฎใใใซ้ฃผใใใ้ญใฏๆฑบใใฆๅฏๆใใใใ็บใฎใใฎใใใชใ
ใกใใฃใจ่ใใ่ปขๆใใใจใๆฐดๆ้คจใฎ้ญใจใใใฎใใใตใคใใๅฏๆใใใใใใฎใงใฏใชใใ ใใ
็ฅไฟ็บใใใๆฅไปใไปฃใใๅใฎๆจๆฅใฏๆ ็ปใฎๆฅใงใใฃใใฎใงใ ๆ ็ปใ่ฆใใใใซๆฑ ่ขใซ่กใใใจใซใใใ ใใฎ้ ใพใๆใใชใฎใงใ็งใฎ่ถณใฏ่ช่ปข่ปใงใใฃใใ ใใคใ่ตฐใ้ใ ใจใ็ฅไฟ็บใใใพใฃใใใซๆง็ฝๅฑฑ้ใใงๅใซ่ตฐใใ ๅ็ณใฎใใใใงใไธๅฟ้ใใงไปๅบฆใฏใพใฃใใ่ฅฟใซๅใใฃใฆๆฅๆฅ้ใใซใถใคใใใพใง่ตฐใใ ไปๅบฆใฏใใใใๅฐใๅใซ่ตฐใใจๆฑ ่ขใงใใใ ใฉใใช้่ทฏใๅจใใใซใใใใใไธ่ฌ็ใซ่จใฃใฆใใใใฏ็ก้งใฎใใ่ตฐ่ทฏใงใใใใ ๆใใซไธ็ด็ทใซ่กใใๆนใ่ฟ้ใงใใใ ใใใใใใใงไปๆฅใฏใ่ฟ้ใ็ฎๆใใฆใไปใพใง่ตฐใฃใใใจใใชใ้ใ ใใ่ตฐใฃใฆๆฑ ่ขใพใง่กใใใจใซใใใ ใฉใใ่ฆ็ฅใใฌ้ใงใใใ ่ฆ็ฅใฃใ้ใใใใใ่ตฐใใปใใ่ฟใใซๆฑบใพใฃใฆใใใฎใงใใใใ ใใใฏใพใใ ไธใคใฎ้ใณใ ใ ่ชๅใใใใใใง่ฟทๅญใซใชใใ ๅญไพใใใใๆขๆคใใฃใใ ใ ่กใใฏๅคช้ฝใๅบใฆใใใใ็ฐกๅใ ใฃใใ ๆฏ่ผ็็ฐกๅใซใๆฅๆฅ้ใใซใถใคใใใใจใใงใใใ ็ฅไฟ็บใใใไธๆฆใ้ฃฏ็ฐๆฉใพใง่ตฐใฃใฆใใใใใๅคงไฝ็ๅใ็ฎๆใใใ ๅฐ็ณๅทใ้ใใฌใใ่่ท่ฐทใจใใๆๅญใ็ฎๆใใฆ่ตฐใใจใๆฅๆฅ้ใใฏ้ๅๆดๅใใใฆใใใ ้ไธญใง้ใฃใๅฐ็ณๅทๅไธ็ฎใฏไปๆใฎๆใฟ้ใฃใ็บใงใใใใใใใใใใฃใๆฝ่จญใๅนผ็จๅใใใ่ฆๅใใใใใ ๅญใฉใใใกใฏๅ ฌ้ใฎไธใงใญใฃใใใใผใซใใใ ๆญ็ฃจๅใใใไธฆๆจใฏใๆฑไบฌใฎ็ใไธญใจใใฆใฏ็ใใใใใใฎ็ท่ฒใ็งใซ่ฆใใฆใใใฆใ ๅคงๅคใฎใฉใใงๅนณๅใชๅฐ่ฑกใงใใฃใใ
ใฉใใใฉใ่ตฐใฃใฆใใๅฐ็ณๅทๆค็ฉๅใจใถใคใใฃใฆๅคงๅค้ช้ญใ ใฃใใ ๆฑ ่ขใใใฎๅธฐใใ็ฅใใชใ้ใใงใใใ ใ่ตฐใใใจใซใใใ ใชใใ็งใฏ็พไปฃไบบใใใใใฌในใใผใใใฉใณใชใใฆใใฎใๆใใชใใฎใงใ ๆฌๅฝใซ่ฟทๅญใซใชใฃใใๆฌๅฝใซใใงใใใ ใใใใพใใๆใใฐใ ใใใจใกใใฃใจ่ฟทๅญใซใชใฃใฆใฟใ่ถฃๅณใฏๅคงๆใใใ ใฃใใ ใใใฏ่จใฃใฆใฟใใฐใๅนณๅกใชๆฅๅธธใซใกใใฃใจใใในใชใซใๅ ใใใใจใงใใใ ในใใผใใใฉใณใใชใใฆใใ้่ทฏๆจ่ญใใใ่ฆใฆใใใฐๅคงไฝ่ชๅใใฉใใซใใใใใใใใ ่ชๅใ้ซๆ ก็ใฎ้ ใฏใใใฃใกใ ใใไบค็ชใซ้ใ่จชใญใฆใ้ง ใฎๅ ดๆใๅฐใญใใใใ่ฃใ ใฃใใชใใฆใใจใใใใ ่ชๅใ่กใๅฟ ่ฆใฎใใๆฐใซๆใๅฎถใๅคงๅญฆใๆฌๅฑใใใๆ ็ป้คจใใใใใใคใชใใใใใ ใๆฐๆฌใฎ้ใ ใใ่ตฐใใฎใๆฅๅธธใ ใจ่ใใฆใใใจใใใซ็ฑๆฅใใใฎใงใฏใชใใใ ใคใพใใ ๆ ่กใซ่กใใชใใฆใใใใชใใจใใไบบใๆฌๅฝใซใใใชใใฆใๆใใชใใฃใใ ใใใใใใใใใใ ใใใใฉใใ ๆ ่กไผ็คพใฃใฆใใใใใ ใงใใ ใใใฃใฆใ ใใใใ่ชๅใฎใ้ใๆใฃใฆใ ใ๏ผ ๆฅฝใใใใฉใใใๅฎใใใใชใใใ ใฎ็งปๅใ ใใ ็ด็ฒใซๆ ่กใ็ฎ็ใซใใๆ ่กใชใใฆใ่ชๅใใใใใจใใใใใใใ
ใใใใทใงใใใซใใใฆใ ๅคงใพใใซใใใฐใ็ฌใจ็ซใจใใใฎไป๏ผ้ญใจใ๏ผใๆฑใใใใ ็ฌใจ็ซใไธปๅฝนใ ใ ใใฎไปใใใชใใก้ญ้กใชใใใฏใๅฏๆใใใใชใใ ๅฎขใซใใงใฏใชใใฆใๅบๅกใซใใ ใ ๅฐใชใใใใไธ้จใฎๅฎขใฏใ็ฑๅธฏ้ญใใใซ็ฑๅฟใ ใ ๆใ ใใ็ฑๅฟใ ใ ใ ใฃใฆใใใใชใใ ใฎๆฐด่ใใใใใ่ฒทใฃใฆใใใใ ใใใ ใใใใงใๅ ฅใใฆใใใฐใใใฎใซใ ๅคงๅขใฎ็พคใใใชใ้ญใฏใ ๆฐดๆ้คจใซใใใฆใฏใๅฎขใซใๆฐดๆ้คจใฎไบบใซใๅฏๆใใใใชใใใ ใใใชใใ
ใใใใใชใใใจใใใฆใพใใใ
Rubpix
ใชใFlash่ฃฝใใบใซใใใฃใฆใฆใใ ใใ ใ่พใใชใฃใฆใใใฎใงใ ่งฃใใใญใฐใฉใ ใๆธใไฝๆฆใซๅคๆดใใ
ใฏใใใฏ \(3 \times 3\) ใงใๅใงๅบๆฅใใใ ใใฉใ้ฃฝใใฆใใ
ในใใผใธใไธใใใใจใซใ\(n\)ใฎๆฐใฏๅพใ
ใซๅขใใใใใใ
\(4 \times 4\) ใซใชใใจใใใๆฌๆ ผ็ใซ้ฃใใใๆใใฆใใ
ใพใ ็งใฏใใฎ็ป้ขใ่ฆใใใจใใชใใใ"rubpix" ใง็ปๅๆค็ดขใใใใจใ \(6 \times 6\) ใๅบใฆใใ
ไปฅไธใฏ \(n \times n\) ใฎๅ ดๅใซใคใใฆใๅๆนๅๆข็ดขใง่งฃใใใญใฐใฉใ
\(6 \times 6\) ใงใ็พๅฎ็ใชๆ้ใง่งฃใใใฎใใกใใฃใจ่ชไฟกใใชใ
้ ญใฎใใใใฅใผใชในใใฃใใฏใๅ
ฅใใในใใ
// you can read this source
// also at: https://gist.github.com/cympfh/3ddc2e84211f37a81bb1
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define loop for(;;)
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;
#define inf (1e9)
template<class S, class T> inline
ostream& operator<<(ostream&os, pair<S,T> p) {
os << '(' << p.first << ", " << p.second << ')';
return os;
}
template<class T> inline
ostream& operator<<(ostream&os, vector<T> v) {
if (v.size() == 0) {
os << "(empty)";
return os;
}
os << v[0];
for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
return os;
}
template<class T> inline
istream& operator>>(istream&is, vector<T>&v) {
rep (i, v.size()) is >> v[i];
return is;
}
template<class S, class T, class U> inline
ostream& operator<<(ostream&os, tuple<S, T, U> t) {
return os << '(' << get<0>(t) << ", " << get<1>(t)
<< ", " << get<2>(t) << ')';
}
using vi = vector<char>;
using vvi = vector<vi>;
enum Dir {
Down = 0,
Up = 1,
Left = 2,
Right = 3
};
Dir invert(Dir d) {
if (d == Down) return Up;
if (d == Up) return Down;
if (d == Left) return Right;
if (d == Right) return Left;
}
struct Op {
Dir dir; int pos;
Op(int _pos, Dir _d) : pos(_pos), dir(_d) {}
};
inline
ostream& operator<<(ostream&os, Op o) {
os << "pos[ " << o.pos << " ] ";
if (o.dir == Left) os << "Left";
if (o.dir == Right) os << "Right";
if (o.dir == Up) os << "Up";
if (o.dir == Down) os << "Down";
return os;
}
inline void
mov_left(vi&v, int n, int k) {
char tmp = v[n*k];
rep (i, n - 1) v[n*k+i] = v[n*k+i+1];
v[n*k+n-1] = tmp;
}
inline void
mov_right(vi&v, int n, int k) {
char tmp = v[n*k+n-1];
rep (i, n - 1) v[n*k+n-i-1] = v[n*k+n-i-2];
v[n*k] = tmp;
}
inline void
mov_up(vi&v, int n, int k) {
char tmp = v[k];
rep (i, n - 1) v[k + n * i] = v[k + n * (i+1)];
v[k + (n-1)*n] = tmp;
}
inline void
mov_down(vi&v, int n, int k) {
char tmp = v[k + (n-1)*n];
rep (i, n - 1) v[k + n*(n-i-1)] = v[k + n*(n-i-2)];
v[k] = tmp;
}
vector<pair<vi, Op>> step(int n, vi v) {
vector<pair<vi, Op>> ret;
rep (k, n) {
mov_left(v, n, k);
ret.push_back({ v, Op(k, Left) });
mov_right(v, n, k);
mov_right(v, n, k);
ret.push_back({ v, Op(k, Right) });
mov_left(v, n, k);
}
rep (k, n) {
mov_up(v, n, k);
ret.push_back({ v, Op(k, Up) });
mov_down(v, n, k);
mov_down(v, n, k);
ret.push_back({ v, Op(k, Down) });
mov_up(v, n, k);
}
return ret;
}
bool equal(vi&xs, vi&ys) {
int n = xs.size();
if (ys.size() != n) return false;
rep (i, n)
if (xs[i] != ys[i]) return false;
return true;
}
map<vi, vector<Op>> memo;
map<vi, vector<Op>> r_memo;
int main(int argc, char*argv[]) {
int n; cin >> n;
vi f(n*n), g(n*n);
rep (i, n*n) cin >> f[i];
rep (i, n*n) cin >> g[i];
trace(f); trace(g);
vector<Op> ops;
queue<pair<vi, bool>> q;
q.push({ f, true });
q.push({ g, false });
memo[f] = {};
r_memo[g] = {};
while (not q.empty()) {
auto tp = q.front(); q.pop();
auto&f = tp.first;
auto d = tp.second;
if ((d and r_memo.count(f) > 0) or ((not d) and memo.count(f) > 0)) {
for (auto&o: memo[f])
cout << o << endl;
for (int i = r_memo[f].size() - 1; i >= 0; --i) {
Op&o = r_memo[f][i];
o.dir = invert(o.dir);
cout << r_memo[f][i] << endl;
}
return 0;
}
for (auto&p: step(n, f)) {
auto&f2 = p.first;
auto o = p.second;
if (d) {
if (memo.count(f2) > 0) continue;
vector<Op> hs2 = memo[f];
hs2.push_back(o);
memo[f2] = hs2;
} else {
if (r_memo.count(f2) > 0) continue;
vector<Op> hs2 = r_memo[f];
hs2.push_back(o);
r_memo[f2] = hs2;
}
q.push({f2, d});
}
}
return 0;
}
$ cat input
4
YYYY
YGYG
RRGR
RGYY
YYYY
GGGG
RRRR
YYYY
$ ./a.out < input
pos[ 1 ] Up
pos[ 2 ] Up
pos[ 2 ] Left
pos[ 1 ] Down
pos[ 0 ] Up
pos[ m ]
(\(0 \leq m < n\)) \(m\) ่ก็ฎใใพใใฏ \(m\) ๅ็ฎใ่กจใ
ใใ ใใ ็คใฎๆไธๆฎตใ0่ก็ฎใๆๅทฆๅใ0ๅ็ฎใ ใจใใฆๆฐใใ
(ไบบ้ใ่ชญใ้จๅใใใใ1-indexedใซใใใใฎใ ใจๅ็ใใ)
ไปใฎๅ ดๅ
ใจใใๆ้ ใ่กจใ
ไธใคใฎในใใผใธใใฏใชใขใใๅบฆใซใ ๅ ฅๅใไฝใไฝๆฅญใไธ็ชใฎๆ้ใ ใฃใ