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;
    }
  • 相关阅读:
    div+css之清除浮动
    ASP.NET repeater添加序号列的方法
    html中给图片添加热点
    jquery中read与js中onload区别
    从.net转型,聊聊最近一些面试,薪资和想法
    (9)分布式下的爬虫Scrapy应该如何做-关于ajax抓取的处理(一)
    数学之美--关于图论引申出来的爬虫构想
    (8)分布式下的爬虫Scrapy应该如何做-图片下载(源码放送)
    【转】Bloom Filter布隆过滤器的概念和原理
    【转】Python中的GIL、多进程和多线程
  • 原文地址:https://www.cnblogs.com/GadyPu/p/4773211.html
Copyright © 2011-2022 走看看