Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
数据确实弱,给个处理精度問題的模板其实一句話總结就是:如果有非整数出现,一定是.5(可以分奇偶性证明之) #include <iostream> #include <stdio.h> using namespace std; int n; double dist[33][33]; const double THRES = 1000000.0; int main() { while(1){ scanf("%d", &n); if(!n) return 0; for(int i = 1; i <= n; i++){ dist[i][i] = 0; for(int j = i+1; j <= n; j++){ int temp; scanf("%d", &temp); dist[i][j] = (double) temp; dist[j][i] = dist[i][j]; } } double size = 0; bool valid[40]; for(int i = 1; i <= n; i++) valid[i] = 1; for(int i = 1; i <= n-1; i++){ for(int a = 1; a <= n; a++){ if(!valid[a]) continue; for(int b = 1; b <= n; b++){ if(!valid[b] || b==a) continue; double Dist = THRES; bool ky = 1; for(int c = 1; c <= n; c++){ if(!valid[c] || c==a || c==b) continue; double tempDist = dist[a][c] - dist[b][c]; if(Dist != THRES && tempDist != Dist){ ky = 0; break; } Dist = tempDist; } if(ky){ valid[b] = 0; size += dist[a][b]; if(Dist != THRES){ double dt = (Dist + dist[a][b])/2; for(int q = 1; q <= n; q++){ if(!valid[q] || q==a) continue; dist[q][a] -= dt; dist[a][q] -= dt; } } goto onePhase; } } } onePhase: continue; } int size_ = (int)size; if(size-size_<0.4) printf("%d\n", size_); else printf("%d.5\n", size_); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator