AtCoder Beginner Contest 300

1|0A - N-choice question


#include<bits/stdc++.h> using namespace std; int read() { int x = 0, f = 1, ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') f = -1, ch = getchar(); while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar(); return x * f; } const int N = 1e5+5; bool vis[N]; vector<int> e[N] ; int d[N]; int main() { int n = read() , a = read() , b = read(); for( int x , i = 1 ; i <= n ; i ++ ){ x = read(); if( x == a + b ) cout << i , exit(0); } return 0; }

2|0B - Same Map in the RPG World


看起来似乎很复杂,其实可以直接枚举横着移动多少次,竖着移动多少次就行了。

#include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false) , cin.tie(nullptr) , cout.tie(nullptr); int n , m; cin >> n >> m; vector<string> a(n) , b(n); for( auto & i : a ) cin >> i; for( auto & i : b ) cin >> i; for( int r = 0 ; r < n ; r ++ ) for( int c = 0 ; c < m ; c ++ ){ int f = 1; for( int i = 0 ; f && i < n ; i ++ ) for( int j = 0 ; f && j < m ; j ++ ){ if( a[i][j] != b[(i+r)%n][ (j+c) % m ] ) f = 0; } if( f ) cout << "Yes\n" , exit(0); } cout << "No\n"; return 0; }

3|0C - Cross


暴力枚举点的坐标,暴力枚举大小,然后暴力判断即可。

#include<bits/stdc++.h> using namespace std; const int dx[] = {1, 1, -1, -1}; const int dy[] = {-1, 1, -1, 1}; int main() { ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); int n, m; cin >> n >> m; vector<string> g(n); vector<int> cnt(min(n, m) + 1); for (auto &i: g) cin >> i; for (int i = 0, t; i < n; i++) for (int j = 0; j < m; j++) { if (g[i][j] == '.') continue; t = 0; for (int k = 1, f; k; k++) { f = 1; for (int l = 0; l < 4 && f; l++) if (g[i + dx[l] * k][j + dy[l] * k] == '.') f = 0; if (f) t = k; else break; } cnt[t]++; } for (int i = 1; i < cnt.size(); i++) cout << cnt[i] << " "; return 0; }

4|0D - AABCC


首先求一下素数,然后枚举a,b二分c就好了。

#include<bits/stdc++.h> using namespace std; #define int __int128 typedef long long ll; int read() { int x = 0, f = 1, ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') f = -1, ch = getchar(); while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar(); return x * f; } int32_t main() { ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); const int N = 300000; vector<int> not_prime(N + 1, 0); vector<int> prime; not_prime[0] = not_prime[1] = true; for (int i = 2; i <= N; i++) { if (not_prime[i]) continue; prime.push_back(i); for (int j = i * 2; j <= N; j += i) not_prime[j] = 1; } int n = read(), res = 0; for (int i = 0, a, b; i < prime.size(); i++) { a = prime[i] * prime[i]; if (a > n) break; for (int j = i + 1; j < prime.size(); j++) { b = prime[j] * a; if (b > n) break; int l = j + 1, r = prime.size() - 1, mid, ans = -1; while (l <= r) { mid = (l + r) >> 1; if (b * prime[mid] * prime[mid] <= n) ans = mid, l = mid + 1; else r = mid - 1; } if (ans == -1) break; res += ans - j; } } cout << (ll) res << "\n"; return 0; }

5|0E - Dice Product 3


有题可知

f(i)=16(f(i)+f(i2)+f(i3)+f(i4)+f(i5)+f(i6))

56f(i)=16(f(i2)+f(i3)+f(i4)+f(i5)+f(i6))

f(i)=15(f(i2)+f(i3)+f(i4)+f(i5)+f(i6))

其中f(1)=1,如果不能整除的话就是0

然后直接记忆化搜索一下?

#include<bits/stdc++.h> using namespace std; #define int long long int read() { int x = 0, f = 1, ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') f = -1, ch = getchar(); while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar(); return x * f; } const int mod = 998244353, inv = 598946612; map<int, int> f; int dp(int n) { if (f.count(n)) return f[n]; int ans = 0; for (int i = 2; i <= 6; i++) if (n % i == 0) ans = (ans + dp(n / i)) % mod; return f[n] = ans * inv % mod; } int32_t main() { int n; cin >> n; f[1] = 1; cout << dp(n); return 0; }

6|0F - More Holidays


记录S中每一个x的位置,很容易可以想到相邻的x一定是最优的,所以直接枚举一下起点就好。但是枚举的是时候实际上只用枚举第一个S中的位置就可以。然后特判第一个和最后一个的特殊情况。

#include <bits/stdc++.h> using namespace std; #define int long long int32_t main(){ ios::sync_with_stdio(false) , cin.tie(nullptr) , cout.tie(nullptr); int n , m , k; string s; cin >> n >> m >> k >> s; vector<int> p; for( int i = 0 ; i < n ; i ++ ) if( s[i] == 'x' ) p.push_back(i); int cnt = p.size() , t = cnt * m; if( cnt * m == k ) cout << n * m , exit(0); int res = 0; res = max( res , n * ( k / cnt ) + p[k%cnt] ); res = max( res , n * ( k / cnt ) + n - 1 - p[cnt - 1 - k % cnt] ); for( int i = 0 ; i < cnt ; i ++ ){ if( k + i + 1 < t ) res = max( res , p[(k+i+1)%cnt] + n * ((k+i+1) / cnt) - p[i] - 1 ); } cout << res; return 0; }

__EOF__

本文作者PHarr
本文链接https://www.cnblogs.com/PHarr/p/17369742.html
关于博主:前OIer,SMUer
版权声明CC BY-NC 4.0
声援博主:如果这篇文章对您有帮助,不妨给我点个赞
posted @   PHarr  阅读(25)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示