zoukankan      html  css  js  c++  java
  • AtCoder Beginner Contest 144 CDE题解

    Atcoder评测机没有ONLINE_JUDGE这个宏!!

    A,B巨水题

    C - Walk on Multiplication Table

    Description

    给一个数mul,求满足$x*y=mul   && min{x+y-2}$

    $mul leq 10^{12}$

    Solution

    由均值不等式可知$x+y geq 2*sqrt{xy}$,给定xy,那么$min{x+y-2}$一定出现在$sqrt{xy}$附近,扫一遍即可

     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 }
    View Code

    D - Water

    Description

    给一个底部为正方形边长为a,高为b的无盖水瓶,以及x单位体积的水,问最大倾斜多少角度可以使水刚好不溢出。

    Solution

    赛场降智。只想到第一种情况,测试样例都过不完心态崩了。

    贴一张nb网友做的图。

    分两种情况讨论就行了,注意转换为角度值。

     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>
    17 #endif
    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 }
    View Code

    E - Gluttony

    Description

    给出两个长为n的序列A,F以及一个操作数上界k(可以不将操作次数用完),每次操作可以使A序列里的任一个值减一。

    操作结束后,将A,F元素两两配对,求配对的最小乘积。

    Solution

    最近总是碰见这种题。

    要求最小乘积,我们肯定得把最小的A和最大的F配对。

    对于答案最小乘积而言,如果我们可以得到答案为x,那么一定可以得到一个大于x的答案(减少操作数或者将配对情况交换)

    也就是说决策具有单调性。

    那么就很显然可以二分来搞。

    每次check时将配对乘积大于答案的减去最小的次数,判断最后次数是否小于等于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>
     16 #endif
     17 #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 }
    View Code
  • 相关阅读:
    MyBatis嵌套查询column传多个参数描述
    RabbitMQ入门Demo
    使用Nginx配置资源虚拟路径
    RabbitMQ在windows环境下的安装
    Nginx的一些基本功能
    Maven的setting配置文件
    Dubbo与Zookeeper
    swap是干嘛的?
    HttpMessageConverter那回事
    java 深拷贝与浅拷贝机制详解
  • 原文地址:https://www.cnblogs.com/mooleetzi/p/11750090.html
Copyright © 2011-2022 走看看