UVA 10790 How Many Points of Intersection? 简单数学题
来源:互联网 发布:linux安装rpm文件 编辑:程序博客网 时间:2024/05/18 00:33
给出m和n为上下两条直线上点的数量,求上下两条直线各选一个点的所有连线的交点最多为多少个,其中两条直线上的 n + m 个点也要计算在内
首先记 d[n][m]为上直线有 n 个点,下直线有 m 个点时,最多的焦点数,则显然有 d[1][i] = d[i][1] = 0
对于d[n + 1][m] 由上直线新加入了一个点,假设加在最右端,对应的与下直线的连接有m条,其中,与下直线最左端的点的连线新增交点 n * (m - 1)条,与下直线从左往右第二个点的连线新增交点 n * (m - 2) 个,如此递推,共新增交点 sigma(n * i) 个, i 从1到m - 1;
则 d[n + 1][m] = n * (m - 1) * m / 2 + d[n][m] = sigma( i*m*(m - 1)/2) + d[1][m] i从1到n
则 d[n][m] = sigma(i*m*(m - 1)/2) + d[1][m] i 从1 到 n - 1
故 d[n][m] = n*m*(n - 1)*(m - 1)/4
要注意答案可能很大,要用long long 型储存答案
代码如下:
Result : Accepted Memory : 0 KB Time : 18 ms
/* * Author: Gatevin * Created Time: 2014/7/8 12:06:03 * File Name: test.cpp */#include<iostream>#include<sstream>#include<fstream>#include<vector>#include<list>#include<deque>#include<queue>#include<stack>#include<map>#include<set>#include<bitset>#include<algorithm>#include<cstdio>#include<cstdlib>#include<cstring>#include<cctype>#include<cmath>#include<ctime>#include<iomanip>using namespace std;const double eps(1e-8);typedef long long lint;long long a,b;int main(){ int cas = 0; while(cin>>a>>b && a && b) { cas++; cout<<"Case "<<cas<<": "<<(a*b*(a - 1)*(b - 1))/4<<endl; } return 0;}
0 0
- UVA 10790 How Many Points of Intersection? 简单数学题
- UVa 10790 How Many Points of Intersection?
- uva 10790 How Many Points of Intersection?
- uva 10790 - How Many Points of Intersection?
- uva-10790-How Many Points of Intersection?
- UVa 10790 - How Many Points of Intersection?
- Uva 10790 - How Many Points of Intersection?
- UVa 10790 - How Many Points of Intersection?
- UVA 10790 How Many Points of Intersection?
- uva 10790 - How Many Points of Intersection
- uva 10790 How Many Points of Intersection?
- UVa 10790 How Many Points of Intersection?
- uva - 10790 - How Many Points of Intersection?
- UVa 10790 - How Many Points of Intersection?
- UVa 10790 - How Many Points of Intersection?
- Uva 10790 How Many Points of Intersection?
- UVA - 10790 How Many Points of Intersection?
- UVA - 10790 How Many Points of Intersection?
- UVA - 817 According to Bartjens
- C++读写EXCEL文件方式比较
- 监听端口号与PID
- pyqt 通过notepad打开中文文件
- Objective-C中的Category(分类)
- UVA 10790 How Many Points of Intersection? 简单数学题
- UVa11420 - Chest of Drawers(动态规划)
- CentOs怎么开机直接进入命令行模式
- 归并排序
- linux自动拷贝文件,并恢复ORACLE数据库
- C++ 虚函数的缺省参数问题
- php 使用 curl 发送 post 数据
- 数据结构与算法——线性时间排序(计数排序、基数排序、桶排序)
- 关于二分图的一些转载