0% found this document useful (0 votes)
99 views

Randomly Testing Circuits

codechef challenge question

Uploaded by

fullmetal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views

Randomly Testing Circuits

codechef challenge question

Uploaded by

fullmetal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Login Signup Login or

Signup with
Have you tried CodeChefs "Code, Compile & Run" Its pretty cool. Try it out by pressing Ctrl+; and
typing "ide" [X]

PRACTICE COMPETE DISCUSS COMMUNITY HELP ABOUT

Home Practice(easy) Randomly Testing Circuits

Randomly Testing Circuits


ALL SUBMISSIONS SUBMIT
Problem code: CIRCUITS
Like Share 9 people like this. Sign Up to see what your
friends like.

All submissions for this problem are available. SUCCESSFUL SUBMISSIONS


AND gates and OR gates are basic components used in building digital circuits. Both gates have two
input lines and one output line. The output of an AND gate is 1 if both inputs are 1, otherwise the output User Time Mem Lang Solution
is 0. The output of an OR gate is 1 if at least one input is 1, otherwise the output is 0.
mayanknsit 0.00 1.6M C View
You are given a digital circuit composed of only AND and OR gates where one node (gate or input) is
specially designated as the output. Furthermore, for any gate G and any input node I, at most one of the
inputs to G depends on the value of node I. chopra22 0.00 1.6M C View
Now consider the following random experiment. Fix some probability p in [0,1] and set each input bit to 1
independently at random with probability p (and to 0 with probability 1-p). The output is then 1 with some karlheinz_jung 0.00 1.6M C View
probability that depends on p. You wonder what value of p causes the circuit to output a 1 with probability
1/2. boopathi 0.00 2.6M C++ 4.3.2 View

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.

Time Limit Exceeded Your program was


compiled successfully, but it didn't stop before time
Comments limit. Try optimizing your approach.

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.

If you are still having problems, see a sample solution


atrib @ 4 May 2014 11:54 PM here.

@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

abhisixthgear @ 4 Nov 2014 06:38 PM

can anyone make me understand this problem?

anuranju @ 20 Nov 2014 02:41 PM

can anyone help me to understand this question ?

CodeChef is a non-commercial competitive programming community


About CodeChef About Directi CEO's Corner C-Programming Programming Languages Contact Us
2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ by Sphere Research Labs The time now is: 01:20:39 PM
In order to report copyright violations of any kind, send in an email to [email protected] Your Ip: 50.97.53.244

CodeChef - A Platform for Aspiring Programmers


CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to
revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have
training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions,
CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.
Practice Section - A Place to hone your 'Computer Programming Skills'
Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+
programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better
prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.
Compete - Monthly Programming Contests and Cook-offs
Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself
up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.
Discuss
Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other
programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the
CodeChef Forums and Wiki section.
CodeChef Community
As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not
the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.
Go For Gold
The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the
ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the

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

You might also like