Algo-Trian
This commit is contained in:
28
Algorithm/Bit/P12141 [蓝桥杯 2025 省 A] 假红黑树.cpp
Normal file
28
Algorithm/Bit/P12141 [蓝桥杯 2025 省 A] 假红黑树.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
int checkbin(long long s){
|
||||
int js = 0;
|
||||
while(s){
|
||||
js += (s & 1);
|
||||
s = s>> 1;
|
||||
}
|
||||
return js;
|
||||
}
|
||||
int main(){
|
||||
int n;
|
||||
cin >> n;
|
||||
vector<long long> s(n);
|
||||
for(int i = 0; i < n; i++){
|
||||
int a, b;
|
||||
cin >> a >> b;
|
||||
s[i] = ( 1 << (a - 1) ) + (b - 1);
|
||||
}
|
||||
for(int i = 0; i < n; i++){
|
||||
if(checkbin(s[i]) % 2 == 0) cout << "BLACK" << endl;
|
||||
else cout << "RED" << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
35
Algorithm/Bit/全排列.cpp
Normal file
35
Algorithm/Bit/全排列.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <iomanip>
|
||||
using namespace std;
|
||||
vector<vector<int>> result;
|
||||
void dfs(vector<int>& path, vector<bool>& used, int n){
|
||||
int js = 0;
|
||||
for(int i = 0; i < n; i++){
|
||||
if(used[i] == false){
|
||||
js++;
|
||||
used[i] = true;
|
||||
path.push_back(i);
|
||||
dfs(path, used, n);
|
||||
path.pop_back();
|
||||
used[i] = false;
|
||||
}
|
||||
}
|
||||
if(js == 0){
|
||||
result.push_back(path);
|
||||
return;
|
||||
}
|
||||
}
|
||||
int main(){
|
||||
int n;
|
||||
cin >> n;
|
||||
vector<int> path;
|
||||
vector<bool> used(n, false);
|
||||
dfs(path, used, n);
|
||||
for(auto x : result){
|
||||
for(auto y: x){
|
||||
cout << setw(5) << y + 1;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user