2031
#include <iostream>
using namespace std;
int main()
{
cout << 2 * 1 + 2 * 9 + 0 * 9 * 9 + 2 * 9 * 9 * 9;
return 0;
}
2032
#include <iostream>
using namespace std;
int main()
{
cout << 14;
return 0;
}
2033
#include <iostream>
#define int long long int
using namespace std;
signed main()
{
int a, b, n;
cin >> a >> b >> n;
int num = a * 5 + b * 2;
int ans = n / num * 7;
n = n % num;
for (int i = 0; i < 5 && n > 0; i++)
{
ans++;
n -= a;
}
for (int i = 0; i < 2 && n > 0; i++)
{
ans++;
n -= b;
}
cout << ans;
return 0;
}
2034
#include <iostream>
#define int long long int
using namespace std;
signed main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
cout << 2 * max(i - 1, n - i) << endl;
}
return 0;
}
2035
#include <iostream>
#define int long long int
using namespace std;
int a[100010], b[100010];
signed main()
{
int n;
cin >> n;
int ma, mb;
cin >> ma;
for (int i = ma; i > 0; i--)
{
cin >> a[i];
}
cin >> mb;
for (int i = mb; i > 0; i--)
{
cin >> b[i];
}
int ans = 0, num = 1;
for (int i = 2; i <= ma; i++)
{
num *= max((int)2, max(a[i - 1], b[i - 1]) + 1);
num %= 1000000007;
//cout << num << endl;
ans += num * (a[i] - b[i]);
ans %= 1000000007;
//cout << ans << endl;
}
cout << ans + (a[1] - b[1]);
return 0;
}
2036
方法是前缀和加双指针,遍历i-j,内层遍历1-m,但是我们使用双指针遍历,用前缀和计算,加入到我们的最大和sum中,当sum大于k时,我们就把l右移,直到sum小于k,每一次就都可以记录答案,答案数量为r-l+1。
#include<iostream>
#define int long long int
using namespace std;
int arr[510][510];
int main()
{
int n, m, k;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
{
cin >> arr[i][j];
arr[i][j] += arr[i - 1][j];
}
int ans = 0;
for (int i = 1; i <= n; i++)
for (int j = i; j <= n; j++)
for (int l = 1, r = 1, p = 0; r <= m; r++)
{
p += arr[j][r] - arr[i - 1][r];
while (p > k)
{
p -= arr[j][l] - arr[i - 1][l];
l++;
}
ans += r - l + 1;
}
cout << ans << endl;
}
2037
#include <iostream>
//#define int long long int
using namespace std;
int dp[10000010][4];
int main()
{
int n;
cin >> n;
dp[1][0] = 1, dp[1][1] = 1, dp[1][2] = 1, dp[1][3] = 1;
for (int i = 2; i <= n; i++)
{
dp[i][0] = (dp[i - 1][0] + dp[i - 1][3]) % 1000000007;
dp[i][1] = (dp[i - 1][0] + dp[i - 1][2]) % 1000000007;
dp[i][2] = (dp[i - 1][1] + dp[i - 1][0]) % 1000000007;
dp[i][3] = ((dp[i - 1][0] + dp[i - 1][1]) % 1000000007 + dp[i - 1][2]) % 1000000007;
}
cout << dp[n][0];
return 0;
}
2038
#include <iostream>
#include <algorithm>
#define int long long int
using namespace std;
typedef struct
{
int x, y, r;
int status;
int count;
} object;
int n, m;
object boomer[100010], rocket[100010];
bool cmp(object &a, object &b)
{
if (a.x == b.x)
return a.y < b.y;
return a.x < b.x;
}
bool cmp_const(const object &a, const object &b)
{
return a.x < b.x;
}
bool cmp_const_equal(const object &a, const object &b)
{
return a.x <= b.x;
}
void insert(object *a, object obj, int &len)
{
a[len + 1] = obj;
len++;
}
bool check(object &a, object &b)
{
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) <= a.r * a.r;
}
int get_key(int x, int y)
{
return (x * (int)(1e+9 + 1)) + y;
}
signed main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> boomer[i].x >> boomer[i].y >> boomer[i].r;
boomer[i].count = 1;
}
for (int i = 1; i <= m; i++)
cin >> rocket[i].x >> rocket[i].y >> rocket[i].r;
sort(boomer + 1, boomer + n + 1, cmp);
int cnt = 1;
for (int i = 2; i <= n; i++)
{
if (get_key(boomer[cnt].x, boomer[cnt].y) == get_key(boomer[i].x, boomer[i].y))
{
if (boomer[cnt].r < boomer[i].r)
{
boomer[cnt].r = boomer[i].r;
}
boomer[cnt].count += boomer[i].count;
}
else if (get_key(boomer[cnt].x, boomer[cnt].y) != get_key(boomer[i].x, boomer[i].y)) // 坐标不相等
{
cnt++;
boomer[cnt] = boomer[i];
}
}
n = cnt;
int ans = 0;
for (int i = 1; i <= m; i++)
{
if (rocket[i].status == 1)
continue;
rocket[i].status = 1;
int x_h = rocket[i].x + rocket[i].r, x_l = rocket[i].x - rocket[i].r; // x_h: x_high,x_l:x_low
int y_h = rocket[i].y + rocket[i].r, y_l = rocket[i].y - rocket[i].r; // y_h: y_high,y_l:y_low
object obj_l = {x_l, 0, 0, 0};
object obj_r = {x_h, 0, 0, 0};
int l = lower_bound(boomer + 1, boomer + n + 1, obj_l, cmp_const) - boomer;
int r = lower_bound(boomer + 1, boomer + n + 1, obj_r, cmp_const_equal) - boomer;
r = min(n, r);
for (int j = l; j <= r; j++)
{
if (boomer[j].status == 0 &&
boomer[j].x >= x_l && boomer[j].x <= x_h &&
boomer[j].y >= y_l && boomer[j].y <= y_h &&
check(rocket[i], boomer[j]) )
{
insert(rocket, boomer[j], m);
boomer[j].status = 1;
ans += boomer[j].count;
}
}
}
cout << ans;
return 0;
}
2039
#include <iostream>
#define int long long int
using namespace std;
int arr[110][110][110];
signed main()
{
int t;
cin >> t;
for (int j = 0; j < t; j++)
{
int n, m;
cin >> n >> m;
arr[0][0][2] = 1;
for (int i = 0; i <= n; i++)
{
for (int j = 0; j <= m; j++)
{
for (int k = 0; k <= m; k++)
{
if (i && k % 2 == 0) arr[i][j][k] = (arr[i][j][k] + arr[i - 1][j][k / 2]) % 1000000007;
if (j) arr[i][j][k] = (arr[i][j][k] + arr[i][j - 1][k + 1]) % 1000000007;
}
}
}
cout << arr[n][m - 1][1] << endl;
}
}
2040
如果它们处于同一高度就可以一起修剪,但是虽然最大到1e18,不超6次就变成1了,这个次数很少,因为n/2+1开根号能保证n与结果相差特别大,同时也最多也只会分解6个数,这时候我们就可以进行判断,如果这个数分解的某一步和前面的高度相同,那么这俩就可以在这个高度被剪掉,就算他们此时不在这个高度也没关系,也可以通过几次其他修剪到达这个高度,我们只需要判断这一步即可。
#include <iostream>
#include <cmath>
#define int long long int
using namespace std;
int arr[200010][10];
signed main()
{
int n;
cin >> n;
int s[10], t = 0, mx = 0, cnt = 0;
for (int i = 0; i < n; i++)
{
t = 0;
int p;
cin >> p;
while (p > 1)
{
s[t++] = p;
p = sqrt(p / 2 + 1);
}
mx = max(mx, t);
cnt += t;
for (int j = 0, k = t - 1; k >= 0; j++, k--)
{
arr[i][j] = s[k];
}
}
for (int i = 0; i < mx; i++)
{
for (int j = 1; j < n; j++)
{
if (arr[j][i] == arr[j - 1][i] && arr[j - 1][i])
cnt--;
}
}
cout << cnt << endl;
}