#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define ok puts("OK");
const int N = 105;
int n, m, k, t;
vector < int > a[N][N], b[N][N];
vector < pair < pair < int, int >, pair < int, int > > > v;
int reversed( int d )
{
int res = (d + 2) % 4;
if(res) return res;
else return 4;
}
inline void bor( int x, int y, int &d )
{
if(d == 1 && x == n)
{
d = reversed(d);
}
else if(d == 2 && y == m)
{
d = reversed(d);
}
else if(d == 3 && x == 0)
{
d = reversed(d);
}
else if(d == 4 && y == 0)
{
d = reversed(d);
}
}
inline bool can( int x, int y, int &d )
{
x += (d == 1);
x -= (d == 3);
y += (d == 2);
y -= (d == 4);
int revd = reversed(d);
if( a[x][y].size() )
{
for(int i : a[x][y])
{
//cout << x << " " << y << " " << i << endl;
if( i == revd )
{
d = revd;
return 0;
}
}
return 1;
}
else
{
x += (d == 1);
x -= (d == 3);
y += (d == 2);
y -= (d == 4);
for(int i : a[x][y])
{
//cout << x << " " << y << " " << i << " " << d << endl;
if(i == revd)
{
d = revd;
return 1;
}
}
}
return 1;
}
inline void move( int x, int y, int &d, int id )
{
b[x][y].pop_back();
//cout << a[4][1].size() << endl;
//cout << "1ID: " << id << " " << x << " " << y << " " << d << endl;
int tox = x, toy = y;
tox += (d == 1);
tox -= (d == 3);
toy += (d == 2);
toy -= (d == 4);
if( a[tox][toy].size() || a[tox + 1][toy].size() )
{
if( can( x, y, d ) )
{
}
else
{
tox += (d == 1);
tox -= (d == 3);
toy += (d == 2);
toy -= (d == 4);
//if(tox == 0 || tox == n || toy == m || toy == 0)
bor(tox, toy, d);
}
//if(tox == 0 || tox == n || toy == m || toy == 0)
bor(tox, toy, d);
}
//if(tox == 0 || tox == n || toy == m || toy == 0)
bor(tox, toy, d);
v[id].fr.fr = tox;
v[id].fr.sc = toy;
b[tox][toy].pb(d);
//cout << "2ID: " << id << " " << tox << " " << toy << " " << d << endl;
return;
}
void out()
{
for(int i = 0; i <= n; i++)
{
for(int j = 0; j <= m; j++)
{
if(a[i][j].size()) cout << '*';
else cout << 0;
}
puts("");
}
}
void start(int time)
{
for(time; time < t; time++)
{
for(int i = 0; i < k; i++)
{
move( v[i].fr.fr, v[i].fr.sc, v[i].sc.fr, i );
}
//ok;
for(int i = 0; i <= n; i++)
{
for(int j = 0; j <= m; j++)
{
a[i][j].clear();
a[i][j] = b[i][j];
}
}
//out();
}
}
main()
{
cin >> n >> m >> k >> t;
for(int i = 1; i <= k; i++)
{
int x, y, d;
cin >> x >> y >> d;
a[x][y].pb(d);
b[x][y].pb(d);
v.pb( mk( mk( x, y ), mk( d, i ) ) );
}
//out();
sort(v.begin(), v.end());
start(0);
vector < pair < pair < int, int >, pair < int, int > > > res;
for(auto i : v)
{
res.pb( mk( mk( i.sc.sc, i.sc.fr ), mk( i.fr.fr, i.fr.sc ) ) );
}
sort(res.begin(), res.end());
for(auto i : res)
{
cout << i.sc.fr << " " << i.sc.sc << " " << i.fr.sc << endl;
}
}
/*
4 4 2 3
1 1 1
3 3 4
4 4 2 4
1 1 1
3 3 4
4 4 2 2
1 1 1
3 1 3
4 4 2 2
2 1 1
3 1 3
4 2 2 3
2 1 1
3 1 1
*/
Compilation message
ants.cpp: In function 'void start(int)':
ants.cpp:146:10: warning: statement has no effect [-Wunused-value]
for(time; time < t; time++)
^
ants.cpp: At global scope:
ants.cpp:166:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
892 KB |
Output is correct |
2 |
Correct |
2 ms |
988 KB |
Output is correct |
3 |
Incorrect |
2 ms |
988 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |