Randomly Testing Circuits
Randomly Testing Circuits
Signup with
Have you tried CodeChefs "Code, Compile & Run" Its pretty cool. Try it out by pressing Ctrl+; and
typing "ide" [X]
Input
jyotesh 0.01 1.6M C View
The first line indicates the number of test cases to follow (about 100).
Each test case begins with a single line containing a single integer n with 1 n 100 indicating the lifeenergy999 0.01 1.6M C View
number of nodes (inputs and gates) in the circuit. Following this, n lines follow where the i'th line
describes the i'th node. If the node is an input, the line simply consists of the integer 0. Otherwise, if the asheybo 0.01 1.6M C View
node is an OR gate then the line begins with a 1 and if the node is an AND gate then the line begins with
a 2. In either case, two more integers a,b follow, both less than i, which indicate that the outputs from View
mubarik 0.01 1.6M C
both a and b are used as the two input to gate i.
As stated before, the circuit will be such that no gate has both of its inputs depending on the value of a smithinsu 0.01 1.6M C View
common input node.
Test cases are separated by a blank line including a blank line preceding the first test case. mist_rock 0.01 1.6M C View
Output
shasank 0.01 1.6M C View
For each test case you are to output a single line containing the value p for which the output of node n is
1 with probability exactly 1/2 if the inputs are independently and randomly set to value 1 with probability p. View
supriyapathuri 0.01 1.6M C
The value p should be printed with exactly 5 digits after the decimal.
Example
1 of 7
Input:
1 HELP
0
3
0
0
112
3
0
0
212
5
0
0
0
212
134
Output:
0.50000
0.29289
0.70711
0.40303
Author: friggstad
Tester: pieguy
converted by W eb2PDFConvert.com
Editorial http://discuss.codechef.com/problems/CIRCUITS
Date Added: 7-06-2010 Program should read from standard input and write to
standard output. After you submit a solution you can see
Time Limit: 2 sec
your results by clicking on the [My Submissions] tab on
Source the problem page. Below are the possible results:
50000 Bytes
Limit:
ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 4.8.1, CPP11, Accepted Your program ran successfully and
gave a correct answer. If there is a score for the
Languages: CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, problem, this will be displayed in parenthesis next to
NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH
3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC the checkmark.
Please login at the top to post a comment. Wrong Answer Your program compiled and ran
succesfully but the output did not match the expected
sericacorp @ 13 Apr 2014 04:54 AM output.
Did any body understood the problem?? i read it like 5 times. Still unclear on what is begin said. Runtime Error Your code compiled and ran but
encountered an error. The most common reasons are
using too much memory or dividing by zero. For the
atrib @ 4 May 2014 08:11 PM specific error codes see the help section.
@sericacorp The input represents a boolean expression. Each input is 1(with probability p) or 0(with Compilation Error Your code was unable to
probability 1-p). For this, the probability for getting an output of 1(output node is probably the last compile. When you see this icon, click on it for more
node) is a function of p. For what value of p does this function become 1/2. information.
@friggstad, working in C, the chances of finding a float value of 'p correct to 5 decimal places, such
that the output prob is 1/2 is irrational. Can't you accept answers with an error of 0.00001 or
0.00002? Its a tradeoff between accuracy and time as we set exit conditions in our code. Please look
into the matter
converted by W eb2PDFConvert.com
Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC
competition here.
converted by W eb2PDFConvert.com