generated from sigonasr2/CPlusPlusProjectTemplate
Completed Part 2
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
55a95a3a08
commit
fb228c81d8
Binary file not shown.
88
main.cpp
88
main.cpp
@ -30,11 +30,13 @@ int maxFlow=0;
|
||||
int iterations=0;
|
||||
int branchesRemaining=0;
|
||||
|
||||
void printArr(int n){
|
||||
void printArr(){
|
||||
int minutesRemaining1=26;
|
||||
int minutesRemaining2=26;
|
||||
std::string currentPos="AA";
|
||||
std::string path1="AA";
|
||||
std::string currentPos2="AA";
|
||||
std::string path2="AA";
|
||||
std::vector<std::string> movePlan1;
|
||||
std::vector<std::string> movePlan2;
|
||||
int moveAmt1=0; //How many steps left to move.
|
||||
@ -44,7 +46,7 @@ void printArr(int n){
|
||||
int flowRate=0;
|
||||
int flowTotal=0;
|
||||
|
||||
for (int i=0;i<n;i++){
|
||||
for (int i=0;i<targetRooms.size();i++){
|
||||
std::string valve=targetRooms[i];
|
||||
if (i&1){
|
||||
movePlan2.push_back(valve);
|
||||
@ -54,45 +56,83 @@ void printArr(int n){
|
||||
//std::cout<<a[i]<<" ";
|
||||
}
|
||||
moveAmt1=rooms[currentPos].paths[movePlan1[currentMarker1]];
|
||||
moveAmt2=rooms[currentPos2].paths[movePlan1[currentMarker2]];
|
||||
moveAmt2=rooms[currentPos2].paths[movePlan2[currentMarker2]];
|
||||
std::cout<<"Current Position 1:"<<currentPos<<std::endl;
|
||||
std::cout<<"Current Position 2:"<<currentPos2<<std::endl;
|
||||
std::cout<<" Flow Total:"<<flowTotal<<std::endl;
|
||||
for (int i=0;i<26;i++){
|
||||
std::cout<<"Minute "<<i+1<<std::endl;
|
||||
flowTotal+=flowRate;
|
||||
if (moveAmt1==0){
|
||||
//We open the valve. Then move to the next one.
|
||||
currentPos=movePlan1[currentMarker1];
|
||||
flowRate+=rooms[movePlan1[currentMarker1++]].flowValue;
|
||||
if (currentMarker1<movePlan1.size()){
|
||||
moveAmt1=rooms[currentPos].paths[movePlan1[currentMarker1]];
|
||||
std::cout<<" Flow: "<<flowTotal<<std::endl;
|
||||
std::cout<<" Flow Rate: "<<flowRate<<std::endl;
|
||||
if (moveAmt1>0){
|
||||
std::cout<<" Moving to "<<movePlan1[currentMarker1]<<" in "<<moveAmt1<<" steps"<<std::endl;
|
||||
} else {
|
||||
if (moveAmt1==0){
|
||||
//We open the valve. Then move to the next one.
|
||||
currentPos=movePlan1[currentMarker1];
|
||||
path1+="->"+currentPos;
|
||||
std::cout<<" Path1: "<<path1<<std::endl;
|
||||
flowRate+=rooms[movePlan1[currentMarker1++]].flowValue;
|
||||
//flowTotal+=rooms[movePlan1[currentMarker1++]].flowValue;
|
||||
std::cout<<" Flow rate is now "<<flowRate<<std::endl;
|
||||
if (currentMarker1<movePlan1.size()){
|
||||
moveAmt1=rooms[currentPos].paths[movePlan1[currentMarker1]]+1;
|
||||
std::cout<<" Reached destination. Next: "<<movePlan1[currentMarker1]<<" in "<<moveAmt1<<" steps"<<std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (moveAmt2==0){
|
||||
//We open the valve. Then move to the next one.
|
||||
currentPos2=movePlan2[currentMarker2];
|
||||
flowRate+=rooms[movePlan2[currentMarker2++]].flowValue;
|
||||
if (currentMarker2<movePlan2.size()){
|
||||
moveAmt2=rooms[currentPos2].paths[movePlan1[currentMarker2]];
|
||||
if (moveAmt2>0){
|
||||
std::cout<<" Moving to "<<movePlan2[currentMarker2]<<" in "<<moveAmt2<<" steps"<<std::endl;
|
||||
} else {
|
||||
if (moveAmt2==0){
|
||||
//We open the valve. Then move to the next one.
|
||||
currentPos2=movePlan2[currentMarker2];
|
||||
path2+="->"+currentPos2;
|
||||
std::cout<<" Path2: "<<path2<<std::endl;
|
||||
flowRate+=rooms[movePlan2[currentMarker2++]].flowValue;
|
||||
//flowTotal+=rooms[movePlan2[currentMarker2++]].flowValue;
|
||||
std::cout<<" Flow rate is now "<<flowRate<<std::endl;
|
||||
if (currentMarker2<movePlan2.size()){
|
||||
moveAmt2=rooms[currentPos2].paths[movePlan2[currentMarker2]]+1;
|
||||
std::cout<<" Reached destination. Next: "<<movePlan2[currentMarker2]<<" in "<<moveAmt2<<" steps"<<std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
moveAmt1--;
|
||||
moveAmt2--;
|
||||
}
|
||||
std::cout<<"Final Flow Total: "<<flowTotal<<std::endl;
|
||||
if (flowTotal>maxFlow){
|
||||
maxFlow=flowTotal;
|
||||
std::cout<<"New max flow is "<<maxFlow<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void permutation(int size, int n){
|
||||
void printArr2(std::vector<std::string> arr){
|
||||
for (int i=0;i<arr.size();i++){
|
||||
if (i!=0){
|
||||
std::cout<<" ";
|
||||
}
|
||||
std::cout<<arr[i];
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
void permutation(std::vector<std::string>&arr,int size){
|
||||
if (size==1){
|
||||
printArr(n);
|
||||
printArr();
|
||||
return;
|
||||
}
|
||||
for (int i=0;i<size;i++){
|
||||
permutation(size-1,n);
|
||||
if (size&1){
|
||||
swap(targetRooms[i],targetRooms[size-i]);
|
||||
} else {
|
||||
swap(targetRooms[0],targetRooms[size-1]);
|
||||
permutation(arr,size-1);
|
||||
if (i<size-1){
|
||||
if (size%2==1){
|
||||
std::swap(arr[0],arr[size-1]);
|
||||
} else {
|
||||
std::swap(arr[i],arr[size-1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -158,7 +198,7 @@ void explore(std::string currentRoom,std::map<std::string,bool>visitedvalves,int
|
||||
|
||||
int main()
|
||||
{
|
||||
std::ifstream file("testinput");
|
||||
std::ifstream file("input");
|
||||
while (file.good()){
|
||||
std::string line;
|
||||
std::getline(file,line);
|
||||
@ -201,7 +241,7 @@ int main()
|
||||
}
|
||||
}
|
||||
|
||||
permutation(targetRooms,targetRooms.size(),targetRooms.size());
|
||||
permutation(targetRooms,targetRooms.size());
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user