Dinner Party SocializingProblem code: SOCIAL |
All submissions for this problem are available.
The chef is having a dinner party. He has N chairs and has invited N guests. The chef knows that if the guests are left to their own devices, they tend to sit in the same chairs and socialize with the same people all night. To prevent this, the chef has developed a plan to help people socialize. He will assign each chair a follow-up chair. At predetermined intervals during the party, the chef will ring a bell, instructing all guests to move from their current chair to its follow-up chair.
The chef will assign follow-up chairs randomly, with the restriction that no chair will be its own follow-up chair, and no two chairs will have the same follow-up chair. That is, the chef randomly chooses one arrangement out of all assignments satisfying the two conditions. The chef wonders, after a certain number of ringings of the bell, what the expected number of guests who will be back in their original chairs will be.
Input
Input will begin with an integer T, the number of test cases. Each test case consists of a single line with 2 integers N and R, the number of chairs and number of ringings, respectively.
Output
For each test case, output on a single line the expected number of guests who will be back in their original seats after exactly R ringings, rounded to 5 decimal places.
Sample Input
4 2 1 2 2 4 2 5 3
Sample Output
0.00000 2.00000 1.33333 1.36364
Constraints
T?3002?N?50
1?R?1000000
| Author: | pieguy |
| Date Added: | 10-11-2010 |
| Time Limit: | 1 sec |
| Source Limit: | 50000 Bytes |
| Languages: | ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC |
Comments
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
HELP
Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:
- Accepted
Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark. - Time Limit Exceeded
Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach. - Wrong Answer
Your program compiled and ran succesfully but the output did not match the expected output. - 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 specific error codes see the help section. - Compilation Error
Your code was unable to compile. When you see this icon, click on it for more information.
If you are still having problems, see a sample solution here.

Fetching successful submissions

The programs gets Runtime
The programs gets Runtime Error with really simple solution.
When I am using StreamTokenizer it seems to read n > 50: http://www.codechef.com/viewsolution/384780
When I am using Scanner it crashes when I just read input data (without any assertion or processing code): http://www.codechef.com/viewsolution/384782
Confirmed in C++, there's
Confirmed in C++, there's definitely something wrong with this problem: http://www.codechef.com/viewsolution/384826
Looks like the number of test cases was wrong, and it was just a lucky side effect of C++ that means anyone got accepted at all.