fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <cassert>
  4. #include <climits>
  5. #include <cstdlib>
  6. #include <cstring>
  7. #include <iomanip>
  8. #include <numeric>
  9. #include <cstdio>
  10. #include <string>
  11. #include <vector>
  12. #include <cmath>
  13. #include <ctime>
  14. #include <queue>
  15. #include <stack>
  16. #include <map>
  17. #include <set>
  18.  
  19. using namespace std;
  20.  
  21. #define F first
  22. #define S second
  23.  
  24. #define endl '\n'
  25.  
  26. #define mp make_pair
  27. #define pb push_back
  28.  
  29. #define FOR(i, a, b) for(int i = a; i <= b; i++)
  30. #define ROF(i, a, b) for(int i = a; i >= b; i--)
  31.  
  32. #define type(x) __typeof((x).begin())
  33. #define foreach(i, x) for(type(x) i = (x).begin(); i != (x).end(); i++)
  34.  
  35. #define sol (root + root)
  36. #define sag (root + root + 1)
  37. #define orta ((bas + son) >> 1)
  38.  
  39. #define bit __builtin_popcount
  40.  
  41. #ifndef D
  42. #define dbg(x) 0
  43. #define dbgs(x) 0
  44. #else
  45. #define dbg(x) cerr << (#x) << " --> " << (x) << endl
  46. #define dbgs(x) cerr << (#x) << " --> " << (x) << ' '
  47. #endif
  48.  
  49. typedef long long ll;
  50. typedef pair < int, int > pii;
  51.  
  52. const int inf = 1e9 + 5;
  53. const ll linf = 1e18 + 5;
  54.  
  55. const int N = 1000 + 5;
  56. const int K = 100000;
  57. const double PI = acos(-1);
  58.  
  59. int n;
  60. pair < pair < double, double >, int > a[N];
  61.  
  62. int main () {
  63.  
  64. ios :: sync_with_stdio(0);
  65.  
  66. cin >> n;
  67.  
  68. int all = 0;
  69.  
  70. FOR(i, 1, n) {
  71. cin >> a[i].F.F >> a[i].F.S >> a[i].S;
  72. all += a[i].S;
  73. }
  74.  
  75. int ans = inf;
  76.  
  77. double x, y, c = cos(PI / K), s = sin(PI / K);
  78.  
  79. FOR(i, 1, K) {
  80. bool flag = 1;
  81. while(flag) {
  82. flag = 0;
  83. FOR(i, 1, n - 1)
  84. if(a[i].F.F > a[i + 1].F.F + (1e-6)) {
  85. flag = 1;
  86. swap(a[i], a[i + 1]);
  87. }
  88. }
  89. int sum = 0;
  90. FOR(i, 1, n) {
  91. sum += a[i].S;
  92. ans = min(ans, abs(all - sum - sum));
  93. x = a[i].F.F;
  94. y = a[i].F.S;
  95. a[i].F.F = x * c - y * s;
  96. a[i].F.S = x * s + y * c;
  97. }
  98. }
  99.  
  100. cout << ans << endl;
  101.  
  102. return 0;
  103.  
  104. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
1000000005