Algorithm
This commit is contained in:
24
Algorithm/Recursion/UVA699 下落的树叶 The Falling Leaves.cpp
Normal file
24
Algorithm/Recursion/UVA699 下落的树叶 The Falling Leaves.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
using namespace std;
|
||||
//<2F><><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>
|
||||
|
||||
map<int, int> sum;
|
||||
void build(int p){
|
||||
int tmp;
|
||||
cin >> tmp;
|
||||
if(tmp == -1) return;
|
||||
sum[p] += tmp;
|
||||
build(p - 1);
|
||||
build(p + 1);
|
||||
}
|
||||
|
||||
int main(){
|
||||
build(0);
|
||||
if(!sum.empty()){
|
||||
for(auto it = sum.begin(); it != sum.end(); ++it){
|
||||
cout << it->second << " ";
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
58
Algorithm/Recursion/UVa839 天平Not_so_Mobile.cpp
Normal file
58
Algorithm/Recursion/UVa839 天平Not_so_Mobile.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#include <iostream>
|
||||
//ǰ<><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ݹ<EFBFBD><DDB9><EFBFBD><EFBFBD>컨<EFBFBD><ECBBA8>
|
||||
using namespace std;
|
||||
struct mobile{
|
||||
double lw, ll, rw, rl;
|
||||
double weight;
|
||||
mobile* left;
|
||||
mobile* right;
|
||||
|
||||
mobile(double a, double b, double c, double d) : lw(a), ll(b), rw(c), rl(d), left(nullptr), right(nullptr) {}
|
||||
};
|
||||
|
||||
bool solve(mobile* &x){
|
||||
double a, b, c, d;
|
||||
bool b1 = true, b2 = true;
|
||||
cin >> a >> b >> c >> d;
|
||||
x = new mobile(a, b, c, d);
|
||||
if(!x->lw) b1 = solve(x->left);
|
||||
if(!x->rw) b2 = solve(x->right);
|
||||
double leftWeight = x->left ? x->left->weight : x->lw;
|
||||
double rightWeight = x->right ? x->right->weight : x->rw;
|
||||
x->weight = leftWeight + rightWeight;
|
||||
//<2F><>עreturn<72><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD>solveһ<65><D2BB><EFBFBD>Ǿ<EFBFBD><C7BE>Ƕ<EFBFBD><C7B6>εݹ<CEB5><DDB9>ˣ<EFBFBD><CBA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>solve<76><65>
|
||||
return b1 && b2 && (leftWeight * x->ll == rightWeight * x->rl);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int n;
|
||||
cin >> n;
|
||||
string tmp;
|
||||
getline(cin, tmp); // <20><>ȡ<EFBFBD><C8A1>һ<EFBFBD>к<EFBFBD><D0BA>Ļ<EFBFBD><C4BB><EFBFBD>
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
mobile* root = nullptr;
|
||||
bool ok = solve(root);
|
||||
cout << (ok ? "YES" : "NO") << "\n";
|
||||
|
||||
if (i != n - 1) cout << "\n"; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ֮<D1AF><D6AE><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||
}
|
||||
/*
|
||||
for(int i = 0; i < n - 1; i++){
|
||||
cin >> a >> b >> c >> d;
|
||||
mobile* tmp = new mobile(a, b, c, d);
|
||||
if(a && !b){
|
||||
|
||||
}
|
||||
}
|
||||
<09><><EFBFBD>Dz<EFBFBD><C7B2>õģ<C3B5>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD><C8BB>Ȼ<EFBFBD><C8BB><EFBFBD>γ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
BIN
Algorithm/Recursion/readme.md
Normal file
BIN
Algorithm/Recursion/readme.md
Normal file
Binary file not shown.
Reference in New Issue
Block a user