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\n", 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;
}
优质内容筛选与推荐>>
1、TVM 学习教程
2、[转]跨域资源共享(Cross-Origin Resource Sharing)实现Ajax跨域请求
3、maven学习记录四——私服 nexus
4、UI3_ViewController初步
5、gradle sitemeth3 配置


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号