codechef Magic Rankings 搞死我的小水题

来源:互联网 发布:sql insert 编辑:程序博客网 时间:2024/04/28 21:31

Magic Rankings

Problem code: MGCRNK

  • Submit
  • My Submissions
  • All Submissions

Everybody loves magic, especially magicians who compete for glory on the Byteland Magic Tournament. Magician Cyael is one such magician.

Cyael has been having some issues with her last performances and today she’ll have to perform for an audience of some judges, who will change her tournament ranking, possibly increasing it. As she is a great magician she managed to gather a description of the fixed judges’ disposition on the room (which is represented as an N ×N square matrix), such that she knows in advance the fixed points each judge will provide. She also knows that the room is divided into several parallel corridors, such that we will denote thej-th cell on corridor i, as [i][j]. Note that some judges can award Cyael, zero points or negative points, as they are never pleased with her performance.

There is just one judge at each cell of the matrix, except the cells [1][1] and[N][N].

To complete her evaluation, she must start on the top leftmost corner of the room (cell[1][1]), and finish on the bottom right corner (cell [N][N]), moving either to the cell directly in front of her on the same corridor (that is, moving from cell[r][c] to cell [r][c+1], where c+1N) or to the cell in the next corridor directly in front of where she is (that is, moving from cell[r][c] to cell [r+1][c], where r+1N). She will keep doing this until she reaches the end point of the room, i.e. last cell[N][N] on the last corridor. Cyael will be judged at all visited cells with a judge.

Cyael wants to maximize her average score at end of her performance. More specifically, if she passesK judges, each being on cell [i1][j1], cell[i2][j2], ..., cell [iK][jK] respectively, then she wants to maximize (S[i1][j1] +S[i2][j2] + ... + S[iK][jK]) /K, where S[i][j] denotes the points that the judge will give her on the cell[i][j].

Help her determine the best path she has to follow in order to maximize her average points.

Input

The first line contains a single integer T denoting the number of test cases. The description forT test cases follows. For each test case, the first line contains a single integerN. Each of the next N lines contains N space-separated integers.
The j-th integer S[i][j] in i-th line denotes the points awarded by the judge at cell[i][j].
Note that the cells [1][1] and [N][N] have no judges, soS[1][1] and S[N][N] will be 0.

Output

For each test case, if the maximum possible average points Cyael can obtain is negative, output a single line containing "Bad Judges" (quotes for clarity). Otherwise, output the maximum possible average points. The answer will be considered correct if it has an absolute error no more than 10-6.

Constraints

1 ≤ T ≤ 20
2 ≤ N ≤ 100
-2500 ≤ S[i][j] ≤ 2500
S[1][1] = S[N][N] = 0

Your code will be judged against several input files.

Example

Input:220 -48 020 -45-3  0
Output:8.000000Bad Judges

http://www.codechef.com/DEC12/problems/MGCRNK/


题意:

输入cas  输入n  输入n*n的矩阵   矩阵为整数

问从0  0  到n-1 n-1   所走过的路程中的数和  除以2*n-3  是多少  如果小于0输出

Bad Judges
否则输出结果保留6位小数


思路:  一开始用优先队列 发现不行  通过打表发现  对于有正负数均存在的情况下  不管求最大值还是求最小值都不能一次得到结果 即不能走到终点就结束 要把所有路径走完 这样也超时了

所以对于正负数均存在的情况下  不要用优先队列去求  只有当全为正或全为负的时候再用

对于本题   可以先求出第一行 和第一列的和   然后对于中间的   用本身加上其上或其左较大的那个

一开始错了无数变   发现原来没看到让球的是平均数

气死了 以后要紧抓英语了

#include<stdio.h>#include<string.h>int n;int mmax(int a,int b){if(a>b) return a;return b;}int map[105][105];int main(){int i,j,cas;scanf("%d",&cas);while(cas--){scanf("%d",&n);for(i=0;i<n;i++)for(j=0;j<n;j++)scanf("%d",&map[i][j]);for(i=1;i<n;i++)map[0][i]=map[0][i]+map[0][i-1];for(i=1;i<n;i++)map[i][0]=map[i][0]+map[i-1][0];for(i=1;i<n;i++){              for(j=1;j<n;j++)  {  map[i][j]=map[i][j]+mmax(map[i-1][j],map[i][j-1]);  }}if(map[n-1][n-1]<0) printf("Bad Judges\n");else printf("%.6lf\n",(double)map[n-1][n-1]/(2.0*n-3.0));}return 0;}






原创粉丝点击