uva 12296 - Pieces and Discs(多边形切割)

2024-06-05 01:08

本文主要是介绍uva 12296 - Pieces and Discs(多边形切割),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题目链接:uva 12296 - Pieces and Discs


对于起始平面集合,每次添加一条切线,就对集合中所有平面进行向左向右的切割,生成新的平面。最后对于每个圆,判断一下相交面积是否为0,注意精度。


#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <complex>
#include <algorithm>using namespace std;
typedef pair<int,int> pii;
const double pi = 4 * atan(1);
const double eps = 1e-6;inline int dcmp (double x) { if (fabs(x) < eps) return 0; else return x < 0 ? -1 : 1; }
inline double getDistance (double x, double y) { return sqrt(x * x + y * y); }
inline double torad(double deg) { return deg / 180 * pi; }struct Point {double x, y;Point (double x = 0, double y = 0): x(x), y(y) {}void read () { scanf("%lf%lf", &x, &y); }void write () { printf("%lf %lf", x, y); }bool operator == (const Point& u) const { return dcmp(x - u.x) == 0 && dcmp(y - u.y) == 0; }bool operator != (const Point& u) const { return !(*this == u); }bool operator < (const Point& u) const { return dcmp(x - u.x) < 0 || (dcmp(x-u.x)==0 && dcmp(y-u.y) < 0); }bool operator > (const Point& u) const { return u < *this; }bool operator <= (const Point& u) const { return *this < u || *this == u; }bool operator >= (const Point& u) const { return *this > u || *this == u; }Point operator + (const Point& u) { return Point(x + u.x, y + u.y); }Point operator - (const Point& u) { return Point(x - u.x, y - u.y); }Point operator * (const double u) { return Point(x * u, y * u); }Point operator / (const double u) { return Point(x / u, y / u); }double operator * (const Point& u) { return x*u.y - y*u.x; }
};
typedef Point Vector;
typedef vector<Point> Polygon;struct Line {double a, b, c;Line (double a = 0, double b = 0, double c = 0): a(a), b(b), c(c) {}
};struct DirLine {Point p;Vector v;double ang;DirLine () {}DirLine (Point p, Vector v): p(p), v(v) { ang = atan2(v.y, v.x); }bool operator < (const DirLine& u) const { return ang < u.ang; }
};struct Circle {Point o;double r;Circle () {}Circle (Point o, double r = 0): o(o), r(r) {}void read () { o.read(), scanf("%lf", &r); }Point point(double rad) { return Point(o.x + cos(rad)*r, o.y + sin(rad)*r); }double getArea (double rad) { return rad * r * r / 2; }
};namespace Punctual {double getDistance (Point a, Point b) { double x=a.x-b.x, y=a.y-b.y; return sqrt(x*x + y*y); }
};namespace Vectorial {/* 点积: 两向量长度的乘积再乘上它们夹角的余弦, 夹角大于90度时点积为负 */double getDot (Vector a, Vector b) { return a.x * b.x + a.y * b.y; }/* 叉积: 叉积等于两向量组成的三角形有向面积的两倍, cross(v, w) = -cross(w, v) */double getCross (Vector a, Vector b) { return a.x * b.y - a.y * b.x; }double getLength (Vector a) { return sqrt(getDot(a, a)); }double getPLength (Vector a) { return getDot(a, a); }double getAngle (Vector u) { return atan2(u.y, u.x); }double getAngle (Vector a, Vector b) { return acos(getDot(a, b) / getLength(a) / getLength(b)); }Vector rotate (Vector a, double rad) { return Vector(a.x*cos(rad)-a.y*sin(rad), a.x*sin(rad)+a.y*cos(rad)); }/* 单位法线 */Vector getNormal (Vector a) { double l = getLength(a); return Vector(-a.y/l, a.x/l); }
};namespace ComplexVector {typedef complex<double> Point;typedef Point Vector;double getDot(Vector a, Vector b) { return real(conj(a)*b); }double getCross(Vector a, Vector b) { return imag(conj(a)*b); }Vector rotate(Vector a, double rad) { return a*exp(Point(0, rad)); }
};namespace Linear {using namespace Vectorial;Line getLine (double x1, double y1, double x2, double y2) { return Line(y2-y1, x1-x2, y1*x2-x1*y2); }Line getLine (double a, double b, Point u) { return Line(a, -b, u.y * b - u.x * a); }bool getIntersection (Line p, Line q, Point& o) {if (fabs(p.a * q.b - q.a * p.b) < eps)return false;o.x = (q.c * p.b - p.c * q.b) / (p.a * q.b - q.a * p.b);o.y = (q.c * p.a - p.c * q.a) / (p.b * q.a - q.b * p.a);return true;}/* 直线pv和直线qw的交点 */bool getIntersection (Point p, Vector v, Point q, Vector w, Point& o) {if (dcmp(getCross(v, w)) == 0) return false;Vector u = p - q;double k = getCross(w, u) / getCross(v, w);o = p + v * k;return true;}/* 点p到直线ab的距离 */double getDistanceToLine (Point p, Point a, Point b) { return fabs(getCross(b-a, p-a) / getLength(b-a)); }double getDistanceToSegment (Point p, Point a, Point b) {if (a == b) return getLength(p-a);Vector v1 = b - a, v2 = p - a, v3 = p - b;if (dcmp(getDot(v1, v2)) < 0) return getLength(v2);else if (dcmp(getDot(v1, v3)) > 0) return getLength(v3);else return fabs(getCross(v1, v2) / getLength(v1));}/* 点p在直线ab上的投影 */Point getPointToLine (Point p, Point a, Point b) { Vector v = b-a; return a+v*(getDot(v, p-a) / getDot(v,v)); }/* 判断线段是否存在交点 */bool haveIntersection (Point a1, Point a2, Point b1, Point b2) {double c1=getCross(a2-a1, b1-a1), c2=getCross(a2-a1, b2-a1), c3=getCross(b2-b1, a1-b1), c4=getCross(b2-b1,a2-b1);return dcmp(c1)*dcmp(c2) < 0 && dcmp(c3)*dcmp(c4) < 0;}/* 判断点是否在线段上 */bool onSegment (Point p, Point a, Point b) { return dcmp(getCross(a-p, b-p)) == 0 && dcmp(getDot(a-p, b-p)) < 0; }bool onLeft(DirLine l, Point p) { return dcmp(l.v * (p-l.p)) >= 0; }
}namespace Triangular {using namespace Vectorial;double getAngle (double a, double b, double c) { return acos((a*a+b*b-c*c) / (2*a*b)); }double getArea (double a, double b, double c) { double s =(a+b+c)/2; return sqrt(s*(s-a)*(s-b)*(s-c)); }double getArea (double a, double h) { return a * h / 2; }double getArea (Point a, Point b, Point c) { return fabs(getCross(b - a, c - a)) / 2; }double getDirArea (Point a, Point b, Point c) { return getCross(b - a, c - a) / 2; }
};namespace Polygonal {using namespace Vectorial;using namespace Linear;double getArea (Point* p, int n) {double ret = 0;for (int i = 0; i < n-1; i++)ret += (p[i]-p[0]) * (p[i+1]-p[0]);return ret/2;}/* 凸包 */int getConvexHull (Point* p, int n, Point* ch) {sort(p, p + n);int m = 0;for (int i = 0; i < n; i++) {/* 可共线 *///while (m > 1 && dcmp(getCross(ch[m-1]-ch[m-2], p[i]-ch[m-1])) < 0) m--;while (m > 1 && dcmp(getCross(ch[m-1]-ch[m-2], p[i]-ch[m-1])) <= 0) m--;ch[m++] = p[i];}int k = m;for (int i = n-2; i >= 0; i--) {/* 可共线 *///while (m > k && dcmp(getCross(ch[m-1]-ch[m-2], p[i]-ch[m-2])) < 0) m--;while (m > k && dcmp(getCross(ch[m-1]-ch[m-2], p[i]-ch[m-2])) <= 0) m--;ch[m++] = p[i];}if (n > 1) m--;return m;}int isPointInPolygon (Point o, Point* p, int n) {int wn = 0;for (int i = 0; i < n; i++) {int j = (i + 1) % n;if (onSegment(o, p[i], p[j]) || o == p[i]) return 0; // 边界上int k = dcmp(getCross(p[j] - p[i], o-p[i]));int d1 = dcmp(p[i].y - o.y);int d2 = dcmp(p[j].y - o.y);if (k > 0 && d1 <= 0 && d2 > 0) wn++;if (k < 0 && d2 <= 0 && d1 > 0) wn--;}return wn ? -1 : 1;}/* 旋转卡壳 */void rotatingCalipers(Point *p, int n, vector<pii>& sol) {sol.clear();int j = 1; p[n] = p[0];for (int i = 0; i < n; i++) {while (getCross(p[j+1]-p[i+1], p[i]-p[i+1]) > getCross(p[j]-p[i+1], p[i]-p[i+1]))j = (j+1) % n;sol.push_back(make_pair(i, j));sol.push_back(make_pair(i + 1, j + 1));}}void rotatingCalipersGetRectangle (Point *p, int n, double& area, double& perimeter) {p[n] = p[0];int l = 1, r = 1, j = 1;area = perimeter = 1e20;for (int i = 0; i < n; i++) {Vector v = (p[i+1]-p[i]) / getLength(p[i+1]-p[i]);while (dcmp(getDot(v, p[r%n]-p[i]) - getDot(v, p[(r+1)%n]-p[i])) < 0) r++;while (j < r || dcmp(getCross(v, p[j%n]-p[i]) - getCross(v,p[(j+1)%n]-p[i])) < 0) j++;while (l < j || dcmp(getDot(v, p[l%n]-p[i]) - getDot(v, p[(l+1)%n]-p[i])) > 0) l++;double w = getDot(v, p[r%n]-p[i])-getDot(v, p[l%n]-p[i]);double h = getDistanceToLine (p[j%n], p[i], p[i+1]);area = min(area, w * h);perimeter = min(perimeter, 2 * w + 2 * h);}}/* 计算半平面相交可以用增量法,o(n^2),初始设置4条无穷大的半平面 *//* 用有向直线A->B切割多边形u,返回左侧。可能退化成单点或线段 */Polygon cutPolygon (Polygon u, Point a, Point b) {Polygon ret;int n = u.size();for (int i = 0; i < n; i++) {Point c = u[i], d = u[(i+1)%n];if (dcmp((b-a)*(c-a)) >= 0) ret.push_back(c);if (dcmp((b-a)*(d-c)) != 0) {Point t;getIntersection(a, b-a, c, d-c, t);if (onSegment(t, c, d))ret.push_back(t);}}return ret;}/* 半平面相交 */int halfPlaneIntersection(DirLine* li, int n, Point* poly) {sort(li, li + n);int first, last;Point* p = new Point[n];DirLine* q = new DirLine[n];q[first=last=0] = li[0];for (int i = 1; i < n; i++) {while (first < last && !onLeft(li[i], p[last-1])) last--;while (first < last && !onLeft(li[i], p[first])) first++;q[++last] = li[i];if (dcmp(q[last].v * q[last-1].v) == 0) {last--;if (onLeft(q[last], li[i].p)) q[last] = li[i];}if (first < last)getIntersection(q[last-1].p, q[last-1].v, q[last].p, q[last].v, p[last-1]);}while (first < last && !onLeft(q[first], p[last-1])) last--;if (last - first <= 1) { delete [] p; delete [] q; return 0; }getIntersection(q[last].p, q[last].v, q[first].p, q[first].v, p[last]);int m = 0;for (int i = first; i <= last; i++) poly[m++] = p[i];delete [] p; delete [] q;return m;}/* 去除多边形共线点 */Polygon simplify (const Polygon& poly) {Polygon ret;int n = poly.size();for (int i = 0; i < n; i++) {Point a = poly[i];Point b = poly[(i+1)%n];Point c = poly[(i+2)%n];if (dcmp((b-a)*(c-b)) != 0 && (ret.size() == 0 || b != ret[ret.size()-1]))ret.push_back(b);}return ret;}
};namespace Circular {using namespace Linear;using namespace Vectorial;using namespace Triangular;/* 直线和原的交点 */int getLineCircleIntersection (Point p, Point q, Circle O, double& t1, double& t2, vector<Point>& sol) {Vector v = q - p;/* 使用前需清空sol *///sol.clear();double a = v.x, b = p.x - O.o.x, c = v.y, d = p.y - O.o.y;double e = a*a+c*c, f = 2*(a*b+c*d), g = b*b+d*d-O.r*O.r;double delta = f*f - 4*e*g;if (dcmp(delta) < 0) return 0;if (dcmp(delta) == 0) {t1 = t2 = -f / (2 * e);sol.push_back(p + v * t1);return 1;}t1 = (-f - sqrt(delta)) / (2 * e); sol.push_back(p + v * t1);t2 = (-f + sqrt(delta)) / (2 * e); sol.push_back(p + v * t2);return 2;}/* 圆和圆的交点 */int getCircleCircleIntersection (Circle o1, Circle o2, vector<Point>& sol) {double d = getLength(o1.o - o2.o);if (dcmp(d) == 0) {if (dcmp(o1.r - o2.r) == 0) return -1;return 0;}if (dcmp(o1.r + o2.r - d) < 0) return 0;if (dcmp(fabs(o1.r-o2.r) - d) > 0) return 0;double a = getAngle(o2.o - o1.o);double da = acos((o1.r*o1.r + d*d - o2.r*o2.r) / (2*o1.r*d));Point p1 = o1.point(a-da), p2 = o1.point(a+da);sol.push_back(p1);if (p1 == p2) return 1;sol.push_back(p2);return 2;}/* 过定点作圆的切线 */int getTangents (Point p, Circle o, Vector* v) {Vector u = o.o - p;double d = getLength(u);if (d < o.r) return 0;else if (dcmp(d - o.r) == 0) {v[0] = rotate(u, pi / 2);return 1;} else {double ang = asin(o.r / d);v[0] = rotate(u, -ang);v[1] = rotate(u, ang);return 2;}}/* a[i] 和 b[i] 分别是第i条切线在O1和O2上的切点 */int getTangents (Circle o1, Circle o2, Point* a, Point* b) {int cnt = 0;if (o1.r < o2.r) { swap(o1, o2); swap(a, b); }double d2 = getLength(o1.o - o2.o); d2 = d2 * d2;double rdif = o1.r - o2.r, rsum = o1.r + o2.r;if (d2 < rdif * rdif) return 0;if (dcmp(d2) == 0 && dcmp(o1.r - o2.r) == 0) return -1;double base = getAngle(o2.o - o1.o);if (dcmp(d2 - rdif * rdif) == 0) {a[cnt] = o1.point(base); b[cnt] = o2.point(base); cnt++;return cnt;}double ang = acos( (o1.r - o2.r) / sqrt(d2) );a[cnt] = o1.point(base+ang); b[cnt] = o2.point(base+ang); cnt++;a[cnt] = o1.point(base-ang); b[cnt] = o2.point(base-ang); cnt++;if (dcmp(d2 - rsum * rsum) == 0) {a[cnt] = o1.point(base); b[cnt] = o2.point(base); cnt++;} else if (d2 > rsum * rsum) {double ang = acos( (o1.r + o2.r) / sqrt(d2) );a[cnt] = o1.point(base+ang); b[cnt] = o2.point(base+ang); cnt++;a[cnt] = o1.point(base-ang); b[cnt] = o2.point(base-ang); cnt++;}return cnt;}/* 三点确定外切圆 */Circle CircumscribedCircle(Point p1, Point p2, Point p3) {  double Bx = p2.x - p1.x, By = p2.y - p1.y;  double Cx = p3.x - p1.x, Cy = p3.y - p1.y;  double D = 2 * (Bx * Cy - By * Cx);  double cx = (Cy * (Bx * Bx + By * By) - By * (Cx * Cx + Cy * Cy)) / D + p1.x;  double cy = (Bx * (Cx * Cx + Cy * Cy) - Cx * (Bx * Bx + By * By)) / D + p1.y;  Point p = Point(cx, cy);  return Circle(p, getLength(p1 - p));  }/* 三点确定内切圆 */Circle InscribedCircle(Point p1, Point p2, Point p3) {  double a = getLength(p2 - p3);  double b = getLength(p3 - p1);  double c = getLength(p1 - p2);  Point p = (p1 * a + p2 * b + p3 * c) / (a + b + c);  return Circle(p, getDistanceToLine(p, p1, p2));  } /* 三角形一顶点为圆心 */double getPublicAreaToTriangle (Circle O, Point a, Point b) {if (dcmp((a-O.o)*(b-O.o)) == 0) return 0;int sig = 1;double da = getPLength(O.o-a), db = getPLength(O.o-b);if (dcmp(da-db) > 0) {swap(da, db);swap(a, b);sig = -1;}double t1, t2;vector<Point> sol;int n = getLineCircleIntersection(a, b, O, t1, t2, sol);if (dcmp(da-O.r*O.r) <= 0) {if (dcmp(db-O.r*O.r) <= 0)	return getDirArea(O.o, a, b) * sig;int k = 0;if (getPLength(sol[0]-b) > getPLength(sol[1]-b)) k = 1;double ret = getArea(O.o, a, sol[k]) + O.getArea(getAngle(sol[k]-O.o, b-O.o));double tmp = (a-O.o)*(b-O.o);return ret * sig * dcmp(tmp);}double d = getDistanceToSegment(O.o, a, b);if (dcmp(d-O.r) >= 0) {double ret = O.getArea(getAngle(a-O.o, b-O.o));double tmp = (a-O.o)*(b-O.o);return ret * sig * dcmp(tmp);}double k1 = O.r / getLength(a - O.o), k2 = O.r / getLength(b - O.o);Point p = O.o + (a - O.o) * k1, q = O.o + (b - O.o) * k2;double ret1 = O.getArea(getAngle(p-O.o, q-O.o));double ret2 = O.getArea(getAngle(sol[0]-O.o, sol[1]-O.o)) - getArea(O.o, sol[0], sol[1]);double ret = (ret1 - ret2), tmp = (a-O.o)*(b-O.o);return ret * sig * dcmp(tmp);}double getPublicAreaToPolygon (Circle O, Point* p, int n) {if (dcmp(O.r) == 0) return 0;double area = 0;for (int i = 0; i < n; i++) {int u = (i + 1) % n;area += getPublicAreaToTriangle(O, p[i], p[u]);}return fabs(area);}
};using namespace Vectorial;
using namespace Polygonal;
using namespace Circular;int N, M, L, W;
vector<Polygon> faces, newfaces;double getPublicAreaToPolygon (Circle O, Polygon p) {if (dcmp(O.r) == 0) return 0;int n = p.size();double area = 0;for (int i = 0; i < n; i++) {int u = (i + 1) % n;area += getPublicAreaToTriangle(O, p[i], p[u]);}return fabs(area);
}double getArea (Polygon p) {int n = p.size();double ret = 0;for (int i = 0; i < n-1; i++)ret += (p[i]-p[0])*(p[i+1]-p[0]);return fabs(ret) / 2;
}int main () {while (scanf("%d%d%d%d", &N, &M, &L, &W) == 4 && N + M + L + W) {Point A, B;Polygon u;u.push_back(Point(0, 0));u.push_back(Point(L, 0));u.push_back(Point(L, W));u.push_back(Point(0, W));faces.clear();faces.push_back(u);for (int i = 0; i < N; i++) {A.read(), B.read();newfaces.clear();for (int j = 0; j < faces.size(); j++) {Polygon left = cutPolygon(faces[j], A, B);Polygon right = cutPolygon(faces[j], B, A);if (left.size() >= 3) newfaces.push_back(left);if (right.size() >= 3) newfaces.push_back(right);}faces = newfaces;}double x, y, r;vector<double> ans;while (M--) {ans.clear();scanf("%lf%lf%lf", &x, &y, &r);for (int i = 0; i < faces.size(); i++) {double tmp = getPublicAreaToPolygon (Circle(Point(x, y), r), faces[i]);if (dcmp(tmp) > 0)ans.push_back(getArea(faces[i]));}sort(ans.begin(), ans.end());printf("%lu", ans.size());for (int i = 0; i < ans.size(); i++)printf(" %.2lf", ans[i]);printf("\n");}printf("\n");}return 0;
}


这篇关于uva 12296 - Pieces and Discs(多边形切割)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1031640

相关文章

uva 10055 uva 10071 uva 10300(水题两三道)

情歌两三首,水题两三道。 好久没敲代码了为暑假大作战热热身。 uva 10055 Hashmat the Brave Warrior 求俩数相减。 两个debug的地方,一个是longlong,一个是输入顺序。 代码: #include<stdio.h>int main(){long long a, b;//debugwhile(scanf("%lld%lld", &

poj 3259 uva 558 Wormholes(bellman最短路负权回路判断)

poj 3259: 题意:John的农场里n块地,m条路连接两块地,w个虫洞,虫洞是一条单向路,不但会把你传送到目的地,而且时间会倒退Ts。 任务是求你会不会在从某块地出发后又回来,看到了离开之前的自己。 判断树中是否存在负权回路就ok了。 bellman代码: #include<stdio.h>const int MaxN = 501;//农场数const int

poj 2349 Arctic Network uva 10369(prim or kruscal最小生成树)

题目很麻烦,因为不熟悉最小生成树的算法调试了好久。 感觉网上的题目解释都没说得很清楚,不适合新手。自己写一个。 题意:给你点的坐标,然后两点间可以有两种方式来通信:第一种是卫星通信,第二种是无线电通信。 卫星通信:任何两个有卫星频道的点间都可以直接建立连接,与点间的距离无关; 无线电通信:两个点之间的距离不能超过D,无线电收发器的功率越大,D越大,越昂贵。 计算无线电收发器D

uva 10387 Billiard(简单几何)

题意是一个球从矩形的中点出发,告诉你小球与矩形两条边的碰撞次数与小球回到原点的时间,求小球出发时的角度和小球的速度。 简单的几何问题,小球每与竖边碰撞一次,向右扩展一个相同的矩形;每与横边碰撞一次,向上扩展一个相同的矩形。 可以发现,扩展矩形的路径和在当前矩形中的每一段路径相同,当小球回到出发点时,一条直线的路径刚好经过最后一个扩展矩形的中心点。 最后扩展的路径和横边竖边恰好组成一个直

uva 10061 How many zero's and how many digits ?(不同进制阶乘末尾几个0)+poj 1401

题意是求在base进制下的 n!的结果有几位数,末尾有几个0。 想起刚开始的时候做的一道10进制下的n阶乘末尾有几个零,以及之前有做过的一道n阶乘的位数。 当时都是在10进制下的。 10进制下的做法是: 1. n阶位数:直接 lg(n!)就是得数的位数。 2. n阶末尾0的个数:由于2 * 5 将会在得数中以0的形式存在,所以计算2或者计算5,由于因子中出现5必然出现2,所以直接一

uva 568 Just the Facts(n!打表递推)

题意是求n!的末尾第一个不为0的数字。 不用大数,特别的处理。 代码: #include <stdio.h>const int maxn = 10000 + 1;int f[maxn];int main(){#ifdef LOCALfreopen("in.txt", "r", stdin);#endif // LOCALf[0] = 1;for (int i = 1; i <=

uva 575 Skew Binary(位运算)

求第一个以(2^(k+1)-1)为进制的数。 数据不大,可以直接搞。 代码: #include <stdio.h>#include <string.h>const int maxn = 100 + 5;int main(){char num[maxn];while (scanf("%s", num) == 1){if (num[0] == '0')break;int len =

uva 10014 Simple calculations(数学推导)

直接按照题意来推导最后的结果就行了。 开始的时候只做到了第一个推导,第二次没有继续下去。 代码: #include<stdio.h>int main(){int T, n, i;double a, aa, sum, temp, ans;scanf("%d", &T);while(T--){scanf("%d", &n);scanf("%lf", &first);scanf

uva 10916 Factstone Benchmark(打表)

题意是求 k ! <= 2 ^ n ,的最小k。 由于n比较大,大到 2 ^ 20 次方,所以 2 ^ 2 ^ 20比较难算,所以做一些基础的数学变换。 对不等式两边同时取log2,得: log2(k ! ) <=  log2(2 ^ n)= n,即:log2(1) + log2(2) + log2 (3) + log2(4) + ... + log2(k) <= n ,其中 n 为 2 ^

uva 10025 The ? 1 ? 2 ? ... ? n = k problem(数学)

题意是    ?  1  ?  2  ?  ...  ?  n = k 式子中给k,? 处可以填 + 也可以填 - ,问最小满足条件的n。 e.g k = 12  - 1 + 2 + 3 + 4 + 5 + 6 - 7 = 12 with n = 7。 先给证明,令 S(n) = 1 + 2 + 3 + 4 + 5 + .... + n 暴搜n,搜出当 S(n) >=