UVaOj How many pieces of land?
来源:互联网 发布:sql server trigger 编辑:程序博客网 时间:2024/05/17 04:04
你有一块椭圆的地。你可以在边界上选n个点,并两两连接得到n*(n-1)/2条线段。它们最多能把土地分成多少个部分? 样例输入:4 样例输出:8
欧拉公式:V-E+F=2(V代表顶点数,E代表线段数,F代表面数,包含椭圆外的无穷大面),面数最多的情况是任意3条线段不会交于同一点。
下面最重要的就是求出图中的顶点数目,线段数目,进而得到土地的块数。方法:
对图中线段遍历(将线段看做有向线段,例如,线段AB与线段BA不同)。每条线段将其他顶点分成两部分,一边i个顶点,另一边n-i-2个顶点。如此,则该线段被分成了i(n-i-2)+1段,且线段上(不包含断点)有i(n-i-2)个交点。PS:每个交点被重复计算了4次,每条线段被重复计算了2次。
代码如下:
#include <iostream>using namespace std;int main(){ int n; cin>>n; int v=0; int e=0; for(int i=0;i<=n-2;i++) { v=v+i*(n-2-i); e=e+(i*(n-2-i)+1); } v=n+n*v/4; e=n+n*e/2; int f=e-v+1; cout<<f<<endl; return 0;}
- UVaOj How many pieces of land?
- How many pieces of land?
- uva 10213 how many pieces of land
- uva_10213 - How Many Pieces of Land ?
- UVa10213 - How Many Pieces of Land ?
- 110602 How Many Pieces of Land
- UVA-10213 How many pieces of land
- UVa 10213 How Many Pieces of Land?
- How Many Pieces of Land题解
- UVa 10213 How Many Pieces of Land ?
- UVa Problem Solution: 10213 - How Many Pieces of Land?
- (挑战编程_6_2)How Many Pieces of Land?
- UVA 10213 How Many Pieces of Land? 欧拉定理
- UVA 10213(p336)----How Many Pieces of Land
- uva 10213 How Many Pieces of Land 分割圆 高精度
- UVa 10213 How Many Pieces of Land (欧拉定理)
- UVa Problem 10213 How Many Pieces of Land? (土地分割)
- UVa 10213 How Many Pieces of Land ? (数学&欧拉公式&高精度)
- java读取文件
- 二叉树的基本操作
- IE浏览器新建窗口session共享问题
- 在Java中使用协程(Coroutine)
- zoj 2124&& poj 1730(数论)
- UVaOj How many pieces of land?
- 在一个文件集合中查找匹配模式的行 (TCPL,练习7-7)
- 如何解决Call to undefined function mysql_connect() 问题
- 似水流年的欢愉和不幸
- 华为技术服务面经
- php获得(给定时间的)前一个月时间
- win7真机与VMware虚拟机实现文件共享(hgfs方式)
- 命令行运行VS2010的C/C++编译器cl.exe报错
- [矩乘]K步最短路