- Secrete Master Plan
签到题,枚举4种情况判断相同即可。
#include<cstdio>
#include<cstring>
using namespace std;
int a[4][2];
void turn()
{
int te = a[0][0];
a[0][0] = a[1][0], a[1][0] = a[1][1], a[1][1] = a[0][1], a[0][1] = te;
}
int main()
{
int t, n, i, j, ca = 1;
scanf("%d", &t);
while (t--)
{
for (i = 0; i < 4; i++)
for (j = 0; j < 2; j++)
scanf("%d", a[i] + j);
int flag = 0;
for (i = 0; i < 4; i++)
{
turn();
if (a[0][0] == a[2][0] && a[0][1] == a[2][1] && a[1][0] == a[3][0] && a[1][1] == a[3][1])
flag = 1;
}
printf("Case #%d: %s\n", ca++, flag ? "POSSIBLE" : "IMPOSSIBLE");
}
return 0;
}
L. Huatuo's Medicine
输入输出签到题,输出2*n-1。
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
int t, n, ca = 1;
scanf("%d", &t);
while (t--&&scanf("%d", &n))
printf("Case #%d: %d\n", ca++, 2 * n - 1);
return 0;
}
H. Sudoku
水题,写过搜索专题解9*9数独的再写这个完全没问题,怎么写都行。
#include<cstdio>
#include<cstring>
using namespace std;
char s[7][7];
int ok[5][5][5];
int flag;
void add(int x, int y, int z)
{
int i, j;
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
if (x == i || j == y || (i / 2 == x / 2) && (j / 2 == y / 2))
ok[i][j][z]++;
}
void del(int x, int y, int z)
{
int i, j;
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
if (x == i || j == y || (i / 2 == x / 2) && (j / 2 == y / 2))
ok[i][j][z]--;
}
void dfs(int x, int y)
{
int i, j, k;
if (x == 4)
{
flag = 1;
return;
}
for (i = x; i < 4; i++)
for (j = (i == x) ? y : 0; j < 4; j++)
if (s[i][j] == '*')
{
for (k = 1; k <= 4; k++)
if (ok[i][j][k] == 0)
{
add(i, j, k);
s[i][j] = k + '0';
if (j == 3)
dfs(i + 1, 0);
else dfs(i, j