Water world
Year is 3030, water is a scare resource.
Civilizations live around glaciers in clusters, with a federal body (identified as F) in center melting glaciers and controlling the water distribution.
Each cluster has need for water for a day and a water storage capacity.
Cluster are connected to each other with a pipe identified by _.
Linked clusters are connected with overflow pipes.
Every time water starts flowing through pipe, the clusters drain their tanks in an instant, as they can use the water flowing to fill the tanks, and federal body sends water till the capacity is full.
Federal body releases water at start of day, cluster uses water at end of day.
In a pipe link like F-C1-C2-C3-C4, when federal water body targets C3, only C3 and nodes before it (here C1,C2,C3) can fill the tank, C4 can fill it only when it’s targeted.
Pipes are flow controlled and water flows in forward direction only.
Calculate the minimum water needed to help the civilizations survive for n days.
Input is multiline. First line is the number of days to survive. Second line the number of clusters followed by their definitions. Next is the number of links in the system, followed by the link definition.
Read the test cases to understand the scenarios better.
Answers
Answer:
#include<bits/stdc++.h>
using namespace std;
void testfun(map<string, int> mp){
map<string, int>::iterator it = mp.begin();
for(; it!=mp.end(); it++){
cout<<it->first<<":"<<it->second<<" ";
}
cout<<endl;
}
int main()
{
int no, add=0;
cin>>no;
int var;
cin>>var;
map<string, int> d, h;
h["F"] = 0;
while(var--){
string naam;
int a, b;
cin>>naam>>a>>b;
d[naam] = b/a;
h[naam] = b;
add+=b;
}
cin>>var;
while(var--){
string naam, c1="", c2="";
cin>>naam;
int meflux=0;
while(meflux<naam.length()){
if(naam[meflux]=='_'){
c1 = c2;
c2 = "";
meflux++;
continue;
}
c2+=naam[meflux++];
}
h[c2]+= h[c1];
}
//print(days);
//print(storage);
map<string, int>::reverse_iterator a= d.rbegin();
int multiply = 1;
for(; a!=d.rend(); a++ ){
int temperature = a->second*multiply;
if(temperature<no){
add+=(h[a->first]*(no-temperature));
multiply++;
}
}
cout<<add;
}
Explanation:
Sufficient amount of water will be required to help the civilizations survive for any n number of days.
For the survival of any civilization, water is one of the primary requirements that are used to be filled for the sake of humanity. Pipes are flow controlled so that water may flow in the forward direction only.
Water linked clusters are connected with overflowing pipes so that water may not be wasted in any scenario.
This way the civilizations will survive.
#SPJ3