B
#pragma warning (disable:4996)
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <vector>
#include <map>
#include <stack>
#include <fstream>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int SIZE = 1e3 + 20;
int n, m;
bool A[SIZE][SIZE], B[SIZE][SIZE];
int change[SIZE][SIZE];
int main() {
while (~scanf("%d%d", &n, &m)) {
string str;
for (int i = 1; i <= n; i++) {
cin >> str;
for (int j = 1; j <= m; j++) {
if (str[j - 1] == 'X')
A[i][j] = 1;
else
A[i][j] = 0;
}
}
for (int i = 1; i <= n; i++) {
cin >> str;
for (int j = 1; j <= m; j++) {
if (str[j - 1] == 'X')
B[i][j] = 1;
else
B[i][j] = 0;
}
}
int cnt = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (A[i][j] != B[i][j])
cnt++;
}
}
if (2 * cnt <= m * n) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++)
if (A[i][j]) printf("X");
else printf(".");
printf("\n");
}
}
else {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++)
if (A[i][j]) printf(".");
else printf("X");
printf("\n");
}
}
}
return 0;
}
M
#pragma warning (disable:4996)
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <vector>
#include <map>
#include <stack>
#include <fstream>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int SIZE = 1e6 + 20;
map<int, string> name;
vector<int> path[SIZE];
bool is[SIZE];
int siz = 0, ans = 0;
void initial() {
for (int i = 0; i <= siz; i++) {
path[i].clear();
is[i] = false;
}
name.clear();
siz = 0, ans = 0;
}
vector<string> split(string str) {
vector<string> res;
string tmp = "";
for (int i = 0; i < str.length(); i++) {
if (str[i] == '/') {
res.push_back(tmp);
tmp = "";
continue;
}
tmp = tmp + str[i];
}
res.push_back(tmp);
return res;
}
bool dfs(int now) {
if (path[now].empty())
return is[now];
int cnt = 0;
bool flag = true;
for (int i = 0; i < path[now].size(); i++) {
if (!dfs(path[now][i])) {
flag = false;
cnt++;
}
}
if (flag)
return true;
ans += path[now].size() - cnt;
return false;
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
int n, m;
scanf("%d%d", &n, &m);
initial();
string str;
for (int ii = 0; ii < n; ii++) {
cin >> str;
vector<string> vec = split(str);
int pos = 0;
stack<int> s;
s.push(0);
while (s.size()) {
int now = s.top();
s.pop();
bool flag = false;
for (int i = 0; i < path[now].size(); i++) {
if (name[path[now][i]] == vec[pos]) {
flag = true;
pos++;
s.push(path[now][i]);
break;
}
}
if (!flag) {
//不在当前的文件目录下
//创建文件路径
while (pos < vec.size()) {
name[++siz] = vec[pos++];
path[now].push_back(siz);
now = siz;
}
break;
}
}
}
for (int i = 0; i <= siz; i++) {
if (path[i].size() == 0) {
is[i] = true;
}
}
for (int ii = 0; ii < m; ii++) {
cin >> str;
vector<string> vec = split(str);
int pos = 0;
stack<int> s;
s.push(0);
while (s.size()) {
int now = s.top();
s.pop();
bool flag = false;
for (int i = 0; i < path[now].size(); i++) {
if (name[path[now][i]] == vec[pos]) {
flag = true;
pos++;
s.push(path[now][i]);
break;
}
}
if (!flag) {
//不在当前的文件目录下
//创建文件路径
while (pos < vec.size()) {
name[++siz] = vec[pos++];
path[now].push_back(siz);
now = siz;
}
break;
}
}
}
for (int i = 0; i < path[0].size(); i++)
if (dfs(path[0][i])) {
ans++;
}
printf("%d\n", ans);
}
return 0;
}
G
#pragma warning (disable:4996)
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <vector>
#include <set>
#include <fstream>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main() {
ll n;
while (~scanf("%lld", &n)) {
if (n == 1) {
printf("0\n");
}
else if (n == 2) {
printf("0\n");
}
else if (n == 3) {
printf("2\n");
}
else {
ll tmp = n / 3;
ll tmp1 = tmp * (n - 1);
ll tmp2 = tmp * (tmp - 1) / 2;
printf("%lld\n", tmp1 - tmp2);
}
}
return 0;
}