A
这个题目只需要输出2024 - 2007。
B
想要必胜,那就需要赢得 场比赛。
C
就按照题目说的去模拟一下就好了,需要先判断这个数是不是已经是 了。这里多提一下,符合题目条件的 一定是 的次方数,我们可以使用位运算快速判断这个数是否符合条件。
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve()
{
int n;
cin >> n;
if((n & (n - 1)) != 0)
{
cout << -1 << "\n";
return;
}
int ans = 0;
while(n != 1)
{
n /= 2;
ans++;
}
cout << ans << "\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
//cin >> t;
while(t--)solve();
return 0;
}D
丢失石头的地方就是第一次捡到的石头跟总和对不上的地方,我们只需要记录一次,最后再输出就好了。
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve()
{
int n;
cin >> n;
int sum = 0, record = -1;
for(int i = 1; i <= n; i++)
{
int u, v;
cin >> u >> v;
if(u + sum != v)
{
if(record == -1)
record = i;
}
sum += u;
}
cout << record << "\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
//cin >> t;
while(t--)solve();
return 0;
}E
不难发现这个题目就是 ,只不过正数位置是一开始跳的地方所以需要减一次。特殊判断一下 这个位置就好了。
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve()
{
int n;
cin >> n;
if(n > 0)
{
cout << 2 * n - 1 << "\n";
}
else
{
cout << -2 * n << "\n";
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
//cin >> t;
while(t--)solve();
return 0;
}F
只有一个画布的情况下,就要考虑什么时候可以把整块画布占满,这样一定是最优的。不难发现使用四个画布拼在一起可以画十五个圆,刚好占满所有的格子。这样,我们就只用讨论小于十五的情况了。那么一到十四我们就自己画一下就好了。
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve()
{
int n;
cin >> n;
for(int i = 1; i <= n; i++)
{
int x;
cin >> x;
int ans = (x / 15) * 4;
x = x % 15;
if(x == 0)
{
cout << ans << " ";
continue;
}
if(x <= 2) ans += 1;
else if(x <= 6)ans += 2;
else if(x <= 10)ans += 3;
else ans += 4;
cout << ans << " ";
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
//cin >> t;
while(t--)solve();
return 0;
}G
我们可以写一个像排队一样的东西来轻松解决这个问题,在每次报号的时候,报到的人就离开队伍,没报到的就走到队伍后边。
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
int q[100005];
void solve()
{
int n, k;
cin >> n >> k;
int head = 1, tail = 1;
for(int i = 1; i <= n; i++)
{
q[tail] = i;
tail++;
}
int now = 1, m = 1;
while(head != tail)
{
int v = q[head];
head++;
if(now != m)
{
now++;
q[tail] = v;
tail++;
}
else
{
if(m == k)
{
cout << v << "\n";
break;
}
m++;
now = 1;
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
//cin >> t;
while(t--)solve();
return 0;
}H
不难发现两种操作对答案的贡献都是 ,所以只需要看在哪场比赛进行操作对答案的影响更大,显然是得分相差的越大的比赛进行操作对答案影响更大,所以我们对得分的差值进行排序,优先操作差值大的比赛。
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
struct node
{
int a, b;
}a[100005];
void solve()
{
int n, h, k;
cin >> n >> h >> k;
i64 suma = 0, sumb = 0;
for(int i = 1; i <= n; i++)
{
cin >> a[i].a;
suma += a[i].a;
}
for(int i = 1; i <= n; i++)
{
cin >> a[i].b;
sumb += a[i].b;
}
if(suma > sumb)
{
cout << 0 << "\n";
return;
}
sort(a + 1, a + n + 1, [&](auto a, auto b){return a.b - a.a > b.b - b.a;});
int ans = 0;
for(int i = 1; i <= n; i++)
{
ans++;
if(a[i].b >= k)
{
sumb -= k;
}
else if(a[i].a + k <= h)
{
suma += k;
}
else
{
if(h - a[i].a > a[i].b)
{
suma += h - a[i].a;
}
else
{
sumb -= a[i].b;
}
}
if(suma > sumb)
{
cout << ans << "\n";
return;
}
}
cout << -1 << "\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
//cin >> t;
while(t--)solve();
return 0;
}I
这个题就是纯模拟题了。首先将十个数字先预处理出来,得到结果再输出就好了。
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
char number[100][100]=
{
{"##### ....# ##### ##### #...# ##### ##### ##### ##### #####"},
{"#...# ....# ....# ....# #...# #.... #.... ....# #...# #...#"},
{"#...# ....# ....# ....# #...# #.... #.... ....# #...# #...#"},
{"#...# ....# ##### ##### ##### ##### ##### ....# ##### #####"},
{"#...# ....# #.... ....# ....# ....# #...# ....# #...# ....#"},
{"#...# ....# #.... ....# ....# ....# #...# ....# #...# ....#"},
{"##### ....# ##### ##### ....# ##### ##### ....# ##### #####"}
};
int ans[110];
void solve()
{
int a, b;
cin >> a >> b;
int sum = a + b;
if(sum == 0)
{
for(int i = 0; i < 7; i++)
{
for(int j = 0; j < 5; j++)
{
cout << number[i][j];
}
cout << "\n";
}
}
else
{
int len = 0;
while(sum)
{
ans[len] = sum % 10;
len++;
sum = sum / 10;
}
for(int j = 0; j < 7; j++)
{
for(int i = len - 1; i >= 0; i--)
{
for(int k = ans[i] * 6; k < ans[i] * 6 + 5; k++)
{
cout << number[j][k];
}
cout << " ";
}
cout << "\n";
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
//cin >> t;
while(t--)solve();
return 0;
}J
仔细观察可以发现,每一层增加的步数是 也就是从 到 增加了 步,那么我们就可以预先处理出每一层一共有多少步,然后用二分查找快速找到离当前步数最近的那一层,就可以得到在新层走了多少步,再讨论这时是往哪个方向走的,就可以得到当前走到的位置了。
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
const int N = 1e6 + 7;
i64 f[N];
int len = 2;
void init()
{
f[1] = 1;
i64 now = 1;
while(now < 1e12)
{
f[len] = f[len - 1] + 4 * len - 3;
now = f[len];
len++;
}
}
void solve()
{
i64 n;
cin >> n;
int l = 0, r = len;
int ans = -1;
while(l <= r)
{
int mid = (l + r) / 2;
if(f[mid] < n)
{
ans = mid;
l = mid + 1;
}
else
{
r = mid - 1;
}
}
i64 last = n - f[ans];
int x, y;
if(ans % 2 == 1)
{
if(last <= ans + 1)
{
x = -ans;
y = last - 1;
}
else if(last <= (ans + 1) * 4 - 3 - ans)
{
x = -ans + (last - ans - 1);
y = ans;
}
else
{
x = ans;
y = ans - (last - ((ans + 1) * 4 - 3 - ans));
}
}
else
{
if(last <= ans + 1)
{
x = ans;
y = last - 1;
}
else if(last <= (ans + 1) * 4 - 3 - ans)
{
x = ans - (last - ans - 1);
y = ans;
}
else
{
x = -ans;
y = ans - (last - ((ans + 1) * 4 - 3 - ans));
}
}
cout << x << " " << y << "\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
init();
int t = 1;
cin >> t;
while(t--)solve();
return 0;
}