uva 10623 - Thinking Backward(数学)
2014-06-29 10:57
337 查看
题目链接:uva 10623 - Thinking Backward
题目大意:就是给出N,表示要将平面分解成N份,问有哪些可选则的方案,m表示椭圆、n表示圆形、p表示三角形的个数,m、n、p分别给定范围。
解题思路:本来这题一点思路都没有,但是在论坛上看到一个公式N=2+2m(m−1)+n(n−1)+4mn+3p(p−1)+6mp+6np
这样只要枚举m和p,求解n,判断n是否满足即可,注意n一定是整数。
题目大意:就是给出N,表示要将平面分解成N份,问有哪些可选则的方案,m表示椭圆、n表示圆形、p表示三角形的个数,m、n、p分别给定范围。
解题思路:本来这题一点思路都没有,但是在论坛上看到一个公式N=2+2m(m−1)+n(n−1)+4mn+3p(p−1)+6mp+6np
这样只要枚举m和p,求解n,判断n是否满足即可,注意n一定是整数。
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; typedef long long ll; const int N = 100005; struct state { ll n, m, p; void set (ll m, ll n, ll p) { this->m = m; this->n = n; this->p = p; } }s ; bool cmp (const state& a,const state& b) { if (a.m != b.m) return a.m < b.m; if (a.n != b.n) return a.n < b.n; return a.p < b.p; } int main () { int cas = 1; ll n; while (scanf("%lld", &n) == 1 && n != -1) { printf("Case %d:\n", cas++); if (n == 1) { printf("0 0 0\n"); continue; } int c = 0; for (ll m = 0; m < 100; m++) { for (ll p = 0; p < 100; p++) { ll sum = 2 + 2 * m * (m-1) + 3 * p * (p-1) + 6 * m * p; sum = n - sum; ll a = 4 * m + 6 * p - 1; /* if (m == 0 && p == 0) printf("%lld %lld! \n", sum, a); */ double tmp = sum + a * a / 4.0; if (tmp < 0) continue; tmp = sqrt(tmp); double x = (tmp - ((double)a / 2.0)); if (x < 0 || x >= 20000) continue; ll n = x; /* */ if (n * n + a * n == sum) s[c++].set(m, n, p); } } sort (s, s + c, cmp); if (c) { for (int i = 0; i < c; i++) printf("%lld %lld %lld\n", s[i].m, s[i].n, s[i].p); } else printf("Impossible.\n"); } return 0; }
相关文章推荐
- 数学专项number_theory:UVa 10622
- UVALive - 3490 Generator 【数学】【高斯消元】
- UVa 11426 - GCD - Extreme (II) (数学 欧拉函数)
- UVA - 10561 Treblecross (博弈数学&SG函数)
- UVa 10916 Factstone Benchmark (数学&阶乘的处理技巧)
- UVALive 7511 Multiplication Table (数学模拟题)
- uva - UVA 1388 - Graveyard (数学推理)
- uva 10620 - A Flea on a Chessboard(暴力+数学)
- UVA - 10014 - Simple calculations (经典的数学推导题!!)
- 数学专项number_theory:UVa 294
- UVA 10325 The Lottery (组合数学,容斥原理,二进制枚举)
- UVa 701 The Archeologists' Dilemma (数学&枚举)
- UVa 10213 How Many Pieces of Land ? (数学&欧拉公式&高精度)
- [UVA11762] Race to 1 && 数学期望
- UVALive 7040 Color (容斥原理 + 组合数学递推公式 + 求逆元 + 基础数论)
- UVa 10900 So you want to be a 2n-aire? (概率DP,数学)
- uva 575(数学)
- 数学专项counting:UVa 11529
- uva 10010(数学)
- uva 10112(数学)