ACdream 1067:Triangles
Problem Description
Input
Output
Sample Input
3
4
5
Sample Output
1
0
5
分析:当3个点组成锐角三角形ABC时,圆心O一定在三角形内部,∠AOB , ∠BOC, ∠COA一定小于180度(∠AOB + ∠BOC + ∠COA = 360度) (1)当N为偶数时,用1, 2 .... k , k+1, .... , 2k来标记N个点(2K = N). 固定一个点, 如点A = 点k, 那么2k点是肯定不能选的了,因为 k, 2k组成一条直径。 所以剩下两个区间 [1, k-1], [K+1, 2k-1].如果点B, 点C同处一个区间,那么ABC一定是一个钝角三角形,所以B,C一定不可处于同一区间。 设点B = 点x, x 属于[1, k-2]; 点C=点y,y 属于[k+1, 2k-1]; 在这样的情况下,y - x > k 才能使得ABC为锐角三角形 ==> (x, y)的取值有S = 0 + 1 + 2 + ... + (k - 2) = (k -1) * (k -2) /2 = (N/2 - 1) * (N / 2 - 2) / 2 ;
有N个点,每个三角形被重复计算3次,所以一共有 S * N / 3种; (2)点N为奇数时, k = N / 2. 用0, 1 ... k , k + 1, 2k.
固定点A = 点0,则过点A的直径把N个点分成[1, k], [k+1, 2k]两个部分。和(1)同理,可以令 点B = 点x , x 属于[1, k], 点C = 点y, y 属于[k+1, 2k]; 在这样的情况下,y - x <= k 才能使得ABC为锐角三角形 ==> (x, y)的取值有S = k + (k- 1) + ... + 1 = k * (k +1) /2 = (N/2) * (N / 2 + 1) / 2 ; 有N个点,每个三角形被重复计算3次,所以一共有 S * N / 3种; 综上: N 为偶数时, ans = N * (N/2 - 1) * (N / 2 - 2) / 6; N为奇数时, ans = N * (N/2) * (N / 2 + 1) / 6;
- #include <stdio.h>
- #include <string.h>
- #include <algorithm>
- using namespace std;
- #define ll long long
- int main()
- {
- ll n,k,ans;
- while(~scanf("%lld",&n))
- {
- if(n<3)
- ans = 0;
- else if(n%2)
- ans = (1+n/2)*(n/2)*n/6;
- else
- ans = (n/2-2)*(n/2-1)*n/6;
- printf("%lld\n",ans);
- }
- return 0;
- }
ACdream 1067:Triangles的更多相关文章
- acdream.Triangles(数学推导)
Triangles Time Limit:1000MS Memory Limit:64000KB 64bit IO Format:%lld & %llu Submit Stat ...
- acdream.A Very Easy Triangle Counting Game(数学推导)
A - A Very Easy Triangle Counting Game Time Limit:1000MS Memory Limit:64000KB 64bit IO Forma ...
- 本地无法启动MySQL服务,报的错误:1067,进程意外终止
在本地计算机无法启动MYSQL服务错误1067进程意外终止 这种情况一般是my.ini文件配置出错了 首先找到这个文件: 默认安装路径 C:/Program Files/MySQL/MySQL Ser ...
- Count the number of possible triangles
From: http://www.geeksforgeeks.org/find-number-of-triangles-possible/ Given an unsorted array of pos ...
- MySQL数据库1067 问题
1.MySql1067错误解决方法 http://blog.csdn.net/mhmyqn/article/details/17043921 MySql 1045解决方法 my.ini mysq ...
- mysql 在windows下,使用 net start mysql 命令发生错误 服务名无效 或 1067
mysql 在windows下,使用 net start mysql 命令发生错误 :服务名无效 或 1067 先使用mysqld -install安装一下 删除data目录下的日志等文件(因为之前 ...
- 启动mysql服务 报1067 错误
启动mysql 报1067 错误 一般报1067错误,先看一下data/my.ini配置文件 中的路径 datadir ,log-bin ,log-error 报1067错误原因 多种 ...
- win764位下安装mysql-5.6.22-x64启动服务报 系统错误 1067的解决办法
本人电脑win7,64位,需要安装mysql服务器.版本:mysql-5.6.22-x64.安装完成后,在服务里面并没有mysql.于是在百度上搜了下,好多信息,最后把解决方法自己总结下. 在${pr ...
- PAT 1067. Sort with Swap(0,*)
1067. Sort with Swap(0,*) (25) Given any permutation of the numbers {0, 1, 2,..., N-1}, it is easy ...
随机推荐
- 【第二十一章】 springboot + 定时任务
1.application.properties #cron job.everysecond.cron=0/1 * * * * * job.everytensecond.cron=0/10 * * * ...
- BZOJ1407: [Noi2002]Savage exgcd
Description Input 第1行为一个整数N(1<=N<=15),即野人的数目. 第2行到第N+1每行为三个整数Ci, Pi, Li表示每个野人所住的初始洞穴编号,每年走过的洞穴 ...
- npm教程_脚手架原理以及bootstrap引入
格式:vue init <templateName> <ProjectName> 例子:vue init webpack vue02 运行上面的命令后,脚手架帮忙按照webpa ...
- 1、webpack编译打包Sass编译的css进js文件
cnpm install css-loader --save-dev //css-loader 是将css打包进js cnpm install style-loader --save-dev ...
- VS2010下创建WEBSERVICE,第二天 ----你会在C#的类库中添加web service引用吗?
本文并不是什么高深的文章,只是VS2008应用中的一小部分,但小部分你不一定会,要不你试试: 本人对于分布式开发应用的并不多,这次正好有一个项目要应用web service,我的开发环境是vs2008 ...
- axis2框架用wsdl文件生成的服务端MessageReceiveInOut文件注意事项
在用axis2生成服务端文件和客户端文件,当客户端文件调用服务端文件时,都是通过wsdl文件生成的 配置文件进行相互的调用. 在一开始做开发测试的时候,通过soapUI进行调用接口的时候,可以调用成功 ...
- 【Coursera】Sixth Week(2)
DNS:Domain Name System The Domain Name System convert user-friendly names,like www.umich.edu, to net ...
- spring boot 捕获filter异常 统一返回处理结果
如前面的文章所述,controller中抛出的异常我们使用ControllerAdvice来处理: @RestControllerAdvice @Slf4j public class GlobalEx ...
- Goroutines和Channels(五)
Channels也可以用于将多个goroutine连接在一起,一个Channel的输出作为下一个Channel的输入.这种串联的Channels就是所谓的管道(pipeline).下面的程序用两个ch ...
- R-CNN(Rich feature hierarchies for accurate object detection and semantic segmentation)论文理解
论文地址:https://arxiv.org/pdf/1311.2524.pdf 翻译请移步: https://www.cnblogs.com/xiaotongtt/p/6691103.html ht ...