generated from sigonasr2/CPlusPlusProjectTemplate
Finish walkthrough
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
1ee858ae8b
commit
f6e658150f
89
main.cpp
89
main.cpp
@ -5,28 +5,6 @@
|
||||
#include <math.h>
|
||||
#include <fstream>
|
||||
|
||||
void printArr(std::vector<std::string> a, int n){
|
||||
for (int i=0;i<n;i++){
|
||||
std::cout<<a[i]<<" ";
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
}
|
||||
|
||||
void permutation(std::vector<std::string> a,int size, int n){
|
||||
if (size==1){
|
||||
printArr(a,n);
|
||||
return;
|
||||
}
|
||||
for (int i=0;i<size;i++){
|
||||
permutation(a,size-1,n);
|
||||
if (size&1){
|
||||
swap(a[0],a[size-1]);
|
||||
} else {
|
||||
swap(a[i],a[size-i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Room{
|
||||
std::vector<std::string>connections;
|
||||
std::map<std::string,int>paths;
|
||||
@ -51,6 +29,71 @@ int maxFlow=0;
|
||||
int iterations=0;
|
||||
int branchesRemaining=0;
|
||||
|
||||
void printArr(std::vector<std::string> a, int n){
|
||||
int minutesRemaining1=26;
|
||||
int minutesRemaining2=26;
|
||||
std::string currentPos="AA";
|
||||
std::string currentPos2="AA";
|
||||
std::vector<std::string> movePlan1;
|
||||
std::vector<std::string> movePlan2;
|
||||
int moveAmt1=0; //How many steps left to move.
|
||||
int moveAmt2=0; //How many steps left to move.
|
||||
int currentMarker1=0;
|
||||
int currentMarker2=0;
|
||||
int flowRate=0;
|
||||
int flowTotal=0;
|
||||
|
||||
for (int i=0;i<n;i++){
|
||||
std::string valve=a[i];
|
||||
if ((i&1)==0){
|
||||
movePlan1.push_back(valve);
|
||||
} else {
|
||||
movePlan2.push_back(valve);
|
||||
}
|
||||
//std::cout<<a[i]<<" ";
|
||||
}
|
||||
moveAmt1=rooms[currentPos].paths[movePlan1[currentMarker1]];
|
||||
moveAmt2=rooms[currentPos2].paths[movePlan1[currentMarker2]];
|
||||
for (int i=0;i<26;i++){
|
||||
flowTotal+=flowRate;
|
||||
if (moveAmt1==0){
|
||||
//We open the valve. Then move to the next one.
|
||||
flowRate+=rooms[movePlan1[currentMarker1++]].flowValue;
|
||||
if (currentMarker1<movePlan1.size()){
|
||||
moveAmt1=rooms[currentPos].paths[movePlan1[currentMarker1]];
|
||||
}
|
||||
}
|
||||
if (moveAmt2==0){
|
||||
//We open the valve. Then move to the next one.
|
||||
flowRate+=rooms[movePlan2[currentMarker2++]].flowValue;
|
||||
if (currentMarker2<movePlan2.size()){
|
||||
moveAmt2=rooms[currentPos2].paths[movePlan1[currentMarker2]];
|
||||
}
|
||||
}
|
||||
moveAmt1--;
|
||||
moveAmt2--;
|
||||
}
|
||||
if (flowTotal>maxFlow){
|
||||
maxFlow=flowTotal;
|
||||
std::cout<<"New max flow is "<<maxFlow<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void permutation(std::vector<std::string> a,int size, int n){
|
||||
if (size==1){
|
||||
printArr(a,n);
|
||||
return;
|
||||
}
|
||||
for (int i=0;i<size;i++){
|
||||
permutation(a,size-1,n);
|
||||
if (size&1){
|
||||
swap(a[0],a[size-1]);
|
||||
} else {
|
||||
swap(a[i],a[size-i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int findRoute(std::string start,std::string end,std::map<std::string,bool>visited,int dist){
|
||||
visited[start]=true;
|
||||
int distance=INFINITY;
|
||||
@ -157,7 +200,7 @@ int main()
|
||||
}
|
||||
|
||||
permutation(targetRooms,targetRooms.size(),targetRooms.size());
|
||||
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user