例题1:
LOOPS
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 12305 Accepted Submission(s): 4671
Homura wants to help her friend Madoka save the world. But because of the plot of the Boss Incubator, she is trapped in a labyrinth called LOOPS.

The planform of the LOOPS is a rectangle of R*C grids. There is a portal in each grid except the exit grid. It costs Homura 2 magic power to use a portal once. The portal in a grid G(r, c) will send Homura to the grid below G (grid(r+1, c)), the grid on the right of G (grid(r, c+1)), or even G itself at respective probability (How evil the Boss Incubator is)!
At the beginning Homura is in the top left corner of the LOOPS ((1, 1)), and the exit of the labyrinth is in the bottom right corner ((R, C)). Given the probability of transmissions of each portal, your task is help poor Homura calculate the EXPECT magic power she need to escape from the LOOPS.
The following R lines, each contains C*3 real numbers, at 2 decimal places. Every three numbers make a group. The first, second and third number of the cth group of line r represent the probability of transportation to grid (r, c), grid (r, c+1), grid (r+1, c) of the portal in grid (r, c) respectively. Two groups of numbers are separated by 4 spaces.
It is ensured that the sum of three numbers in each group is 1, and the second numbers of the rightmost groups are 0 (as there are no grids on the right of them) while the third numbers of the downmost groups are 0 (as there are no grids below them).
You may ignore the last three numbers of the input data. They are printed just for looking neat.
The answer is ensured no greater than 1000000.
Terminal at EOF
int n,m;
const int MAX=1010;
double p[MAX][MAX][4];//p是在ij位置选择三种不同走法的概率
double dp[MAX][MAX];
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
for(int k=1;k<=3;k++){
cin>>p[i][j][k];
}
}
}
dp[n][m]=0;
for(int i=n;i>=1;i--){
for(int j=m;j>=1;j--){
if((i==n&&j==m)||p[i][j][1]==1) continue;
dp[i][j]=(p[i][j][2]*dp[i][j+1]+p[i][j][3]*dp[i+1][j]+2)/(1-p[i][j][1]);
}
}
printf("%.3f\n",dp[1][1]);
}
例题2:
Aeroplane chess
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7792 Accepted Submission(s): 4870
There are also M flight lines on the chess map. The i-th flight line can help Hzz fly from grid Xi to Yi (0<Xi<Yi<=N) without throwing the dice. If there is another flight line from Yi, Hzz can take the flight line continuously. It is granted that there is no two or more flight lines start from the same grid.
Please help Hzz calculate the expected dice throwing times to finish the game.
Each test case contains several lines.
The first line contains two integers N(1≤N≤100000) and M(0≤M≤1000).
Then M lines follow, each line contains two integers Xi,Yi(1≤Xi<Yi≤N).
The input end with N=0, M=0.
int n,m;
const int MAX=100010;
double dp[MAX];
int fly[MAX];
int main(){
while (~scanf("%d %d",&n,&m)&&(n||m)) {
for(int i=0;i<=n;i++){
fly[i]=-1;
dp[i]=0;
}
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
fly[a]=b;
}
//状态转移方程优先选择直接飞过去 然后再选择走
//所以dp i=dp fly I
//然后走的话是1/6的几率 注意最后要进行dp++
for(int i=n-1;i>=0;i--){
if(fly[i]!=-1)
dp[i]=dp[fly[i]];
else {
for(int j=1;j<=6;j++){
if(i+j>=n)
dp[i]+=1.0/6*dp[n];
else {
dp[i]+=1.0/6*dp[i+j];
}
}
dp[i]++;
}
}
printf("%.4f\n",dp[0]);
}
}
例题3:
Collecting Bugs
| Time Limit: 10000MS | Memory Limit: 64000K | |
| Total Submissions: 12436 | Accepted: 5572 | |
| Case Time Limit: 2000MS | Special Judge |
Description
Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material stuff, he collects software bugs. When Ivan gets a new program, he classifies all possible bugs into n categories. Each day he discovers exactly one bug in the program and adds information about it and its category into a spreadsheet. When he finds bugs in all bug categories, he calls the program disgusting, publishes this spreadsheet on his home page, and forgets completely about the program.
Two companies, Macrosoft and Microhard are in tight competition. Microhard wants to decrease sales of one Macrosoft program. They hire Ivan to prove that the program in question is disgusting. However, Ivan has a complicated problem. This new program has s subcomponents, and finding bugs of all types in each subcomponent would take too long before the target could be reached. So Ivan and Microhard agreed to use a simpler criteria --- Ivan should find at least one bug in each subsystem and at least one bug of each category.
Macrosoft knows about these plans and it wants to estimate the time that is required for Ivan to call its program disgusting. It's important because the company releases a new version soon, so it can correct its plans and release it quicker. Nobody would be interested in Ivan's opinion about the reliability of the obsolete version.
A bug found in the program can be of any category with equal probability. Similarly, the bug can be found in any given subsystem with equal probability. Any particular bug cannot belong to two different categories or happen simultaneously in two different subsystems. The number of bugs in the program is almost infinite, so the probability of finding a new bug of some category in some subsystem does not reduce after finding any number of bugs of that category in that subsystem.
Find an average time (in days of Ivan's work) required to name the program disgusting.
Input
Input file contains two integer numbers, n and s (0 < n, s <= 1 000).
Output
Output the expectation of the Ivan's working days needed to call the program disgusting, accurate to 4 digits after the decimal point.
Sample Input
1 2
Sample Output
3.0000
Source
Northeastern Europe 2004, Northern Subregion
const int MAXN = 1005;
double dp[MAXN][MAXN];
int main()
{
int n, s;
while(~scanf("%d%d", &n, &s))
{
double p1, p2, p3, p4;
memset(dp, 0, sizeof(dp));
for(int i=n; i>=0; --i)
for(int j=s; j>=0; --j)
{
if(i==n && j==s)continue;
p1=1.0*(n-i)*(s-j)/(n*s);
p2=1.0*(n-i)*j/(n*s);
p3=1.0*i*(s-j)/(n*s);
p4=1.0*i*j/(n*s);
dp[i][j]=(p1*dp[i+1][j+1]+p2*dp[i+1][j]+p3*dp[i][j+1]+1)/(1-p4);
}
printf("%.4f\n", dp[0][0]);
}
return 0;
}
3275



被折叠的 条评论
为什么被折叠?



