zoukankan      html  css  js  c++  java
  • poj 1840 Eqs

    题目连接

    http://poj.org/problem?id=1840  

    Eqs

    Description

    Consider equations having the following form: 
    a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 
    The coefficients are given integers from the interval [-50,50]. 
    It is consider a solution a system (x1, x2, x3, x4, x5) that verifies the equation, xi∈[-50,50], xi != 0, any i∈{1,2,3,4,5}. 

    Determine how many solutions satisfy the given equation. 

    Input

    The only line of input contains the 5 coefficients a1, a2, a3, a4, a5, separated by blanks.

    Output

    The output will contain on the first line the number of the solutions for the given equation.

    Sample Input

    37 29 41 43 47

    Sample Output

    654

    二分。。

    #include<algorithm>
    #include<iostream>
    #include<cstdlib>
    #include<cstring>
    #include<cstdio>
    #include<vector>
    #include<map>
    using std::map;
    using std::min;
    using std::sort;
    using std::pair;
    using std::vector;
    using std::multimap;
    using std::lower_bound;
    using std::upper_bound;
    #define pb(e) push_back(e)
    #define sz(c) (int)(c).size()
    #define mp(a, b) make_pair(a, b)
    #define all(c) (c).begin(), (c).end()
    #define iter(c) __typeof((c).begin())
    #define cls(arr, val) memset(arr, val, sizeof(arr))
    #define cpresent(c, e) (find(all(c), (e)) != (c).end())
    #define rep(i, n) for(int i = 0; i < (int)n; i++)
    #define tr(c, i) for(iter(c) i = (c).begin(); i != (c).end(); ++i)
    const int N = 110;
    const int INF = 0x3f3f3f3f;
    vector<int> vec;
    int a, b, c, d, e;
    inline int cube(int x) {
        return x * x * x;
    }
    void solve() {
        int ans = 0, ret = 0;
        for(int i = -50; i <= 50; i++) {
            if(!i) continue;
            for(int j = -50; j <= 50; j++) {
                if(!j) continue;
                for(int k = -50; k <= 50; k++) {
                    if(!k) continue;
                    ret = a * cube(i) + b * cube(j) + c * cube(k);
                    vec.pb(ret);
                }
            }
        }
        sort(all(vec));
        for(int i = -50; i <= 50; i++) {
            if(!i) continue;
            for(int j = -50; j <= 50; j++) {
                if(!j) continue;
                ret = d * cube(i) + e * cube(j);
                ans += upper_bound(all(vec), -ret) - lower_bound(all(vec), -ret);
            }
        }
        vec.clear();
        printf("%d
    ", ans);
    }
    int main() {
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w+", stdout);
    #endif
        while(~scanf("%d %d %d %d %d", &a, &b, &c, &d, &e)) {
            solve();
        }
        return 0;
    }
  • 相关阅读:
    CSS3的[att$=val]选择器
    CSS3的[att^=val]选择器
    CSS3的[att*=val]选择器
    CSS3的[att=val]选择器
    web报表工具finereport常用函数的用法总结(数组函数)
    web报表工具finereport常用函数的用法总结(数组函数)
    人性多面性的终极教材——北漂18年(4)
    第23章 MYSQL结构
    11g OS文件移动到ASM
    Oracle 10g TAF配置
  • 原文地址:https://www.cnblogs.com/GadyPu/p/4773211.html
Copyright © 2011-2022 走看看