poj 1840 Eqs
http://poj.org/problem?id=1840
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.
The only line of input contains the 5 coefficients a1, a2, a3, a4, a5, separated by blanks.
The output will contain on the first line the number of the solutions for the given equation.
37 29 41 43 47
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; }优质内容筛选与推荐>>