A.退休
代码
void solve()
{
int a, b;
cin >> a >> b;
int num = a + b;
int res = (1000000 + num - 1) / num;
cout << res / 12 << ' ' << res % 12;
}
B.四季
代码
void solve()
{
int a, b;
scanf("%d-%d", &a, &b);
if (b >= 3 && b <= 5) cout << "spring";
else if (b >= 6 && b <= 8) cout << "summer";
else if (b >= 9 && b <= 11) cout << "autumn";
else cout << "winter";
}
C.乘法运算
代码
void solve()
{
long long a, b, c;
cin >> a >> c;
b = c - a;
cout << b << '\n' << a * b;
}
D.三数最大
代码
char a, b, c;
void solve()
{
cin >> a >> b >> c;
char res = 'A';
if (a == '>') {
if (b == '<') res = 'C';
if (c == '>') return void(cout << "-1");
}
else {
res = 'B';
if (c == '<') res = 'C';
if (b == '>') return void(cout << "-1");
}
cout << res;
}
E.小T的误判
代码
string s;
void solve()
{
cin >> s;
int res = 0;
for (int i = 0; i < si(s); i += 2)
{
if (s[i] == 'T') i ++;
if (s[i] == 'W' && i + 2 < si(s) && s[i + 2] == 'C') res ++;
}
cout << res;
}
F.村庄的友谊
代码
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
#define ll long long
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define all(a) a.begin(), a.end()
#define lowbit(x) x & -x
#define ent cout << '\n'
#define out(x) cout << x << ' '
#define out2(x, y) cout << x << " ~ " << y << ' '
#define me(a, b) memset(a, b, sizeof a)
#define mc(a, b) memcpy(a, b, sizeof a)
#define pk push_back
#define ur(x) sort(all(x)), x.erase(unique(all(x)), x.end())
#define fi first
#define se second
#define si(x) int(x.size())
#define chi(x) (x - '0')
#define ull unsigned long long
#define Mp make_pair
using namespace std;
const ll inf = 1e18;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const int mod = 998244353;
const int P = 1e9 + 7;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {-1, 1, 0, 0};
const int N = 1e6 + 10;
const int M = 1000 + 10;
ll n;
int a[N];
bool is_prime(int x)
{
if (x < 2) return false;
for (int i = 2; i <= x / i; i ++)
if (x % i == 0) return false;
return true;
}
void solve()
{
cin >> n;
ll cnt = 0, sum = 0;
for (int i = 1; i <= n; i ++)
{
int x;
cin >> x;
if (x == 1) cnt ++;
else if (is_prime(x)) sum ++;
}
sum *= cnt;
ll res = n * (n - 1) / 2;
cout << res - sum;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while (t --) solve();
return 0;
}
G.再多一些0
代码
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
#define ll long long
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define all(a) a.begin(), a.end()
#define lowbit(x) x & -x
#define ent cout << '\n'
#define out(x) cout << x << ' '
#define out2(x, y) cout << x << " ~ " << y << ' '
#define me(a, b) memset(a, b, sizeof a)
#define mc(a, b) memcpy(a, b, sizeof a)
#define pk push_back
#define ur(x) sort(all(x)), x.erase(unique(all(x)), x.end())
#define fi first
#define se second
#define si(x) int(x.size())
#define chi(x) (x - '0')
#define ull unsigned long long
#define Mp make_pair
using namespace std;
const ll inf = 1e18;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const int mod = 998244353;
const int P = 1e9 + 7;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {-1, 1, 0, 0};
const int N = 1e6 + 10;
const int M = 1000 + 10;
int n, m, res;
string s;
string sal;
int count_2(int x)
{
int res = 0;
while (x % 2 == 0) res ++, x /= 2;
return res;
}
int count_5(int x)
{
int res = 0;
while (x % 5 == 0) res ++, x /= 5;
return res;
}
void solve()
{
cin >> n >> m;
int cnt2 = count_2(n);
int cnt5 = count_5(n);
ll num = 1;
for (int i = 0; i < cnt5; i ++)
{
if (num * 2 > m) break;
num *= 2;
}
for (int i = 0; i < cnt2; i ++)
{
if (num * 5 > m) break;
num *= 5;
}
// out(num); ent;
while (num * 10 <= m) num *= 10;
cout << m / num * num;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while (t --) solve();
return 0;
}
H.图样图森破
代码
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
#define ll long long
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define all(a) a.begin(), a.end()
#define lowbit(x) x & -x
#define ent cout << '\n'
#define out(x) cout << x << ' '
#define out2(x, y) cout << x << " ~ " << y << ' '
#define me(a, b) memset(a, b, sizeof a)
#define mc(a, b) memcpy(a, b, sizeof a)
#define pk push_back
#define ur(x) sort(all(x)), x.erase(unique(all(x)), x.end())
#define fi first
#define se second
#define si(x) int(x.size())
#define chi(x) (x - '0')
#define ull unsigned long long
#define Mp make_pair
using namespace std;
const ll inf = 1e18;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const int mod = 998244353;
const int P = 1e9 + 7;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {-1, 1, 0, 0};
const int N = 1e6 + 10;
const int M = 1000 + 10;
int n, L;
int x;
bool check(int mid)
{
ll res = L;
ll cnt = 1LL << mid;
ll sum = (cnt - 1) * 150;
return res * cnt - sum >= x;
}
void solve()
{
cin >> L >> n;
while (n --)
{
cin >> x;
if (x == L) {
cout << 0;
ent;
continue;
}
int l = 1, r = 63;
while (l < r)
{
int mid = (l + r) >> 1;
if (check(mid)) r = mid;
else l = mid + 1;
}
if (check(l)) {
ll cnt = 1LL << l;
ll sum = L * cnt - 150 * (cnt - 1);
if (sum == x) cout << l << '\n';
else cout << -1 << '\n';
}
else cout << -1 << '\n';
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while (t --) solve();
return 0;
}
I.开光灯
代码
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
#define ll long long
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define all(a) a.begin(), a.end()
#define lowbit(x) x & -x
#define ent cout << '\n'
#define out(x) cout << x << ' '
#define out2(x, y) cout << x << " ~ " << y << ' '
#define me(a, b) memset(a, b, sizeof a)
#define mc(a, b) memcpy(a, b, sizeof a)
#define pk push_back
#define ur(x) sort(all(x)), x.erase(unique(all(x)), x.end())
#define fi first
#define se second
#define si(x) int(x.size())
#define chi(x) (x - '0')
#define ull unsigned long long
#define Mp make_pair
using namespace std;
const ll inf = 1e18;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const int mod = 998244353;
const int P = 1e9 + 7;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {-1, 1, 0, 0};
const int N = 1e6 + 10;
const int M = 1000 + 10;
int n, m;
int a[N];
PII b[N];
void solve()
{
cin >> n >> m;
for (int i = 0; i < m; i ++)
{
int l, r;
cin >> l >> r;
a[l] += 1, a[r + 1] -= 1;
b[i] = {l, r};
}
for (int i = 1; i <= n; i ++) a[i] += a[i - 1];
for (int i = 1; i <= n; i ++)
{
a[i] %= 2;
a[i] += a[i - 1];
}
for (int i = 0; i < m; i ++)
{
int l = b[i].fi, r = b[i].se;
int res = a[l - 1] + a[n] - a[r] + (r - l + 1 - a[r] + a[l - 1]);
cout << res << ' ';
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while (t --) solve();
return 0;
}
J.上班规划
代码
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
#define ll long long
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define all(a) a.begin(), a.end()
#define lowbit(x) x & -x
#define ent cout << '\n'
#define out(x) cout << x << ' '
#define out2(x, y) cout << x << " ~ " << y << ' '
#define me(a, b) memset(a, b, sizeof a)
#define mc(a, b) memcpy(a, b, sizeof a)
#define pk push_back
#define ur(x) sort(all(x)), x.erase(unique(all(x)), x.end())
#define fi first
#define se second
#define si(x) int(x.size())
#define chi(x) (x - '0')
#define ull unsigned long long
#define Mp make_pair
using namespace std;
const ll inf = 1e18;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const int mod = 998244353;
const int P = 1e9 + 7;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {-1, 1, 0, 0};
const int N = 1e6 + 10;
const int M = 1000 + 10;
ll n, m, num, wt, bt, v;
bool vis[N], st[N], stt[N];
vector<int> g[N];
int s, e;
ll d[N], dd[N], w[N], ddd[N];
void dijkstra(int u, ll c[], bool flag)
{
for (int i = 1; i <= n; i ++) c[i] = inf, st[i] = 0;
priority_queue<PLL, vector<PLL>, greater<PLL>> pq;
c[u] = 0;
pq.push({c[u], u});
while (!pq.empty())
{
auto t = pq.top();
pq.pop();
if (st[t.se]) continue;
st[t.se] = 1;
for (int i : g[t.se])
{
ll wi = wt;
if (flag && (vis[t.se] || stt[t.se])) wi = bt, stt[i] = 1;
if (c[i] >= t.fi + wi) {
if (wi == bt) {
if (w[i] > w[t.se] + v) w[i] = w[t.se] + v;
else if (!w[i] && c[i] > t.fi + wi) w[i] = w[t.se] + v;
}
c[i] = t.fi + wi;
pq.push({c[i], i});
}
}
}
}
void solve()
{
cin >> n >> m >> num >> wt >> bt >> v;
for (int i = 0; i < m; i ++)
{
int x;
cin >> x;
vis[x] = 1;
}
while (num --)
{
int a, b;
cin >> a >> b;
g[a].pk(b);
g[b].pk(a);
}
cin >> s >> e;
dijkstra(s, d, 1);
dijkstra(e, dd, 0);
ll res = dd[s], ans = 0;
for (int i = 1; i <= n; i ++)
{
if (vis[i]) {
ll sum = d[i] + dd[i];
if (sum < res) res = sum, ans = w[i];
else if (sum == res && ans > w[i]) ans = w[i];
}
}
cout << res << ' ' << ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while (t --) solve();
return 0;
}
K.数组涂染
代码
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
#define ll long long
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define all(a) a.begin(), a.end()
#define lowbit(x) x & -x
#define ent cout << '\n'
#define out(x) cout << x << ' '
#define out2(x, y) cout << x << " ~ " << y << ' '
#define me(a, b) memset(a, b, sizeof a)
#define mc(a, b) memcpy(a, b, sizeof a)
#define pk push_back
#define ur(x) sort(all(x)), x.erase(unique(all(x)), x.end())
#define fi first
#define se second
#define si(x) int(x.size())
#define chi(x) (x - '0')
#define ull unsigned long long
#define Mp make_pair
using namespace std;
const ll inf = 1e18;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const int mod = 998244353;
const int P = 1e9 + 7;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {-1, 1, 0, 0};
const int N = 1e6 + 10;
const int M = 1000 + 10;
int n;
int a[N], p[N];
struct node {
int w, u, v;
};
vector<node> g;
int lcm(int a, int b)
{
return a / __gcd(a, b) * b;
}
int find(int x)
{
if (p[x] != x) p[x] = find(p[x]);
return p[x];
}
ll kruskal()
{
for (int i = 1; i <= n; i ++) p[i] = i;
ll res = 0;
for (auto [w, u, v] : g)
{
int pu = find(u), pv = find(v);
if (pu != pv)
{
p[pu] = pv;
res += w;
}
}
return res;
}
void solve()
{
cin >> n;
ll res = 0;
for (int i = 1; i <= n; i ++) cin >> a[i], res += a[i];
for (int i = 1; i < n; i ++)
for (int j = i + 1; j <= n; j ++)
g.pk({lcm(a[i], a[j]), i, j});
sort(all(g), [&](node a, node b){
return a.w < b.w;
});
res += kruskal();
cout << res;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while (t --) solve();
return 0;
}
L.小可的red子序列
代码
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
#define ll long long
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define all(a) a.begin(), a.end()
#define lowbit(x) x & -x
#define ent cout << '\n'
#define out(x) cout << x << ' '
#define out2(x, y) cout << x << " ~ " << y << ' '
#define me(a, b) memset(a, b, sizeof a)
#define mc(a, b) memcpy(a, b, sizeof a)
#define pk push_back
#define ur(x) sort(all(x)), x.erase(unique(all(x)), x.end())
#define fi first
#define se second
#define si(x) int(x.size())
#define chi(x) (x - '0')
#define ull unsigned long long
#define Mp make_pair
using namespace std;
const ll inf = 1e18;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const int mod = 998244353;
const int P = 1e9 + 7;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {-1, 1, 0, 0};
const int N = 1e6 + 10;
const int M = 1000 + 10;
int n;
string s;
ll r[N], d[N];
void solve()
{
cin >> s;
s = ' ' + s;
for (int i = 1; i < si(s); i ++)
r[i] = (r[i - 1] + (s[i] == 'r' ? i : 0)) % P;
for (int i = si(s) - 1; i; i --)
d[i] = (d[i + 1] + (s[i] == 'd' ? si(s) - i : 0)) % P;
ll res = 0;
for(int i = 1; i < si(s); i ++)
if (s[i] == 'e') res = (res + r[i] * d[i]) % P;
cout << res;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while (t --) solve();
return 0;
}
M.寻找jyuwin
代码
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
#define ll long long
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define all(a) a.begin(), a.end()
#define lowbit(x) x & -x
#define ent cout << '\n'
#define out(x) cout << x << ' '
#define out2(x, y) cout << x << " ~ " << y << ' '
#define me(a, b) memset(a, b, sizeof a)
#define mc(a, b) memcpy(a, b, sizeof a)
#define pk push_back
#define ur(x) sort(all(x)), x.erase(unique(all(x)), x.end())
#define fi first
#define se second
#define si(x) int(x.size())
#define chi(x) (x - '0')
#define ull unsigned long long
#define Mp make_pair
using namespace std;
const ll inf = 1e18;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const int mod = 998244353;
const int P = 1e9 + 7;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {-1, 1, 0, 0};
const int N = 1e6 + 10;
const int M = 1000 + 10;
int n, m;
void solve()
{
cin >> n >> m;
vector<vector<char>> g(n + 1, vector<char>(m + 1));
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= m; j ++)
cin >> g[i][j];
vector<vector<int>> sj(n + 1, vector<int>(m + 1)), sy(n + 1, vector<int>(m + 1)), su(n + 1, vector<int>(m + 1)), sw(n + 1, vector<int>(m + 1)), sI(n + 1, vector<int>(m + 1)), sn(n + 1, vector<int>(m + 1));
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= m; j ++)
{
sj[i][j] = sj[i - 1][j] + sj[i][j - 1] - sj[i - 1][j - 1] + (g[i][j] == 'j');
sy[i][j] = sy[i - 1][j] + sy[i][j - 1] - sy[i - 1][j - 1] + (g[i][j] == 'y');
su[i][j] = su[i - 1][j] + su[i][j - 1] - su[i - 1][j - 1] + (g[i][j] == 'u');
sw[i][j] = sw[i - 1][j] + sw[i][j - 1] - sw[i - 1][j - 1] + (g[i][j] == 'w');
sI[i][j] = sI[i - 1][j] + sI[i][j - 1] - sI[i - 1][j - 1] + (g[i][j] == 'i');
sn[i][j] = sn[i - 1][j] + sn[i][j - 1] - sn[i - 1][j - 1] + (g[i][j] == 'n');
}
int res = INF;
if (!sj[n][m] || !sy[n][m] || !su[n][m] || !sw[n][m] || !sI[n][m] || !sn[n][m]) return void(cout << -1);
int minp = min(n, m), maxp = max(n, m);
for (int i = 1; i <= minp; i ++)
{
for (int ii = 1; ii <= i; ii ++)
{
for (int j = 1, jj = 1; j <= maxp; j ++)
{
while (jj <= j) {
int ix = i, iix = ii, jy = j, jjy = jj;
if (m < n) swap(ix, jy), swap(iix, jjy);
int cntj = sj[ix][jy] - sj[iix - 1][jy] - sj[ix][jjy - 1] + sj[iix - 1][jjy - 1];
int cnty = sy[ix][jy] - sy[iix - 1][jy] - sy[ix][jjy - 1] + sy[iix - 1][jjy - 1];
int cntu = su[ix][jy] - su[iix - 1][jy] - su[ix][jjy - 1] + su[iix - 1][jjy - 1];
int cntw = sw[ix][jy] - sw[iix - 1][jy] - sw[ix][jjy - 1] + sw[iix - 1][jjy - 1];
int cnti = sI[ix][jy] - sI[iix - 1][jy] - sI[ix][jjy - 1] + sI[iix - 1][jjy - 1];
int cntn = sn[ix][jy] - sn[iix - 1][jy] - sn[ix][jjy - 1] + sn[iix - 1][jjy - 1];
if (cntj && cnty && cntu && cntw && cnti && cntn) {
res = min(res, (jy - jjy + 1) * (ix - iix + 1));
jj ++;
}
else break;
}
}
}
}
cout << res;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while (t --) solve();
return 0;
}
标签:决赛,cout,int,ll,long,2024,个人赛,include,define
From: https://www.cnblogs.com/Natural-TLP/p/18550636