P1162
#include<map>
#include<vector>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
using namespace std;
const int N = 1020;
int n;
int g[N][N];//标记数组
int a[N][N];//储存数组
int dx[] = { -1,0,1,0 };
int dy[] = { 0,1,0,-1 };
bool st[N][N];
void dfs(int x, int y)
{
for (int i = 0; i < 4; i++)
{
int a = x + dx[i], b = y + dy[i];
/* cout << "经过" << a << "," << b << endl;*/
if (a < 1 || a > n || b < 1 || b > n)
{
continue;
}
if (g[a][b] !=0)
continue;
if (st[a][b])
{
continue;
}
st[a][b] = true;
g[a][b] = 1;
dfs(a, b);
st[a][b] = false;
}
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
cin >> g[i][j];
a[i][j] = g[i][j];
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (i == 1 && g[i][j] == 0 || j == 1 && g[i][j] == 0||i == n && g[i][j] == 0 || j == n && g[i][j] == 0)
{
st[i][j] = true;
g[i][j] = 1;
dfs(i, j);
}
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (g[i][j] == 0)
{
a[i][j] = 2;
}
cout << a[i][j]<<" ";
}
cout << endl;
}
return 0;
}
B2129
#include<map>
#include<vector>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
using namespace std;
const int N = 5e6;
int main()
{
double a,b,c,m1,m2,m3;
cin >> a >> b >> c;
double m;
m1 = max(a, b);
m1 = max(m1, c);
m2 = max(a + b, b);
m2 = max(m2, c);
m3 = max(a, b);
m3 = max(m3, b + c);
m = 1.0*m1 / (m2 * m3);
printf("%.3f", m);
return 0;
}
P1605
#include<map>
#include<vector>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
using namespace std;
const int N = 20;
int g[N][N];
int n, m, t;
int sx, sy, fx, fy;
int dx[] = { -1,0,1,0 };
int dy[] = { 0,1,0,-1 };
int ans = 0;
bool st[N][N];
void dfs(int x,int y)
{
for (int i = 0; i < 4; i++)
{
int a = x + dx[i], b = y + dy[i];
if (a == fx && b == fy)
{
ans++;
continue;
}
if (a < 1 || a > n || b < 1 || b > m)
{
continue;
}
if (g[a][b] !=1)
continue;
if (st[a][b])
{
continue;
}
st[a][b] = true;
dfs(a, b);
st[a][b] = false;
}
}
int main()
{
cin >> n >> m >> t;
cin >> sx >> sy >> fx >> fy;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
g[i][j] = 1;
}
}
while (t--)
{
int a, b;
cin >> a >> b;
if (a == fx && b == fy)
{
cout << 0;
return 0;
}
g[a][b] = 0;
}
st[sx][sy] = true;
dfs(sx, sy);
cout << ans;
return 0;
}