Atcoder evaluation machine does not ONLINE_JUDGE this macro! !
A, B giant water title
C - Walk on Multiplication Table
Description
To a number mul, seeking to meet the $ x * y = mul \ && min \ {x + y-2 \} $
$ Mul \ leq 10 ^ {12} $
Solution
By the mean inequality seen $ x + y \ geq 2 * \ sqrt {xy} $, given xy, then $ min \ {x + y-2 \} $ must appear in the $ \ sqrt {xy} $ near, sweep over to
1 #include <algorithm> 2 #include <bits/stdc++.h> 3 #include <cctype> 4 #include <cmath> 5 #include <cstdio> 6 #include <cstdlib> 7 #include <cstring> 8 #include <ctime> 9 #include <iostream> 10 #include <map> 11 #include <numeric> 12 #include <queue> 13 #include <set> 14 #include <stack> 15 #if __cplusplus >= 201103L 16 #include <unordered_map> 17 #include <unordered_set> 18 #endif 19 #include <vector> 20 #define lson rt << 1, l, mid 21 #define rson rt << 1 | 1, mid + 1, r 22 #define LONG_LONG_MAX 9223372036854775807LL 23 #define pblank putchar(' ') 24 #define ll LL 25 #define fastIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) 26 using namespace std; 27 typedef long long ll; 28 typedef long double ld; 29 typedef unsigned long long ull; 30 typedef pair<int, int> P; 31 ll n, m, k; 32 const int maxn = 1e7 + 10; 33 template <class T> 34 inline T read() 35 { 36 int f = 1; 37 T ret = 0; 38 char ch = getchar(); 39 while (!isdigit(ch)) 40 { 41 if (ch == '-') 42 f = -1; 43 ch = getchar(); 44 } 45 while (isdigit(ch)) 46 { 47 ret = (ret << 1) + (ret << 3) + ch - '0'; 48 ch = getchar(); 49 } 50 ret *= f; 51 return ret; 52 } 53 template <class T> 54 inline void write(T n) 55 { 56 if (n < 0) 57 { 58 putchar('-'); 59 n = -n; 60 } 61 if (n >= 10) 62 { 63 write(n / 10); 64 } 65 putchar(n % 10 + '0'); 66 } 67 template <class T> 68 inline void writeln(const T &n) 69 { 70 write(n); 71 puts(""); 72 } 73 int main(int argc, char const *argv[]) 74 { 75 #ifndef ONLINE_JUDGE 76 // freopen("in.txt", "r", stdin); 77 // freopen("out.txt", "w", stdout); 78 #endif 79 n = read<ll>(); 80 ll up = (ll)sqrt(n * 1.0); 81 ll res = n - 1; 82 for (ll i = up; i >= 1; i--) 83 if (n % i == 0) 84 { 85 res = i + n / i - 2; 86 break; 87 } 88 writeln(res); 89 return 0; 90 }
D - Water
Description
To the bottom of a square side length a, b of the cap-height bottle and x per unit volume of water, and asked how much the maximum inclination angle may be just the water does not overflow.
Solution
Track down wisdom. Just think of the first case, the test samples have been endless mentality collapse.
Posted a nb users do chart.
The two cases discussed on the line, attention is converted to an angle value.
1 #include <algorithm> 2 #include <cctype> 3 #include <cmath> 4 #include <cstdio> 5 #include <cstdlib> 6 #include <cstring> 7 #include <iomanip> 8 #include <iostream> 9 #include <map> 10 #include <numeric> 11 #include <queue> 12 #include <set> 13 #include <stack> 14 #if __cplusplus >= 201103L 15 #include <unordered_map> 16 #include <unordered_set> #endif17 18 #include <vector> 19 #define lson rt << 1, l, mid 20 #define rson rt << 1 | 1, mid + 1, r 21 #define LONG_LONG_MAX 9223372036854775807LL 22 #define pblank putchar(' ') 23 #define ll LL 24 #define fastIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) 25 using namespace std; 26 typedef long long ll; 27 typedef long double ld; 28 typedef unsigned long long ull; 29 typedef pair<int, int> P; 30 int n, m, k; 31 const int maxn = 1e5 + 10; 32 template <class T> 33 inline T read() 34 { 35 int f = 1; 36 T ret = 0; 37 char ch = getchar(); 38 while (!isdigit(ch)) 39 { 40 if (ch == '-') 41 f = -1; 42 ch = getchar(); 43 } 44 while (isdigit(ch)) 45 { 46 ret = (ret << 1) + (ret << 3) + ch - '0'; 47 ch = getchar(); 48 } 49 ret *= f; 50 return ret; 51 } 52 template <class T> 53 inline void write(T n) 54 { 55 if (n < 0) 56 { 57 putchar('-'); 58 n = -n; 59 } 60 if (n >= 10) 61 { 62 write(n / 10); 63 } 64 putchar(n % 10 + '0'); 65 } 66 template <class T> 67 inline void writeln(const T &n) 68 { 69 write(n); 70 puts(""); 71 } 72 const ld PI = acos(-1); 73 ld solve(int a, int b, int x) 74 { 75 if (2.0 * x >= a * a * b) 76 return (ld)atan((2 * a * a * b * 1.0 - 2 * x) / (a * a * a * 1.0)); 77 return PI / 2 - atan(2 * x * 1.0 / (a * b * b)); 78 } 79 int main(int argc, char const *argv[]) 80 { 81 #ifndef ONLINE_JUDGE 82 // freopen("in.txt", "r", stdin); 83 // freopen("out.txt", "w", stdout); 84 #endif 85 86 int a, b, x; 87 cin >> a >> b >> x; 88 cout << fixed << setprecision(7) << solve(a, b, x) * 180.0 / PI; 89 return 0; 90 }
E - Gluttony
Description
Given two sequences of length n, A, F, and on a boundary operand k (the number of operations may not run out), each operation can be made in sequence according to any one of A is decreased by one.
After the operation, the A, F element paired off, seeking minimum product pairing.
Solution
Recent always run into this problem.
The minimum product requirements, we certainly have to pair the minimum A and maximum F.
The answer to the minimum product, if we can get the answer is x, then we can get an answer greater than x (reducing the number of switching operation or pairing)
That decision is monotonic.
Then it is clear that you can carry out his half.
The number of times each pair by subtracting the product is greater than the minimum when the answer to check, and finally determines whether the number is less than equal to k
1 #include <algorithm> 2 #include <cctype> 3 #include <cmath> 4 #include <cstdio> 5 #include <cstdlib> 6 #include <cstring> 7 #include <iostream> 8 #include <map> 9 #include <numeric> 10 #include <queue> 11 #include <set> 12 #include <stack> 13 #if __cplusplus >= 201103L 14 #include <unordered_map> 15 #include <unordered_set> 17#endif16 #include <vector> 18 #define lson rt << 1, l, mid 19 #define rson rt << 1 | 1, mid + 1, r 20 #define LONG_LONG_MAX 9223372036854775807LL 21 #define pblank putchar(' ') 22 #define ll LL 23 #define fastIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) 24 using namespace std; 25 typedef long long ll; 26 typedef long double ld; 27 typedef unsigned long long ull; 28 typedef pair<int, int> P; 29 int n, m; 30 ll k; 31 const int maxn = 2e5 + 10; 32 template <class T> 33 inline T read() 34 { 35 int f = 1; 36 T ret = 0; 37 char ch = getchar(); 38 while (!isdigit(ch)) 39 { 40 if (ch == '-') 41 f = -1; 42 ch = getchar(); 43 } 44 while (isdigit(ch)) 45 { 46 ret = (ret << 1) + (ret << 3) + ch - '0'; 47 ch = getchar(); 48 } 49 ret *= f; 50 return ret; 51 } 52 template <class T> 53 inline void write(T n) 54 { 55 if (n < 0) 56 { 57 putchar('-'); 58 n = -n; 59 } 60 if (n >= 10) 61 { 62 write(n / 10); 63 } 64 putchar(n % 10 + '0'); 65 } 66 template <class T> 67 inline void writeln(const T &n) 68 { 69 write(n); 70 puts(""); 71 } 72 ll a[maxn], f[maxn]; 73 inline int judge(ll x) 74 { 75 ll cnt = 0; 76 for (int i = 1; i <= n; i++) 77 if (a[i] * f[n - i + 1] > x) 78 { 79 ll tmp = a[i] * f[n - i + 1] - x; 80 cnt += tmp / f[n - i + 1]; 81 if (tmp % f[n - i + 1]) 82 ++cnt; 83 } 84 return cnt <= k; 85 } 86 int main(int argc, char const *argv[]) 87 { 88 #ifndef ONLINE_JUDGE 89 // freopen("in.txt", "r", stdin); 90 // freopen("out.txt", "w", stdout); 91 #endif 92 n = read<int>(); 93 k = read<ll>(); 94 for (int i = 1; i <= n; i++) 95 a[i] = read<ll>(); 96 for (int i = 1; i <= n; i++) 97 f[i] = read<ll>(); 98 sort(a + 1, a + 1 + n); 99 sort(f + 1, f + 1 + n); 100 ll l = 0, r = 1e12 + 1; 101 ll res = 0; 102 while (l <= r) 103 { 104 ll mid = l + r >> 1; 105 if (judge(mid)) 106 { 107 res = mid; 108 r = mid - 1; 109 } 110 else 111 l = mid + 1; 112 } 113 writeln(res); 114 return 0; 115 }