UVALive
2016-09-05 19:46
405 查看
#pragma warning(disable:4996) #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<vector> #include<algorithm> #include<iostream> #include<time.h> using namespace std; const double INF = 0x3f3f3f3f; double a[1005]; double b[1005]; int vs_main() { int n, m; while (cin >> n >> m) { int k1 = 1; memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); double temp1 = 10000.0 / n; while ((k1-1)*temp1 <= 10000 - 0.5) { a[k1++] = (k1 - 1)*temp1; } double temp2 = 10000.0 / (n + m); int k2 = 1; while ((k2 - 1)*temp2 <= 10000 - 0.5) { b[k2++] = (k2 - 1)*temp2; } double sum = 0; for (int i = 1; i <= k1; i++) { double Min = INF; for (int j = 1; j <= k2; j++) { Min = min(Min, fabs(a[i] - b[j])); } sum += Min; } printf("%.4f\n", sum); } return 0; }
#pragma warning(disable:4996) #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<vector> #include<algorithm> #include<iostream> #include<time.h> using namespace std; const double INF = 0x3f3f3f3f; double a[1005]; double b[1005]; int vs_main() { int n, m; while (cin >> n >> m) { memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); double ans = 0.0; for (int i = 1; i < n; i++) { double pos = (double)i / n*(n + m); ans += fabs(pos - floor(pos + 0.5)) / (n + m); } printf("%.4lf\n", ans * 10000); } return 0; }
相关文章推荐
- UVALive 4244 Party Party Party(HDU 2779 && Sicily 1663)
- UVALive 6741 The Sacrificial Firepits
- UVALive 5870 - Smooth Visualization
- UVALive 5876 - Writings on the Wall 【KMP】
- UVALive 5878 - Shortest Leash 【计算几何】
- UVALive 5873 - Tree Inspections 【模拟】
- uvalive3938 “Ray, Pass me the dishes!”
- UVALive 6800 The Mountain of Gold (bellman_ford判负环)
- UVALive 6436 The Busiest City
- F - Buggy Sat
- E - Lazy Math Instructor
- C - Push!!
- UVALive - 3635 - Pie(二分)
- Uvalive 6855 Banks
- Uvalive 7150 Amalgamated Artichokes
- Uvalive 4954 Lawn mower
- Uvalive 6832 Bit String Reordering
- Uvalive 6398 Low Power
- Uvalive 6929 Sums
- uvalive 6859