A. Wowoear
B. Mine Sweeper II
#include
using namespace std;
const int N = 1e3 + 10;
int n, m;
char s1[N][N], s2[N][N], s3[N][N];
int solve(char sa[N][N], char sb[N][N])
{
int cnt = n * m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cnt -= sa[i][j] == sb[i][j];
return cnt;
}
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%s", s1[i] + 1);
for (int i = 1; i <= n; i++) scanf("%s", s2[i] + 1);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
s3[i][j] = (s1[i][j] == '.' ? 'X' : '.');
if (solve(s1, s2) <= n * m / 2)
{
for (int i = 1; i <= n; i++) puts(s1[i] + 1);
return 0;
}
for (int i = 1; i <= n; i++) puts(s3[i] + 1);
return 0;
}
C. Sum of Log
D. Walker
主要考虑两种情况:1.相遇后扭头 2.相遇后不扭头。
对于第一种情况可以用二分的方式寻找p1,p2的相遇点,对每个相遇点分别求出两个人走完自己的路程所需最小时间。
对于第二种情况就更简单了,直接相对走到头就可以了。
#include
using namespace std;
inline double calc(double l, double r, double v, double p)
{
return (min(p - l, r - p) + r - l) / v;
}
int main()
{
int cass;
for (cin >> cass; cass; cass--)
{
double n, p1, v1, p2, v2;
cin >> n >> p1 >> v1 >> p2 >> v2;
if (p1 > p2) swap(p1, p2), swap(v1, v2);
double res = min(calc(0, n, v1, p1), calc(0, n, v2, p2));
res = min(res, max((n - p1) / v1, p2 / v2));
double l = p1, r = p2;
for (int i = 0; i < 100; i++)
{
double mid = (l + r) / 2;
double res1 = calc(0, mid, v1, p1), res2 = calc(mid, n, v2, p2);
res = min(res, max(res1, res2));
if (res1 > res2) r = mid;
else l = mid;
}
printf("%.10f\n", res);
}
}
E. The Journey of Geor Autumn
F. Fountains
G. Fibonacci
#include
using namespace std;
typedef long long ll;
int main()
{
ll n; cin >> n;
ll even = n % 3, odd = n / 3;
ll ans = odd * (odd + 1) + odd * even + (odd - 1) * 3 * odd / 2;
cout << ans;
return 0;
}
H. Rice Arrangement
I. Sky Garden
#include
using namespace std;
const double PI = acos(-1.0);
int main()
{
int n, m;
scanf("%d%d", &n, &m);
double ans = (2 * m + 2 * m * n) * n / 2;
if (m == 1) ans = 0;
for (int i = 1; i <= n; i++)
{
double len = PI * i / m;
for (int j = i; j <= n; j++)
{
double now = j - i;
for (int p = 1; p <= m - 1; p++)
now += min(len * p + (j - i), (double)i + j) * 2;
now += i + j;
if (j == i) ans += now * m;
else ans += now * m * 2;
}
}
printf("%.10f\n", ans);
return 0;
}
J. Octasection
K. Traveling Merchant
L. Traveling in the Grid World
M. Gitignore
#include
using namespace std;
typedef long long ll;
map<string, ll> q, vis;
string a[1001];
int main()
{
int cass;
for (cin >> cass; cass; cass--)
{
ll m, n;
cin >> n >> m;
vis.clear();
q.clear();
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++)
{
string x, y;
cin >> x;
for (int j = 0; j < x.size(); j++)
{
y += x[j];
if (x[j] == '/') vis[y] = 1;
}
}
ll s = 0;
for (int i = 1; i <= n; i++)
{
string x;
int flag = 0;
for (int j = 0; j < a[i].size(); j++)
{
x += a[i][j];
if (a[i][j] == '/')
{
if (q[x])
{
flag = 1;
break;
}
if (!vis[x])
{
flag = q[x] = 1;
s++;
break;
}
}
}
s += !flag;
}
cout << s << "\n";
}
return 0;
}