Codeforces Round 871 (Div. 4) ABCDEF
很久没写题目了,划点水题
A. Love Story
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;
const LL MAXN = 1e18;
const LL N = 1e6, M = 4002;
const LL mod = 1e9 + 7;
int main()
{
//cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
LL T = 1;
cin>>T;
while (T--)
{
string s = "codeforces";
string c;
cin >> c;
LL ans = 0;
for (int i = 0; i < c.size(); i++)
{
if (s[i] != c[i]) ans++;
}
cout << ans << endl;
}
return 0;
}
B. Blank Space
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;
const LL MAXN = 1e18;
const LL N = 1e6, M = 4002;
const LL mod = 1e9 + 7;
LL a[N];
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
LL T = 1;
cin>>T;
while (T--)
{
LL n;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
LL flag = 0;
LL maxn = 0;
for (int i = 1; i <= n; i++)
{
if (a[i] == 1) flag = 0;
else flag++;
maxn = max(maxn, flag);
}
cout << maxn << endl;
}
return 0;
}
C. Mr. Perfectly Fine
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;
const LL MAXN = 1e18;
const LL N = 1e6, M = 4002;
const LL mod = 1e9 + 7;
LL a[N];
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
LL T = 1;
cin>>T;
while (T--)
{
LL n;
cin >> n;
LL minn = MAXN;
LL ly = MAXN, yl = MAXN;
for (int i = 1; i <= n; i++)
{
LL x, y;
cin >> x >> y;
if (y == 11) minn = min(minn, x);
else if (y == 01) ly = min(ly, x);
else if (y == 10) yl = min(yl, x);
}
minn = min(minn, ly + yl);
if (minn >= MAXN / 2) minn = -1;
cout << minn << endl;
}
return 0;
}
D. Gold Rush
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;
const LL MAXN = 1e18;
const LL N = 1e6, M = 4002;
const LL mod = 1e9 + 7;
LL a[N];
bool check(LL n, LL m)
{
queue<LL> q;
if (n / 3 == m || n / 3 * 2 == m) return true;
if(n/3>=m) q.push(n / 3);
if(n/3*2>=m) q.push(n / 3 * 2);
while (q.size())
{
auto t = q.front();
q.pop();
if (t % 3 == 0)
{
if (t / 3 == m || t / 3 * 2 == m) return true;
if (t / 3 >= m) q.push(t / 3);
if (t / 3 * 2 >= m) q.push(t / 3 * 2);
}
}
return false;
}
int main()
{
//cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
LL T = 1;
cin>>T;
while (T--)
{
LL n, m;
cin >> n >> m;
if (n == m) cout << "YES" << endl;
else if (n < m) cout << "NO" << endl;
else if (n % 3 != 0) cout << "NO" << endl;
else {
if (check(n, m) == true) cout << "YES" << endl;
else cout << "NO" << endl;
}
}
return 0;
}
E. The Lakes
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;
const LL MAXN = 1e18;
const LL N = 1e6, M = 4002;
const LL mod = 1e9 + 7;
LL a[M][M];
bool st[M][M];
LL n, m;
LL dx[] = { -1,0,0,1 }, dy[] = { 0,1,-1,0 };
LL sum = 0, maxn = 0;
void dfs(int x, int y)
{
st[x][y] = true;
sum += a[x][y];
for (int i = 0; i < 4; i++)
{
LL xx = dx[i] + x, yy = dy[i] + y;
if (xx >= 1 && xx <= n && yy >= 1 && yy <= m && st[xx][yy] == false && a[xx][yy] != 0)
{
dfs(xx, yy);
}
}
}
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
LL T = 1;
cin>>T;
while (T--)
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
cin >> a[i][j];
st[i][j] = false;
}
}
sum = 0;
maxn = 0;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
if (st[i][j] == false&&a[i][j]!=0)
{
sum = 0;
dfs(i, j);
maxn = max(maxn, sum);
}
}
}
cout << maxn << endl;
}
return 0;
}
F. Forever Winter
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;
const LL MAXN = 1e18;
const LL N = 1e6, M = 4002;
const LL mod = 1e9 + 7;
LL n, m;
LL a[N], b[N];
LL d[N], deep[N];
LL maxn = 0;
vector<LL> g[N];
void init()
{
maxn = 0;
memset(deep, 0, sizeof deep);
memset(d, 0, sizeof d);
for (int i = 0; i <= 1000; i++)
{
g[i].clear();
}
}
void dfs(LL idx, LL depth,LL father)
{
maxn = max(maxn, depth);
LL sum = g[idx].size();
deep[depth]=max(deep[depth],sum);
for (int i = 0; i < g[idx].size(); i++)
{
if (g[idx][i] == father) continue;
dfs(g[idx][i], depth + 1, idx);
}
}
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
LL T = 1;
cin>>T;
while (T--)
{
cin >> n >> m;
init();
for (int i = 1; i <= m; i++)
{
cin >> a[i] >> b[i];
g[a[i]].push_back(b[i]);
d[a[i]]++;
g[b[i]].push_back(a[i]);
d[b[i]]++;
}
LL beg = 0;
for (int i = 1; i <= m; i++)
{
if (d[a[i]] == 1)
{
beg = a[i];
break;
}
else if(d[b[i]]==1)
{
beg = b[i];
break;
}
}
dfs(beg, 1,-1);
cout << deep[maxn / 2 + 1] << " " << deep[maxn - 1]-1 << endl;
}
return 0;
}