AcWing 4800. 下一个
签到
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
int x;
cin >> x;
auto f = []( int x){
set<int> a;
for( int y ; x > 0; x /= 10 ) {
y = x % 10;
if( a.count(y) ) return false;
a.insert(y);
}
return true;
};
for( int i = x + 1 ; i ; i ++ ){
if( !f(i) ) continue;
cout << i << "\n";
return 0;
}
return 0;
}
AcWing 4801. 强连通图
这题实际上是一个诈骗题,因为任意一个点一定可以走到边界上,且边界可以走到任意一个点上。所以只要边界是一个环就是YES
,否则就是NO
#include<bits/stdc++.h>
using namespace std;
int main(){
int n , m;
string a , b;
cin >> n >> m >> a >> b;
if( a[0] == '<' && a[n-1] == '>' && b[0] == 'v' && b[m-1] == '^' )
cout << "YES\n";
else if ( a[0] == '>' && a[n-1] == '<' && b[0] == '^' && b[m-1] == 'v' )
cout << "YES\n";
else
cout << "NO\n";
return 0;
}
AcWing 4802. 金明的假期
简单的dp,似乎比上一题还要简单
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
int n;
cin >> n;
vector<int> a(n+1);
for( int i = 1 ; i <= n ; i ++ )
cin >> a[i];
vector<vector<int>> f(n+1 , vector<int>(3) );
for( int i = 1 ; i <= n ; i ++ ){
if( a[i] == 0 ) f[i][0] = f[i][1] = INT_MAX;
else if( a[i] == 1 ) f[i][0] = INT_MAX , f[i][1] = min( f[i-1][0] , f[i-1][2] );
else if( a[i] == 2 ) f[i][0] = min( f[i-1][1] , f[i-1][2] ) , f[i][1] = INT_MAX;
else f[i][0] = min( f[i-1][1] , f[i-1][2] ) , f[i][1] = min( f[i-1][0] , f[i-1][2] );
f[i][2] = min( { f[i-1][0] , f[i-1][1] , f[i-1][2] } ) + 1;
}
cout << min( { f[n][0] , f[n][1] , f[n][2] } );
return 0;
}
标签:周赛,int,namespace,88,vector,&&,main,AcWing
From: https://www.cnblogs.com/PHarr/p/17095877.html