首页 > 其他 > 详细

poj 1840 Eqs

时间:2015-08-31 16:47:11      阅读:183      评论:0      收藏:0      [点我收藏+]

题目连接

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;
}

poj 1840 Eqs

原文:http://www.cnblogs.com/GadyPu/p/4773211.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!