高中组冲刺
Done
IOI
Start at: 2025-5-23 13:30
24
hour(s)
Host:
14
#include <bits/stdc++.h>
using namespace std;
int n, a[55];
int f[55];//f[i]拿第i个苹果的最大值
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int res = 0;
for (int i = 1; i <= n; i++) {
f[i] = a[i];
for (int j = 1; j < i - 1; j++) {
f[i] = max(f[i], f[j] + a[i]);
}
res = max(res, f[i]);
}
cout << res << endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
int n, a[N];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int res = 2, diff = a[2] - a[1], ans = 2;
for (int i = 3; i <= n; i++) {
if (a[i] - a[i - 1] == diff) {
res++;
ans = max(ans, res);
} else {
diff = a[i] - a[i - 1];
res = 2;
}
}
cout << ans << endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
cout<<"#";
}
cout<<endl;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int n, a[1000005], res = 0, m;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
int now = a[1];
for (int i = 2; i < n; i++) {
if (a[i] - now < m)
res++;
else{
now = a[i];
}
}
cout << res << endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, res = 0;
cin >> n;
for (int a = 0; a * 2 <= n; a++) {
for (int b = 0; b * 4 <= n; b++) {
if (a * 2 + b * 4 > n)
break;
for (int c = 0; c * 8 <= n; c++) {
if (a * 2 + b * 4 + c * 8 > n)
break;
for (int d = 0; d * 16 <= n; d++) {
if (a * 2 + b * 4 + c * 8 + d * 16 > n)
break;
for (int e = 0; e * 32 <= n; e++) {
if (a * 2 + b * 4 + c * 8 + d * 16 + e * 32 == n) {
res++;
}
}
}
}
}
}
cout << res << endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int n, a[105];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int res = 0;
for (int i = 1; i < n; i++) {
for (int j = 1; j < n; j++) {
if (a[j] > a[j + 1]) {
res++;
swap(a[j], a[j + 1]);
}
}
}
for (int i = 1; i <= n; i++) {
cout << a[i] << " ";
}
cout<<"\n";
cout << res << endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
char mat[45][45];
int n, m, nxt[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};
int book[45][45];
struct node {
int x, y, cost;
};
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> mat[i][j];
}
}
queue<node>q;
q.push({1, 1, 1});
book[1][1] = 1;
while (!q.empty()) {
node tmp = q.front();
q.pop();
if (tmp.x == n && tmp.y == m) {
cout << "YES" << endl;
//cout<<tmp.cost<<endl;
return 0;
}
for (int i = 0; i < 4; i++) {
int nx = tmp.x + nxt[i][0];
int ny = tmp.y + nxt[i][1];
if (nx >= 1 && nx <= n && ny >= 1 && ny <= m) {
if (book[nx][ny] == 0 && mat[nx][ny] != '#') {
book[nx][ny] = 1;
q.push({nx, ny, tmp.cost + 1});
}
}
}
}
cout<<"NO"<<endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
int n, a[N], f[N][N]; //f[i][j]选的第i个结尾,第j个数倒数第二个
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
f[2][1] = 2;
for (int i = 3; i <= n; i++) {
for (int j = 1; j < i; j++) {
int diff = a[i] - a[j];
for (int k = 1; k < j; k++) {
int df = a[j] - a[k];
if (diff != df)
continue;
f[i][j] = max(f[i][j], f[j][k] + 1);
}
//f[i][j] = f[j][k]+1
}
}
int res = 0 ;
for (int i = n; i >= 1; i--) {
for (int j = 1; j < i; j++) {
res = max(res, f[i][j]);
}
}
cout << res << endl;
return 0;
}
- Status
- Done
- Rule
- IOI
- Problem
- 8
- Start at
- 2025-5-23 13:30
- End at
- 2025-5-24 13:30
- Duration
- 24 hour(s)
- Host
- Partic.
- 14