牛客小白月赛59

1|0我会开摆


枚举一下左上角即可

#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; } string g[5]; void solve(){ for( int i = 0 ; i < 4 ; i ++ ) cin >> g[i]; for( int i = 0 ; i < 3 ; i ++ ) for( int j = 0 ; j < 3 ; j ++ ) if( g[i][j] == g[i][j+1] && g[i][j] == g[i+1][j] && g[i][j] == g[i+1][j+1] ){ cout << "Yes\n"; return; } cout << "No\n"; return; } int32_t main() { for( int t = read() ; t ; t -- ) solve(); return 0; }

2|0走廊的灯


找一下联系非1 的长度和连续非 0 的长度,取较大值

#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; } string g[5]; void solve(){ int n = read(); string s; cin >> s; int cnt = 0 , res = 0; for( auto c : s ){ if( c != '1' ) cnt ++ , res = max( res , cnt ); else cnt = 0; } cnt = 0; for( auto c : s ){ if( c != '0' ) cnt ++ , res = max( res , cnt ); else cnt = 0; } cout << res << "\n"; return; } int32_t main() { for( int t = read() ; t ; t -- ) solve(); return 0; }

3|0输出练习


特判 0 的所有次方有 0 和 1,1的所有次方只有1。

对于当前数字tt×kr时可以结束循环,对该式子变换可得trk

#include<bits/stdc++.h> #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; } void solve(){ int l = read() , r = read() , k = read() , f = 0; if( k == 0 && l <= 0 && 0 <= r ) std::cout << "0 " , f = 1; if( l <= 1 && 1 <= r ) std::cout<< "0\n"; for( int t = 1 ; k > 1 && t <= r / k; t *= k ){ t *= k; if( t >= l ) std::cout << t , f = 1; } if( f ) printf("\n"); else printf("None.\n"); return; } int32_t main() { for( int t = read() ; t ; t -- ) solve(); return 0; }

4|0国际象棋


我的做法是用两个 set 分别存储棋子是否存在,对于每次下一个棋子,统计他所在的四条线上相邻的同色棋子数量。

#include<bits/stdc++.h> #define int long long 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 dx[] = {1,1,0,-1}; const int dy[] ={0,1,1,1}; const int N = 1e3+5; int h[N]; set< pair<int,int> > g[2]; int32_t main() { int n = read() , m = read() , k = read() , t = read(); for( int i = 1 , x , y , c = 1 ; i <= t ; i ++ , c ^= 1 ){ x = read() , y = ++h[x] ; g[c].insert(make_pair( x , y ) ); for( int d = 0 ; d < 4 ; d ++ ){ int cnt = 1; for( int j = 1 ; ; j ++ ){ if( g[c].find(make_pair( x + dx[d]*j , y + dy[d]*j ) ) != g[c].end() ) cnt ++; else break; } for( int j = -1 ; ; j -- ){ if( g[c].find(make_pair( x + dx[d]*j , y + dy[d]*j ) ) != g[c].end() ) cnt ++; else break; } if( cnt >= k ){ cout << i << "\n"; return 0; } } } return 0; }

__EOF__

本文作者PHarr
本文链接https://www.cnblogs.com/PHarr/p/16842343.html
关于博主:前OIer,SMUer
版权声明CC BY-NC 4.0
声援博主:如果这篇文章对您有帮助,不妨给我点个赞
posted @   PHarr  阅读(25)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
历史上的今天:
2019-10-30 OI时期其他题解
点击右上角即可分享
微信分享提示