Dhaka Regional ACM ICPC 2016 Preleminary Contest Solution A - A Directed Graph
A. A Directed Graph
Score: 1
CPU: 1s
Memory: 1200MB
CPU: 1s
Memory: 1200MB
Some people often ask what is the real-life usage of algorithm. There are tons of such usages and one popped up in the following real life scenario.
One day Alpha, Beta and Gamma went for dinner. When the bill came, we saw Alpha is charged with 23 takas, Beta with 21 takas and Gamma with 24 takas. So, Alpha gave 20 takas to Beta and Beta does not mind paying 3 takas out of his pocket for Alpha. Other than these 3 takas, Beta will pay for himself and also for Gamma. So, Beta gave 100 takas to Gamma and asked Gamma to pay to the restaurant boy. However, after a while, Beta said- “Hey Alpha, why don’t you pay for Gamma today. And for my meal, here is the 20 takas, I guess you won’t mind paying the rest.” Alpha agreed to the proposal (and paid the restaurant) and Beta took the 100 takas back from Gamma.
Now the question is, after all these transactions how much money was spent by each one of Alpha, Beta and Gamma.
I guess you can easily solve this problem by yourself. But some people may find it difficult to solve such puzzles. In such case, it may be convenient to draw three nodes for Alpha, Beta and Gamma. And draw directed edges between nodes representing money transaction. Maybe you can add another node for the restaurant to complete the picture. So, if X pays Z amount of money to Y, we will draw an edge from X to Y with cost Z. And thus, the total amount of money paid by X will be the sum of costs of outgoing edges minus sum of costs of incoming edges. Nice, right?
Input
There will be no input to this problem.
Output
Output three numbers in a line. The amount of money paid by Alpha, Beta and Gamma from their pocket. If you think Alpha, Beta and Gamma paid 10, 20, 30 takas respectively out of their pocket then the output will look like the sample output.
Sample
Input | Output |
---|---|
No Sample Input | 10 20 30 |
Hint: Code snippet in C/C++ to print the above sample output
#include<stdio.h>
int main(){
int alpha = 10, beta = 20, gamma = 30;
printf("%d %d %d\n", alpha, beta, gamma);
return 0;
}
Comments
Post a Comment