Algorithm


Problem Name: beecrowd | 1023

Drought

By Neilor Tonin, URI Brazil

Timelimit: 2

 

Due to the continuous drought that happened recently in some regions of Brazil, the Federal Government created an agency to assess the consumption of these regions in order to verify the behavior of the population at the time of rationing. This agency will take some cities (for sampling) and it will verify the consumption of each of the townspeople and the average consumption per inhabitant of each town.

 

Input

 

The input contains a number of test's cases. The first line of each case of test contains an integer N (1 ≤ N ≤ 1 * 10 6), indicating the amount of properties. The following N lines contains a pair of values X (1 ≤ X ≤ 10) and Y ( 1 ≤ Y ≤ 200) indicating the number of residents of each property and its total consumption (m3). Surely, no residence consumes more than 200 m3 per month. The input's end is represented by zero.

 

Output

 

For each case of test you must present the message “Cidade# n:”, where n is the number of the city in the sequence (1, 2, 3, ...), and then you must list in ascending order of consumption, the people's amount followed by a hyphen and the consumption of these people, rounding the value down. In the third line of output you should present the consumption per person in that town, with two decimal places without rounding, considering the total real consumption. Print a blank line between two consecutives test's cases. There is no blank line at the end of output.

 

 

 

Input Sample Output Sample

3
3 22
2 11
3 39
5
1 25
2 20
3 31
2 40
6 70
2
1 1
3 2
0

Cidade# 1:
2-5 3-7 3-13
Consumo medio: 9.00 m3.

Cidade# 2:
5-10 6-11 2-20 1-25
Consumo medio: 13.28 m3.

Cidade# 3:
3-0 1-1
Consumo medio: 0.75 m3.

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming



#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

int arr[300];

int main(int argc, char const *argv[])
{
 int i, j, n, c = 1, a, b, ta, tp, fp;
 double ip;
 bool bo = false;

 while(scanf("%d", &n) && n)
 {
  if(bo) printf("n");
  bo = true;

  ta = tp = 0;
  memset(arr, 0, sizeof arr);

  for (i = 0; i < n; ++i)
  {
   scanf("%d %d", &a, &b);
   ta += b;
   tp += a;
   arr[b/a] += a;
  }

  printf("Cidade# %d:n", c); c++;

  for(i = 0, j = 0; i  <  300; i++>
  {
            if(arr[i] > 0){
                if(j != 0)
                    printf(" ");
                printf("%d-%d", arr[i], i);
                j++;   
            }  
        }
  printf("n");

  fp = (int) (modf ((double)ta/tp, &ip) * 100);

  if(fp < 10) printf("Consumo medio: %d.0%d m3.n", (int)ip, (int)fp);
  else printf("Consumo medio: %d.%d m3.n", (int)ip, (int)fp>;
 }

 return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 3 22 2 11 3 39 5 1 25 2 20 3 31 2 40 6 70 2 1 1 3 2 0

Output

x
+
cmd
Cidade# 1: 2-5 3-7 3-13 Consumo medio: 9.00 m3. Cidade# 2: 5-10 6-11 2-20 1-25 Consumo medio: 13.28 m3. Cidade# 3: 3-0 1-1 Consumo medio: 0.75 m3.
Advertisements

Demonstration


Previous
#1022 Beecrowd Online Judge Solution 1022 TDA Rational Solution in C, C++, Java, Python and C#
Next
#1025 Beecrowd Online Judge Solution 1025 Where is the Marble? Solution in C, C++, Java, Python and C#