第十四届蓝桥杯三月真题刷题训练——第 5 天（3.8）

Cauchy 2023-03-08 12:23:36
``````#include <iostream>
using namespace std;
int main()
{
int n = 2019;
int res = 0;
auto ok = [](int x) { while (x) { if (x % 10 == 2 || x % 10 == 4) return false; x /= 10; } return true; };
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
int k = n - i - j;
if (k >= j + 1 && ok(i) && ok(j) && ok(k)) {
res++;
}
}
}
cout << res;
return 0;
}``````
``````#include <iostream>
using namespace std;
int main()
{
for (int i = 1950; i <= 2010; i++) {
for (int j = 1; j <= 12; j++) {
for (int k = 1; k <= 31; k++) {
int x = (i * 100 + j) * 100 + k;
if (x % 2012 == 0 && x % 3 == 0 && x % 12 == 0 && j == 6) {
cout << x << endl;
return 0;
}
}
}
}
return 0;
}``````
``````#include <iostream>
using namespace std;
int main()
{
int n; cin >> n;
int x = 0, y = 0;
int a[n]; for (auto &c: a) {cin >> c; if(c >= 85) x++; else if(c >= 60) y++; }
y += x;
printf("%.0lf%%\n%.0lf%%\n", 1.0 * y / n * 100, 1.0 * x / n * 100);
return 0;
}``````
``````#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int n; cin >> n;
int a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i];

int prime[n + 1]; memset(prime, 0x3f, sizeof prime);
auto init = [&](){
for (int i = 2; i <= n; i++)
for (int j = 1; j <= n / i; j++)
prime[i * j] = min(prime[i * j], i);

};
init();
// for (int i = 1; i <= n; i++) cout << prime[i] << ' '; cout << endl;

int f[n + 1]; memset(f, -0x3f, sizeof f);
f[1] = a[1];
for (int i = 1; i <= n; i++) {
int j = prime[n - i];
if (j == 0x3f3f3f3f) j = 1;
for (int k = i + 1; k <= n && k <= i + j; k++) {
f[k] = max(f[k], f[i] + a[k]);
}
}
// for (int i = 1; i <= n; i++) cout << f[i] << ' '; cout << endl;
cout << f[n] << endl;
return 0;
}``````
``````#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int n; cin >> n;
int a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i];
int f[n + 1]; memset(f, -0x3f, sizeof f);
f[1] = a[1];
for (int i = 1; i <= n; i++) {
int x = n - i;
int j;
for (j = 2; j <= x; j++) if (x % j == 0) break;
if (x % j != 0) j = 1;
for (int k = i + 1; k <= n && k <= i + j; k++) {
f[k] = max(f[k], f[i] + a[k]);
}
}
cout << f[n] << endl;
return 0;
}``````

...全文
7 回复 打赏 收藏 举报

4.1w+

2023-03-08 12:28

2023-03-08 12:23

刷题！