- 算法 AC 编程挑战赛
【题解】算法 AC 编程挑战赛
- @ 2025-12-4 15:16:20
T1
#include <bits/stdc++.h>
using namespace std;
int main()
{
char t;
int x;
cin >> t >> x;
if (x <= 3)
{
cout << "0";
}
else
{
if (t == 'N')
{
if (x == 4)
cout << 2 + 1;
if (x == 5)
cout << 3 + 2;
if (x == 6)
cout << 6 + 3;
}
else
{
if (x == 4)
cout << 0 + 0;
if (x == 5)
cout << 1 + 0;
if (x == 6)
cout << 4 + 1;
}
}
return 0;
}
T2
#include <bits/stdc++.h>
using namespace std;
int a, b, n, m, h;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> a >> b >> n >> m;
int now = 0;
for (int i = 1; i <= m; i++)
{
cin >> h;
now += h;
}
int nn = n + now;
if (n < 0 && nn >= 0)
nn++;
else if (n > 0 && nn <= 0)
nn--;
cout << nn;
return 0;
}
T3
#include <bits/stdc++.h>
using namespace std;
long long x, y, ans;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> x >> y;
ans = x;
while (x)
{
ans += x / y * 2;
x /= y;
}
cout << ans;
return 0;
}
T4
#include <bits/stdc++.h>
using namespace std;
int l, r, ans;
bool leap(int y)
{
if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0)
return true;
return false;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> l >> r;
ans = 0;
for (int i = l; i <= r; i++)
if (leap(i))
ans += 366;
cout << ans;
return 0;
}
T5
#include <bits/stdc++.h>
using namespace std;
int n, m;
string s[15];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> s[i];
int l = 0;
for (int i = 1; i <= m; i++)
{
bool flag = true;
for (int j = 2; j <= n; j++)
if (s[j][i - 1] != s[1][i - 1])
{
flag = false;
break;
}
if (flag)
l++;
else
break;
}
int r = 0;
for (int i = m; i >= 1; i--)
{
bool flag = true;
for (int j = 2; j <= n; j++)
if (s[j][i - 1] != s[1][i - 1])
{
flag = false;
break;
}
if (flag)
r++;
else
break;
}
cout << min(l + r, m);
return 0;
}
T6
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
long long ans = 1LL * n * n;
// 第一行的位置
for (int pos = 1; pos <= 5; pos++)
{
int now = pos;
long long sum = 0;
for (int i = 1; i <= n; i++)
{
sum += (n - now) / 5 + 1;
now -= 2;
if (now < 1)
now += 5;
}
ans = min(ans, sum);
}
cout << ans;
return 0;
}
1 comments
-
PomeloGPT LV 7 @ 2025-12-20 9:04:06算法 WA 编程挑战赛
- 1