AtCoder Beginner Contest 298

1|0A - Job Interview


#include <bits/stdc++.h> using namespace std; int main(){ int n; string s; cin >> n >> s; if( s.find("x") != -1 ){ printf("No\n"); }else if( s.find("o") == -1 ){ printf("No\n"); }else printf("Yes\n"); return 0; }

2|0B - Coloring Matrix


旋转三次然后暴力比较

#include <bits/stdc++.h> using namespace std; const int N = 105; int a[N][N] , b[N][N] , c[N][N]; int main(){ int n; cin >> n; for( int i = 1 ; i <= n ; i ++ ) for( int j = 1 ; j <= n ; j ++ ) cin >> a[i][j]; for( int i = 1 ; i <= n ; i ++ ) for( int j = 1 ; j <= n ; j ++ ) cin >> b[i][j]; for( int k = 4 ; k ; k -- ){ bool f = true; for( int i = 1 ; f && i <= n ; i ++ ){ for( int j = 1 ; f && j <= n ; j ++ ){ if( a[i][j] == 1 && b[i][j] != 1 ) f = false; } } if( f ) return printf("Yes\n") , 0; for( int i = 1 ; i <= n ; i ++ ) for( int j = 1 ; j <= n ; j ++ ) c[n+1-j][i] = a[i][j]; for( int i = 1 ; i <= n ; i ++ ) for( int j = 1 ; j <= n ; j ++ ) a[i][j] = c[i][j]; } printf("No\n"); return 0; }

3|0C - Cards Query Problem


整两个set数组维护一下就好了,注意 box 中的 card 要用 multiset维护,因为会重复

#include <bits/stdc++.h> using namespace std; int read(){ int ch = getchar() , x = 0; while( ch < '0' || ch > '9' ) ch = getchar(); while( ch >= '0' && ch <= '9' ) x = (x<<3)+(x<<1) + ch - '0' , ch = getchar(); return x; } const int N = 2e5+5; int n; multiset<int> box[N]; set<int> card[N]; int main(){ int n = read() , q = read(); for( int op , x , y ; q ; q -- ){ op = read(); if( op == 1 ){ x = read() , y = read(); box[y].insert(x) , card[x].insert(y); }else{ x = read(); if( op == 2 ){ for( auto i : box[x] ) printf("%d " , i ); }else{ for( auto i : card[x] ) printf("%d " , i ); } printf("\n"); } } }

4|0D - Writing a Numeral


其实只要知道每个数被乘十了多少次就很好算了

#include <bits/stdc++.h> using namespace std; #define int long long int read(){ int ch = getchar() , x = 0; while( ch < '0' || ch > '9' ) ch = getchar(); while( ch >= '0' && ch <= '9' ) x = (x<<3)+(x<<1) + ch - '0' , ch = getchar(); return x; } const int mod = 998244353; int power( int x , int y ){ int ans = 1; while( y ){ if( y & 1 ) ans = ans * x % mod; x = x * x % mod , y >>= 1; } return ans; } int32_t main(){ vector<int> dq; int pos = 0; dq.push_back(1); int cnt = 1 , q = read(); for( int op , x ; q ; q -- ){ op = read(); if( op == 1 ){ x = read(); cnt = (cnt * 10 % mod + x) % mod; dq.push_back(x); }else if( op == 2 ){ x = dq[pos++]; x = mod - x * power( 10 , dq.size() - pos ) % mod; cnt = ( cnt + x ) % mod; }else printf("%lld\n" , cnt); } }

5|0F - Rook Score


首先用map统计一下每一行每一列的和。然后考虑枚举(r,c)。这里可以分成两类情况。

第一种(r,c)位置上的值不是 0,此时枚举所有的点就好。

第二种(r,)位置上的值是 0 ,首先把所有的行列都取出来按照和从大到小排序。然后枚举行行列,如果找到了(r,c)不存在的情况就更新答案并 break,因为已经排序后面找到一定更小。

#include<bits/stdc++.h> using namespace std; #define int long long 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() { int n = read(); map<int, int> cntR, cntC; map<int, map<int, int>> val; set<pair<int, int>> st; for (int x, y, w; n; n--) { x = read(), y = read(), w = read(); cntR[x] += w, cntC[y] += w, val[x][y] = w, st.emplace(x, y); } vector<pair<int, int>> r, c; for (auto [k, v]: cntR) r.emplace_back(v, k); for (auto [k, v]: cntC) c.emplace_back(v, k); sort(r.begin(), r.end(), greater<pair<int, int>>()); sort(c.begin(), c.end(), greater<pair<int, int>>()); int res = 0; for (auto [x, y]: st) res = max(res, cntR[x] + cntC[y] - val[x][y] ); for( auto [ v1 , x ] : r ) for( auto [ v2 , y ] : c ){ if( st.count(make_pair(x,y) ) ) continue; res = max( res , v1 + v2 ); break; } cout << res << "\n"; return 0; }

__EOF__

本文作者PHarr
本文链接https://www.cnblogs.com/PHarr/p/17334309.html
关于博主:前OIer,SMUer
版权声明CC BY-NC 4.0
声援博主:如果这篇文章对您有帮助,不妨给我点个赞
posted @   PHarr  阅读(25)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示