A - Sequence of Strings
#include<bits/stdc++.h>
using namespace std;
int32_t main(){
int n;
cin >> n;
vector<string> s(n);
for( auto &i : s ) cin >> i;
for( int i = n-1 ; i >= 0 ; i -- )
cout << s[i] << "\n";
return 0;
}
B - Multi Test Cases
#include<bits/stdc++.h>
using namespace std;
int read(){...}
void solve(){
int n = read() , res = 0;
for( int x ; n ; n -- ){
x = read();
if( x & 1 ) res ++;
}
cout << res << "\n";
return;
}
int32_t main(){
for( int T = read() ; T ; T -- )
solve();
return 0;
}
C - Count Connected Components
#include<bits/stdc++.h>
using namespace std;
int read(){...}
vector<int> vis;
vector<vector<int>> e;
void dfs( int u ){
vis[u] = 1;
for( auto v : e[u] ){
if( vis[v] ) continue;
dfs(v);
}
return;
}
int32_t main(){
int n = read() , m = read() , res = 0;
e.resize(n+1) , vis.resize(n+1);
for( int u , v ; m ; m -- )
u = read() , v = read() , e[u].push_back(v) , e[v].push_back(u);
for( int i = 1 ; i <= n ; i ++ ){
if( vis[i] ) continue;
dfs(i) , res ++;
}
cout << res << "\n";
return 0;
}
D - Happy New Year 2023(补题)
根据唯一分解定理,\(p^2q\)是唯一的,且\(max(p,q)\le \sqrt[3]{n}\)
所以直接暴力写就好
#include<bits/stdc++.h>
#define int unsigned long long
typedef long long ll;
using namespace std;
int read(){...}
void solve(){
int n = read();
for( int i = 2 , j ; ; i ++ ){
if( n % i != 0 ) continue;
n /= i;
if( n % i == 0 ) j = n / i;
else j = i , i = sqrt( n );
cout << i << " " << j << "\n";
return;
}
}
int32_t main(){
for( int T = read() ; T ; T -- ) solve();
return 0;
}
E - Count Simple Paths
非常简单的统计一下从1开始的简单路径,dfs不断的搜索就好了。
#include<bits/stdc++.h>
using namespace std;
int read(){...}
const int N = 1e6 ;
int n , m , res;
vector<int> vis;
vector<vector<int>> e;
void dfs( int u ){
vis[u] = 1;
res ++;
if( res == N ){
cout << res<<"\n";
exit(0);
}
for( auto v : e[u] ){
if( vis[v] ) continue;
dfs(v);
}
vis[u] = 0;
return;
}
int32_t main(){
n = read() , m = read() , res = 0;
e.resize(n+1) , vis.resize(n+1);
for( int u , v ; m ; m -- ){
u = read() , v = read();
e[u].push_back(v) , e[v].push_back(u);
}
dfs(1);
cout << res << "\n";
return 0;
}