牛客小白月赛59
我会开摆
枚举一下左上角即可
#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;
}
走廊的灯
找一下联系非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;
}
输出练习
特判 0 的所有次方有 0 和 1,1的所有次方只有1。
对于当前数字\(t\)当\(t\times k \ge r\)时可以结束循环,对该式子变换可得\(t\ge \frac{r}{k}\)
#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;
}
国际象棋
我的做法是用两个 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;
}