URI 1093 Solution in C, C++ | URI Vampire Solution
URI Online Judge Solution 1093 Vampire | Mathematics
URI Main Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1093
Problem Name: URI Problem 1093 Vampire Solution
Problem Number : URI Problem 1093 Solution
Online Judge : URI Online Judge Solution
Level: Mathematics
Solution Language : C, C plus plus
URI Solution 1093 Code in ANSI C:
#include <stdio.h> #include <math.h> double foo(int x, int n2, int at) { double d; if(at == 3) { return (double)x/(double)(x + n2); }else{ d = 1.0 - (6 - at)/6.0, d = (1 - d)/d; return (1.0 - pow(d, x))/(1.0 - pow(d, x + n2)); } } int main(int argc, char const *argv[]) { int ev1, ev2, at, d, tmp; double p; while(scanf("%d%d%d%d", &ev1, &ev2, &at, &d) && (ev1 || ev2 || at || d)){ tmp = ev1, ev1 = 0; while(tmp > 0){ tmp -= d, ev1++; } tmp = ev2, ev2 = 0; while(tmp > 0){ tmp -= d, ev2++; } p = foo(ev1, ev2, at); printf("%.1f\n", p * 100); } return 0; }
URI Solution 1093 Code in C++:
#include <stdio.h> #include <math.h> double gambler(int n1, int n2, int at){ double dado; if(at == 3){ return (double)n1/(double)(n1+n2); }else{ dado = 1.0 - (6-at)/6.0; dado = (1 - dado)/dado; return (1.0 - pow(dado,n1))/(1.0 - pow(dado,n1+n2)); } } int main(){ int ev1, ev2, at, d, aux; double p; for(;;){ scanf("%d %d %d %d",&ev1,&ev2,&at,&d); if(ev1 == 0 && ev2 == 0 && at == 0 && d == 0) break; aux = ev1; ev1 = 0; while(aux > 0){ aux -= d; ev1++; } aux = ev2; ev2 = 0; while(aux > 0){ aux -= d; ev2++; } p = gambler(ev1,ev2,at); printf("%.1f\n",p*100); } return 0; }
Tags:
Uri solve , Uri solution, URI oj Solve, URI Online Judge Solution list, URI 1093 Solution, URI Vampire Solution
No comments:
Write commentsTo know more about the problem, give us your valuable commment. We'll try to help you. Thanks