Codeforces Round #607 (Div. 2) D. Beingawesomeism
https://codeforces.com/contest/1281/problem/D
제목:
You are an all-powerful being and you have created a rectangular world. In fact, your world is so bland that it could be represented by a r×c grid. Each cell on the grid represents a country. Each country has a dominant religion. There are only two religions in your world. One of the religions is called Beingawesomeism, who do good for the sake of being good. The other religion is called Pushingittoofarism, who do murders for the sake of being bad.
Oh, and you are actually not really all-powerful. You just have one power, which you can use infinitely many times! Your power involves missionary groups. When a missionary group of a certain country, say a, passes by another country b, they change the dominant religion of country b to the dominant religion of country a.
In particular, a single use of your power is this:
You choose a horizontal 1×x subgrid or a vertical x×1 subgrid. That value of x is up to you; You choose a direction d. If you chose a horizontal subgrid, your choices will either be NORTH or SOUTH. If you choose a vertical subgrid, your choices will either be EAST or WEST; You choose the number s of steps; You command each country in the subgrid to send a missionary group that will travel s steps towards direction d. In each step, they will visit (and in effect convert the dominant religion of) all s countries they pass through, as detailed above. The parameters x, d, s must be chosen in such a way that any of the missionary groups won't leave the grid. The following image illustrates one possible single usage of your power. Here, A represents a country with dominant religion Beingawesomeism and P represents a country with dominant religion Pushingittoofarism. Here, we've chosen a 1×4 subgrid, the direction NORTH, and s=2 steps.
You are a being which believes in free will, for the most part. However, you just really want to stop receiving murders that are attributed to your name. Hence, you decide to use your powers and try to make Beingawesomeism the dominant religion in every country.
What is the minimum number of usages of your power needed to convert everyone to Beingawesomeism?
With god, nothing is impossible. But maybe you're not god? If it is impossible to make Beingawesomeism the dominant religion in all
아이디어:
작은 걸음부터 큰 걸음까지 걸음걸이가 충분한지 판단하고 A가 있는 위치를 측정한다.
코드:
#include
using namespace std;
char Map[100][100];
int r, c;
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
scanf("%d%d", &r, &c);
bool flag1 = false, flag2 = false;
for (int i = 1;i <= r;i++)
scanf("%s", Map[i]+1);
for (int i = 1;i <= r;i++)
{
for (int j = 1;j <= c;j++)
{
if (Map[i][j] == 'A') flag1 = true;
else flag2 = true;
}
}
if (!flag1)
{
puts("MORTAL");
continue;
}
if (!flag2)
{
puts("0");
continue;
}
for (int i = 1;i <= 4;i++)
{
if (i == 1)
{
bool ok = false;
bool tmp = true;
for (int i = 1;i <= c;i++) if (Map[1][i] == 'P')
{
tmp = false;
break;
}
if (tmp) ok = true;
tmp = true;
for (int i = 1;i <= c;i++) if (Map[r][i] == 'P')
{
tmp = false;
break;
}
if (tmp) ok = true;
tmp = true;
for (int i = 1;i <= r;i++) if (Map[i][1] == 'P')
{
tmp = false;
break;
}
if (tmp) ok = true;
tmp = true;
for (int i = 1;i <= r;i++) if (Map[i][c] == 'P')
{
tmp = false;
break;
}
if(tmp) ok = true;
if (ok)
{
puts("1");
break;
}
}
if (i == 2)
{
bool ok = false;
for (int i = 1;i <= r;i++)
{
bool tmp = true;
for (int j = 1;j <= c;j++) if(Map[i][j] == 'P')
{
tmp = false;
break;
}
if (tmp)
{
ok = true;
break;
}
}
for (int j = 1;j <= c;j++)
{
bool tmp = true;
for (int i = 1;i <= r;i++) if(Map[i][j] == 'P')
{
tmp = false;
break;
}
if (tmp)
{
ok = true; break;
}
}
if (Map[1][1] == 'A' || Map[r][1] == 'A' || Map[1][c] == 'A' || Map[r][c] == 'A') ok = true;
if (ok)
{
puts("2");
break;
}
}
if (i == 3)
{
int ok = false;
for (int i = 1;i <= c;i++) if (Map[1][i] == 'A')
{
ok = true;
break;
}
for (int i = 1;i <= c;i++) if (Map[r][i] == 'A')
{
ok = true;
break;
}
for (int i = 1;i <= r;i++) if (Map[i][1] == 'A')
{
ok = true;
break;
}
for (int i = 1;i <= r;i++) if (Map[i][c] == 'A')
{
ok = true;
break;
}
if (ok)
{
puts("3");
break;
}
}
if (i == 4)
{
puts("4");
break;
}
}
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.