Work Conversion
2015-05-27 12:05 kingshow 阅读(328) 评论(0) 编辑 收藏 举报
Most work in a factory is performed by robots. In the robots’ work, the most time used is when converting an operation.
For the above case,
For each test case, you should round off the mean frequency of work conversion at three decimal places moving from a certain work to another at the first row and generate the values.
Input
1.833 Case #2 |
代码:
#include <iostream> #include <stdio.h> #include <queue> #include <iomanip> #define MAX 9999 int map[501][501]; int dis[501]; int sum[501]; int InitArray(); using namespace std; int main() { //freopen("test.txt","r",stdin); int T; cin>>T; for(int t=1; t<=T; t++) { int n; int s,e; int maxPoint = 0; int temp = 0; int num; float countSteps = 0; float countPairs = 0; float result = 0; queue<int> qt; InitArray(); cin>>n; for(int i=0; i<n; i++) { cin>>s>>e; map[s][e] = 1; if(s >= maxPoint) { maxPoint = s; } else if(e >= maxPoint) { maxPoint = e; } } for(int k=1; k<=maxPoint; k++) { for(int i=1; i<=maxPoint; i++) { dis[i] = MAX; } dis[k] = 0; qt.push(k); while(!qt.empty()) { num = qt.front(); qt.pop(); for(int h=1; h<=maxPoint; h++) { temp = dis[num] + map[num][h]; if(temp < dis[h]) { dis[h] = temp; qt.push(h); } } } for(int i=1; i<=maxPoint; i++) { if(dis[i]>0 && dis[i]< MAX) { countPairs++; sum[k] += dis[i]; } } } for(int j=1; j<=maxPoint; j++) { countSteps += sum[j]; } result = countSteps/countPairs; cout<<"Case #"<<t<<endl; //cout<<result<<endl; //cout<<fixed<<setprecision(3)<<result<<endl; printf("%.3f\n",result); } //cout << "Hello world!" << endl; return 0; } int InitArray() { for(int i=1; i<501; i++) { dis[i] = MAX; sum[i] = 0; for(int j=1; j<501; j++) { if(i == j) { map[i][j] = 0; } else { map[i][j] = MAX; } } } return 0; }