「解题报告」freee Programming Contest 2023(AtCoder Beginner Contest 310)
比赛地址:freee Programming Contest 2023(AtCoder Beginner Contest 310) - AtCoder
后记:原本写了比较详细的题解,但是,突发意外情况,它没了,所以这份题解略写了。归根结底还是懒
A - Order Something Else#
贪心的选价格最小的和优惠券一起使用,最后和原价比大小即可。
/*
The code was written by yifan, and yifan is neutral!!!
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T>
inline T read() {
T x = 0;
bool fg = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
fg |= (ch == '-');
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch ^ 48);
ch = getchar();
}
return fg ? ~x + 1 : x;
}
const int N = 110;
int n, q, p, mn = 1e9;
int d[N];
int main() {
n = read<int>(), p = read<int>(), q = read<int>();
for (int i = 1, x; i <= n; ++ i) {
x = read<int>();
mn = min(x, mn);
}
cout << min(p, q + mn) << '\n';
return 0;
}
B - Strictly Superior#
B - Strictly Superior (atcoder.jp)
按照题意模拟即可。
/*
The code was written by yifan, and yifan is neutral!!!
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T>
inline T read() {
T x = 0;
bool fg = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
fg |= (ch == '-');
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch ^ 48);
ch = getchar();
}
return fg ? ~x + 1 : x;
}
const int N = 110;
int n, m;
int f[N][N], p[N], c[N];
bitset<N> vis[N];
int main() {
n = read<int>(), m = read<int>();
for (int i = 1; i <= n; ++ i) {
p[i] = read<int>(), c[i] = read<int>();
for (int j = 1; j <= c[i]; ++ j) {
vis[i].set(read<int>());
}
}
for (int i = 1; i <= n; ++ i) {
for (int j = 1; j <= n; ++ j) {
if (i == j) continue ;
if (p[i] == p[j]) {
if (((vis[i] & vis[j]) == vis[i]) && (c[j] > c[i])) {
puts("Yes");
return 0;
}
}
else if (p[i] > p[j]) {
if ((vis[i] & vis[j]) == vis[i]) {
puts("Yes");
return 0;
}
}
}
}
puts("No");
return 0;
}
C - Reversible#
字符串哈希来判断,可以搭配 map
来食用。
/*
The code was written by yifan, and yifan is neutral!!!
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<typename T>
inline T read() {
T x = 0;
bool fg = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
fg |= (ch == '-');
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch ^ 48);
ch = getchar();
}
return fg ? ~x + 1 : x;
}
const int N = 2e5 + 5;
const int based = 29;
int n, len, ans;
ull Hash1[N], Hash2[N];
char s[N];
map<ull, bool> mp;
int main() {
n = read<int>();
for (int i = 1; i <= n; ++ i) {
scanf("%s", s + 1);
len = strlen(s + 1);
Hash1[0] = 0, Hash2[len + 1] = 0;
for (int j = 1; j <= len; ++ j) {
Hash1[j] = Hash1[j - 1] * based + s[j];
}
for (int j = len; j >= 1; -- j) {
Hash2[j] = Hash2[j + 1] * based + s[j];
}
if (mp.count(Hash1[len]) || mp.count(Hash2[1])) {
continue ;
}
mp[Hash1[len]] = 1;
mp[Hash2[1]] = 1;
++ ans;
}
cout << ans << '\n';
return 0;
}
D - Peaceful Teams#
D - Peaceful Teams (atcoder.jp)
由于 很小,所以可以直接搜索。
/*
The code was written by yifan, and yifan is neutral!!!
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<typename T>
inline T read() {
T x = 0;
bool fg = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
fg |= (ch == '-');
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch ^ 48);
ch = getchar();
}
return fg ? ~x + 1 : x;
}
int n, t, m, ans;
bool ok[15][15];
vector<int> Team[15];
void dfs(int u) {
if (u == n + 1) {
for (int i = 1; i <= t; ++ i) {
if (!Team[i].size()) {
return ;
}
}
++ ans;
return ;
}
for (int i = 1; i <= t; ++ i) {
int fg = 0;
for (int j : Team[i]) {
fg |= ok[u][j];
}
if (fg) {
continue ;
}
Team[i].emplace_back(u);
dfs(u + 1);
Team[i].pop_back();
if (!Team[i].size()) {
return ;
}
}
}
int main() {
n = read<int>(), t = read<int>(), m = read<int>();
for (int i = 1, x, y; i <= m; ++ i) {
x = read<int>(), y = read<int>();
ok[x][y] = ok[y][x] = 1;
}
dfs(1);
cout << ans << '\n';
return 0;
}
E - NAND repeatedly#
E - NAND repeatedly (atcoder.jp)
假设 位置是 ,则到 位置的值,为 的全变成 ,为 的全变成 ,即交换即可,当 位置是 ,那么所有情况都会变成 ,最后统计答案即可。
/*
The code was written by yifan, and yifan is neutral!!!
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T>
inline T read() {
T x = 0;
bool fg = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
fg |= (ch == '-');
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch ^ 48);
ch = getchar();
}
return fg ? ~x + 1 : x;
}
const int N = 1e6 + 5;
int n;
ll ans;
string s;
ll a[N], cnt[2];
int main() {
n = read<int>();
for (int i = 1; i <= n; ++ i) {
scanf("%1lld", &a[i]);
}
for (int i = 1; i <= n; ++ i) {
if (a[i]) {
swap(cnt[1], cnt[0]);
}
else {
cnt[1] += cnt[0];
cnt[0] = 0;
}
++ cnt[a[i]];
ans += cnt[1];
}
cout << ans << '\n';
return 0;
}
F 往后没看题,就不写了。
作者:yifan0305
出处:https://www.cnblogs.com/yifan0305/p/17569826.html
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
转载时还请标明出处哟!
朝气蓬勃 后生可畏
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】