Algorithm
Problem Name: beecrowd | 2533
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2533
Internship
By Ricardo Oliveira, UFPR Brazil
Timelimit: 1
Googlbook is a famous IT company that opened an office in your town this year! Also, Googlbook has just offered interviews to an internship position in the company!
To be interviewed, you need to send some personal information to the company, that will be used to decide who will earn the position. You sent all information they need except one: your API (Academic Performance Index). To get things worse, Student’s Portal, the system that provide your API, is not working!
Fortunately, you remember all the grades you got in all M subjects you coursed, as well their workloads. You also remember how the API is calculated:
, where N1, N2, ..., NM are your grades in each subject, and C1, C2, ..., CM are the workload of the respective subjects.
Given the grades you got and the workload of each subject, determine your API, so you can send it to Googlbook as soon as possible!
Input
The input contains several test cases. The first line of each test case contains integer M (1 ≤ M ≤ 40), the number of subjects you coursed. Each of the next M lines describe a subject. Each line contains two integers Ni and Ci (0 ≤ Ni ≤ 100, 30 ≤ Ci ≤ 120), indicating the grade you got in that subject and its workload, respectively.
The input ends with end-of-file (EOF).
Output
For each test case, print a line containing your API. Round and print it with exactly 4 decimal places.
Input Sample | Output Sample |
3 |
0.8000 |
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include<stdio.h>
int main()
{
int m,ar[2],i,n,c;
while(scanf("%d",&m)!=EOF){
ar[0] = 0;
ar[1] = 0;
for(i = 0; i < m; i++){
scanf("%d %d",&n,&c);
ar[0]+=n*c;
ar[1]+=100*c;
}
printf("%.4f\n",(float)ar[0]/(float)ar[1]);
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with Java Programming
Code -
Java Programming
import java.util.*;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc=new Scanner(System.in);
int t;
while(sc.hasNext()){
t=sc.nextInt();
float d=0,e=0;
for(int i = 1;i < = t; i++)
{
int N,C;
N=sc.nextInt();
C=sc.nextInt();
d=d+(N*C);
e=e+C;
}
e=e*100;
float x=d/e;
System.out.printf("%.4f\n",x);
}
}
}
Copy The Code &
Try With Live Editor
Input
Output
#3 Code Example with Javascript Programming
Code -
Javascript Programming
const { readFileSync } = require("node:fs")
const input = readFileSync("/dev/stdin", "utf8")
.split("\n")
.map(line => line.split(" ", 2).map(value => Number.parseInt(value, 10)))
function main() {
const output = []
while (input.length > 0) {
const [M] = input.shift()
if (Number.isNaN(M)) break // EOF Condition
const disciplines = input.splice(0, M)
const IRA =
disciplines.reduce((total, [N, C]) => total + (N * C), 0)
/ disciplines.reduce((total, [, C]) => total + C, 0)
/ 100
output.push(IRA.toFixed(4))
}
console.log(output.join("\n"))
}
main()
Copy The Code &
Try With Live Editor
Input
Output
#4 Code Example with Python Programming
Code -
Python Programming
while True:
try:
ci = ba = 0
for g in range(int(input())):
a, b = [int(x) for x in input().split()]
ci += a * b
ba += b
ba *= 100
print('{:.4f}'.format(ci / ba))
except EOFError: break
Copy The Code &
Try With Live Editor
Input
Output