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 + zipkin(brave定制-AsyncHttpClient)
brave本身没有对AsyncHttpClient提供类似于brave-okhttp的ClientRequestInterceptor和ClientResponseInterceptor,所以需要我们 ...
- 最常用的15大Eclipse开发快捷键技巧【转】
引言 做java开发的,经常会用Eclipse或者MyEclise集成开发环境,一些实用的Eclipse快捷键和使用技巧,可以在平常开发中节约出很多时间提高工作效率,下面我就结合自己开发中的使用和大家 ...
- 升级php7一些需要注意的地方
1.升级过程涉及代码的主要处理的就是几个扩展(mysql.mssql .mcrypt.ereg)使用到的一些废弃函数(call_user_method.call_user_method_array等) ...
- nodejs+gulpjs压缩js代码
1.安装node.js 下载地址:nodejs.org 或者 nodejs.cn 2.安装gulp之前我们需要安装nodejs的环境,检测能够正常使用npm后,我们用npm对gulp进行一次全局安 ...
- node 循序渐进
1. 执行 node helloworld.js 2. http 服务器 建 server.js 文件 - node server.js 跑起来 - 浏览器访问 http://localho ...
- mint18
ubuntu16.04用了一段时间,果然遇到祖传内部错误.然后虚拟机遇到2次重启后卡死在黑屏闪光标位置.但是用系统盘准备重装,执行到分区这步放弃,重启,居然有能启动. 作为开发机,实在有点胆战心惊,虽 ...
- 30分钟了解Shiro与Springboot的多Realm基础配置
写在前面的话: 我之前写过两篇与shiro安全框架有关的博文,居然能够广受欢迎实在令人意外.说明大家在互联网时代大伙对于安全和登录都非常重视,无论是大型项目还是中小型业务,普遍都至少需要登录与认证的逻 ...
- git/ssh备查文档
配置多个ssh key: 待更新 git速查表: git remote set-url origin(远程仓库名称) https://xxxxx/ProjectName.git 从ssh切换至htt ...
- 使用排序数组/链表/preorder构建二叉搜索树
2018-08-13 11:29:05 一.Convert Sorted Array to Binary Search Tree 问题描述: 问题求解: public TreeNode sortedA ...
- Failed to execute operation: No such file or directory(systemctl enable iptables.service)
在保存Iptables配置时:systemctl enable iptables.service 出现错误: Failed to execute operation: No such file or ...