zoukankan      html  css  js  c++  java
  • Codeforces Round #499 (Div. 2)

    C. Fly

    题解:二分答案,然后模拟验证。

    //#include<bits/stdc++.h>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<bitset>
    #include<vector>
    #include<queue>
    #include<set>
    #define ll long long
    #define P pair<int, int>
    #define PP pair<int,pair<int, int>>
    #define pb push_back
    #define pp pop_back
    #define lson root << 1
    #define INF (int)2e9 + 7
    #define rson root << 1 | 1
    #define LINF (unsigned long long int)1e18
    #define mem(arry, in) memset(arry, in, sizeof(arry))
    using namespace std;
    
    const int N = 1e5 + 5;
    
    int n, m;
    int a[1005], b[1005];
    
    bool check(double mid) {
        double x = m * 1.0 + mid;
        if(mid * a[1] * 1.0 < x) return false;
        for(int i = 1; i <= n; i++) {
            x -= x / (1.0 * a[i]);
            if(x < 1.0 * m) return false;
            x -= x / (1.0 * (i == n ? b[1] : b[i + 1]));
            if(x < 1.0 * m) return false;
        }
        return true;
    }
    
    int main()
    {
        cin >> n >> m;
        for(int i = 1; i <= n; i++) cin >> a[i];
        for(int i = 1; i <= n; i++) cin >> b[i];
    
        double l = 0, r = 1000000007.0;
        double ans = -1;
        for(int i = 1; i <= 100; i++) {
            double mid = (l + r) / 2.0;
            if(check(mid)) {
                ans = mid;
                r = mid;
            }
            else l = mid;
        }
        if(ans == -1) puts("-1");
        else printf("%.7f
    ", ans);
        return 0;
    }
    View Code

    D. Rocket

    待填

    E. Border

    题解:①  a1 * x1 + a2 * x2 + a3 * x3 + ···· + an * xn = C,令 k = gcd( a1, a2, a3, ····· , an ),那么①式等价于 k * M = C,M是某个正整数。即用k可以构造出①式中所有可能出现的C。

    //#include<bits/stdc++.h>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<bitset>
    #include<vector>
    #include<queue>
    #include<set>
    #define ll long long
    #define P pair<int, int>
    #define PP pair<int,pair<int, int>>
    #define pb push_back
    #define pp pop_back
    #define lson root << 1
    #define INF (int)2e9 + 7
    #define rson root << 1 | 1
    #define LINF (unsigned long long int)1e18
    #define mem(arry, in) memset(arry, in, sizeof(arry))
    using namespace std;
    
    const int N = 1e5 + 5;
    
    int n, k;
    
    int gcd(int a, int b) {
        if(a < b) swap(a, b);
        return (b == 0 ? a : gcd(b, a % b));
    }
    
    
    int main()
    {
        cin >> n >> k;
        int g = 0;
        for(int i = 1; i <= n; i++) {
            int t;
            cin >> t;
            g = gcd(g, t);
        }
        set<int> ans;
        for(ll i = 0, s = 0; i < k; i++, s += g) ans.insert(s % k);
    
        cout << (int)ans.size() << endl;
        for(auto &i : ans) cout << i << " ";
        cout << endl;
    
    
        return 0;
    }
    View Code
  • 相关阅读:
    腾讯云启动jenkins
    腾讯云centos7.5安装jdk1.8
    windows安装python2.7、python3.7和pycharm
    centos
    jquery----Ajax异步获取数据添加到表格中
    java----封装思想
    js----对table操作
    jquery----Ajax补充
    jquery----ajax解决scrf问题
    jquery----Ajax
  • 原文地址:https://www.cnblogs.com/zgglj-com/p/9377082.html
Copyright © 2011-2022 走看看