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 ...
随机推荐
- 如何替换vi的配色方案
答: 1.获取配色方案 git clone git://github.com/altercation/vim-colors-solarized.git ~/.vim/bundle/vim-colors ...
- IDEA快捷键复习使用
https://www.jetbrains.com/help/idea/meet-intellij-idea.html 快捷键可以极快地进行代码编辑整理,在IDEA的快捷键中,除了有几个好像特别难按之 ...
- Cent OS 常用配置命令
1.ifconfig #查看网络接口状态 2.ifconfig –a #查看主机所有接口的情况 3.ifconfig eth0 192.168.1.106 netmask 255.255.255 ...
- ZOJ 3329 One Person Game (经典概率dp+有环方程求解)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3329 题意:现在有三个骰子,分别有k1,k2和k3面,面上的点就是1~ki ...
- SPOJ 375 Query on a tree(树链剖分)
https://vjudge.net/problem/SPOJ-QTREE 题意: 给出一棵树,树上的每一条边都有权值,现在有查询和更改操作,如果是查询,则要输出u和v之间的最大权值. 思路: 树链剖 ...
- 基于R进行相关性分析--转载
https://www.cnblogs.com/fanling999/p/5857122.html 一.相关性矩阵计算: [1] 加载数据: >data = read.csv("231 ...
- WPF基础学习笔记整理 (五) DependencyObject & DependencyProperty
参考资料: 1.http://www.cnblogs.com/Zhouyongh/archive/2009/10/20/1586278.html 基础知识: DependencyObject & ...
- Window系统下用Ant实现Java项目的自动构建和部署
https://blog.csdn.net/xinxin19881112/article/details/7297021 Step 1: 从官网下载Ant包,官网地址http://ant.apache ...
- Django2.0 URL配置
一.实例 先看一个例子: from django.urls import path from . import views urlpatterns = [ path('articles/2003/', ...
- [原][译][lua][luabridge]一个简单的luabridge与c++例子结合例子
参考:https://eliasdaler.wordpress.com/tag/luabridge/ https://eliasdaler.wordpress.com/2015/08/10/using ...