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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

How Many Pieces of Land ? (UVA-10213)

發布時間:2025/3/17 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 How Many Pieces of Land ? (UVA-10213) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Problem Description

You are given an elliptical shaped land and you are asked to choose n arbitrary points on its boundary. Then you connect all these points with one another with straight lines (that’s n ? (n?1)/2 connections for n points). What is the maximum number of pieces of land you will get by choosing the points on the boundary carefully?

Input

The first line of the input file contains one integer S (0 < S < 3500), which indicates how many sets of input are there. The next S lines contain S sets of input. Each input contains one integer N?(0 ≤ N < 231).

Output

For each set of input you should output in a single line the maximum number pieces of land possible to get for the value of N.

Sample Input

4
1
2
3
4

Sample Output

1
2
4
8

題意:t 組樣例,每組給出一個數 n,代表一個橢圓上有 n 個點,將這 n 個點兩兩相連,問最多能將這個橢圓分成個區域

思路:歐拉公式

在平面圖中,V-E+F=2,其中 V 是點數,E 是邊數 F 是面數,因此只需要計算 V、E 即可,此外還需減去外面的 “無限面”

不管是點還是邊,在計算時,都要枚舉一條從固定點出發的對角線,因此最后要乘以 n,對角線的左邊有 i?個點,右邊有 n-2-i 個點,左右點連線在這條對角線上形成了 i*(n-2-i) 個交點,得到 i*(n-2-i)+1 條線段,這樣一來,每個點被重復計算了 4 次,每條邊被重復計算了 2 次,故有:

因此減去外面的無限面,有:

這樣一來,時間復雜度為 O(n),但 n 最大到 2^31,仍然會 TLE

根據?

可得:

Source Program

import java.math.BigInteger; import java.util.*;public class Main{public static void main(String[] args){Scanner input = new Scanner(System.in);int T=input.nextInt();while(T-->0){BigInteger n=input.nextBigInteger();BigInteger temp1=n.multiply(n.subtract(BigInteger.ONE)).divide(BigInteger.valueOf(2));BigInteger temp2=n.multiply(n.subtract(BigInteger.ONE)).multiply(n.subtract(BigInteger.valueOf(2))).multiply(n.subtract(BigInteger.valueOf(3))).divide(BigInteger.valueOf(24));BigInteger res=temp1.add(temp2).add(BigInteger.ONE);System.out.println(res);}} }

?

總結

以上是生活随笔為你收集整理的How Many Pieces of Land ? (UVA-10213)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。