- 东明张展奕's blog
abc365整理
- 2024-8-4 15:14:56 @
A-AC
判断闰年,闰年输出:
否则输出:
code:
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define TRACE 1
#define tcout TRACE && cout
#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
const int P = 998244353;
const int Base = 3221225477;
const int INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10, M = 2e6 + 10;
signed main()
{
int n;
cin >> n;
if(n % 4 == 0 && n % 100 != 0 || n % 400 == 0 && n % 3200!= 0)
{
cout <<"366";
}
else
{
cout <<"365";
}
return 0;
}
B-AC
求次大值在数组的第几位
操,屌丝翻译让我错了 次
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define TRACE 1
#define tcout TRACE && cout
#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
const int P = 998244353;
const int INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10, M = 2e6 + 10;
int a[N], b[N];
signed main()
{
int n;
cin >> n;
for(int i = 1; i <= n;i ++)
{
cin >> a[i];
b[i] = a[i];
}
sort(a + 1, a+n+1);
int maxx = a[n-1];
for(int i = 1; i <= n; i++)
{
if(maxx == b[i])
{
cout << i;
return 0;
}
}
return 0;
}
C
二分查找做🤣🤣🤣
如果一个地方合法,那他以下的都合法,上面的不合法
找到合法和不合法的分界点,找到那个范围()
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define TRACE 1
#define tcout TRACE && cout
#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
const int P = 998244353;
const int Base = 2281701377;
const int INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10, M = 2e6 + 10;
int n, m;
int a[N];
int sum;
int ans;
int l, r;
bool check(int mid)
{
int res = 0;
for(int i=1; i<=n; i++)
{
res += min(a[i], mid);
}
return res <= m;
}
signed main()
{
cin >> n >> m;
for(int i=1; i<=n; i++)
{
cin >> a[i];
sum += a[i];
r = max(r, a[i]);
}
if(sum <= m)
{
cout << "infinite";
return 0;
}
while(l <= r)
{
int mid = (l + r) / 2;
if(check(mid))
{
ans = mid;
l = mid + 1;
}
else
{
r = mid - 1;
}
}
cout << ans;
return 0;
}
D
动态规划()做👈
题意:
你知道对方的出拳规律 ,我们可以赢几局
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define TRACE 1
#define tcout TRACE && cout
#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
const int P = 998244353;
const int Base = 2281701377;
const int INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10, M = 2e6 + 10;
int n;
char a[N];
int f[N][3];
signed main()
{
cin >> n;
cin >> a + 1;
for(int i = 1; i <= n; i++)
{
if(a[i] == 'R')
{
f[i][0] = max(f[i-1][1], f[i-1][2]);
f[i][1] = max(f[i-1][0], f[i-1][2]) + 1;
}
if(a[i] == 'P')
{
f[i][1] = max(f[i-1][0], f[i-1][2]);
f[i][2] = max(f[i-1][0], f[i-1][1]) + 1;
}
if(a[i] == 'S')
{
f[i][2] = max(f[i-1][1], f[i-1][0]);
f[i][0] = max(f[i-1][1], f[i-1][2]) + 1;
}
}
cout << max(max(f[n][0],f[n][1]), f[n][2]);
return 0;
}