- 注册时间
- 2014-7-6
- 最后登录
- 1970-1-1
- 威望
- 星
- 金币
- 枚
- 贡献
- 分
- 经验
- 点
- 鲜花
- 朵
- 魅力
- 点
- 上传
- 次
- 下载
- 次
- 积分
- 76
- 在线时间
- 小时
|
楼主 |
发表于 2014-7-10 13:40:06
|
显示全部楼层
我找一个很久前做过这道题的人帮忙,他翻出个旧文档,说可能有些参数小改了。大家看看这些代码有没参考价值?
被这题堵着真心烦呀。。。
- #include <vector>
- #include <set>
- #include <numeric>
- #include <iostream>
- using namespace std;
- #define SZ(x) (int)((x).size())
- typedef long long int64;
- template <typename T> T gcd(T x, T y) {for (T t; x; ) t = x, x = y % x, y = t; return y; }
- const int N = 3.6e4;//N要改
- struct node {
- int64 a, b, c;
- node(int A, int B, int C) : a(A), b(B), c(C) {}
- } ;
- bool operator < (const node &a, const node &b) {
- return a.a == b.a ? (a.b < b.b) : (a.a < b.a);
- }
- node operator * (const node &a, const node &b) {
- return node(a.a * b.a - a.b * b.b, a.a * b.b + a.b * b.a, a.c * b.c);
- }
- int cnt;
- set<node> S;
- void test(int a, int b, int c) {
- auto p = node(a, b, c);
- if (S.count(p)) return ;
- vector<node> v;
- for (auto q = p; q.c < N; q = q * p) v.push_back(q), S.insert(q);
- for (int i = 0; i < SZ(v); ++i) {
- for (int j = i + 1; j < SZ(v); ++j) {
- int x = gcd(i + 1, j + 1);
- int pr = N * (i + 1) / (i + j + 2) / v[j].c;
- for (int t = 1; t <= pr; ++t) {
- int64 r = t * v[j].c * (i + 1) / x, R = t * v[j].c * (j + 1) / x;
- if (r == 500 && R == 1500)
- cout << r << " " << R << " " << (R * v[i].a / v[i].c + r * v[j].a / v[j].c) << " " << (R * v[i].b / v[i].c - r * v[j].b / v[j].c) << endl;
- }
- }
- }
- }
- void gen(int a, int b, int c) {
- if (c > N) return ;
- if (a && b) test(a, b, c);
- ++cnt;
- int g = (a + b + c) << 1, d, e, f;
- gen(d = g - a, e = g - b, f = g + c);
- if (a) g = (a <<= 1) << 1, gen(d - a, e - g, f - g);
- if (b) g = (b <<= 1) << 1, gen(d - g, e - b, f - g);
- }
- int main() {
- ios_base::sync_with_stdio(false);
- gen(3,4,5);//正常使用要改参数?
- gen(4,3,5);//正常使用要改参数?
- cout << cnt << endl;
- return 0;
- }
复制代码 |
|