日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDU2050 折线分割平面

發(fā)布時間:2025/6/17 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU2050 折线分割平面 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題目:acm.hdu.edu.cn/showproblem.php?pid=2050

遞推:

從直線入手,第n條直線,最多和平面上的直線有n-1個交點,多出(n-1)+1個部分

序號123...n
交點012...n-1
多出部分123...(n-1)+1

總部分 ? ? ? ? ? ? ? ? ? ? ? ? 2 ? ? ? ?? 4 ? ? ? ?? 7 ? ? ?? ....

在轉(zhuǎn)化為折線,當增加第n條折線時,與圖形新的交點最多2*2*(n-1), 多出2*2*(n-1)+1 個部分

(可以把折線看作兩條直線理解)

所以 f(n) = f(n-1) + 4*(n-1)+1;

AC代碼:

#include <iostream> #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <string> #include <bitset> #include <vector> #include <set> #include <map> #include <queue> #include <algorithm> #include <sstream> #include <stack> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) #define FO freopen("in.txt", "r", stdin); #define lowbit(x) (x&-x) typedef vector<int> VI; typedef long long ll; typedef pair<int,int> PII; const ll mod=1000000007; const int inf = 0x3f3f3f3f; ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} template <class T> inline bool scan_d(T &ret) {char c; int sgn;if (c = getchar(), c == EOF) return 0; //EOFwhile (c != '-' && (c < '0' || c > '9')) c = getchar();sgn = (c == '-') ? -1 : 1;ret = (c == '-') ? 0 : (c - '0');while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');ret *= sgn;return 1; } inline void out(ll x) {if (x > 9) out(x / 10);putchar(x % 10 + '0'); }const int maxn = 10010; ll f[maxn], ans; int main() {int _, n;f[1] = 2;rep(i, 2, maxn) {f[i] = f[i-1]+4*(i-1)+1;//遞推公式 } for(scan_d(_);_;_--) {scan_d(n);out(f[n]);printf("\n");} }

?

轉(zhuǎn)載于:https://www.cnblogs.com/ACMerszl/p/9572954.html

總結

以上是生活随笔為你收集整理的HDU2050 折线分割平面的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。