Problem Description

已知一个圆的圆周被N个点分成了N段等长圆弧,求任意取三个点,组成锐角三角形的个数。

Input

多组数据,每组数据一个N(N <= 1000000)

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;



  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <algorithm>
  4. using namespace std;
  5. #define ll long long
  6. int main()
  7. {
  8. ll n,k,ans;
  9. while(~scanf("%lld",&n))
  10. {
  11. if(n<3)
  12. ans = 0;
  13. else if(n%2)
  14. ans = (1+n/2)*(n/2)*n/6;
  15. else
  16. ans = (n/2-2)*(n/2-1)*n/6;
  17. printf("%lld\n",ans);
  18. }
  19. return 0;
  20. }

ACdream 1067:Triangles的更多相关文章

  1. acdream.Triangles(数学推导)

    Triangles Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit Stat ...

  2. acdream.A Very Easy Triangle Counting Game(数学推导)

    A - A Very Easy Triangle Counting Game Time Limit:1000MS     Memory Limit:64000KB     64bit IO Forma ...

  3. 本地无法启动MySQL服务,报的错误:1067,进程意外终止

    在本地计算机无法启动MYSQL服务错误1067进程意外终止 这种情况一般是my.ini文件配置出错了 首先找到这个文件: 默认安装路径 C:/Program Files/MySQL/MySQL Ser ...

  4. Count the number of possible triangles

    From: http://www.geeksforgeeks.org/find-number-of-triangles-possible/ Given an unsorted array of pos ...

  5. MySQL数据库1067 问题

    1.MySql1067错误解决方法 http://blog.csdn.net/mhmyqn/article/details/17043921   MySql 1045解决方法 my.ini  mysq ...

  6. mysql 在windows下,使用 net start mysql 命令发生错误 服务名无效 或 1067

    mysql 在windows下,使用 net start mysql 命令发生错误 :服务名无效 或 1067  先使用mysqld -install安装一下 删除data目录下的日志等文件(因为之前 ...

  7. 启动mysql服务 报1067 错误

    启动mysql 报1067 错误         一般报1067错误,先看一下data/my.ini配置文件 中的路径 datadir ,log-bin ,log-error 报1067错误原因 多种 ...

  8. win764位下安装mysql-5.6.22-x64启动服务报 系统错误 1067的解决办法

    本人电脑win7,64位,需要安装mysql服务器.版本:mysql-5.6.22-x64.安装完成后,在服务里面并没有mysql.于是在百度上搜了下,好多信息,最后把解决方法自己总结下. 在${pr ...

  9. 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 ...

随机推荐

  1. C#中的异步编程模式

    异步编程模型(APM) 基于事件的异步编程模式 基于任务的异步模式 Async Await编程 关于C#,可以看看Learning Hard的博客

  2. css布局一屏幕的自适应高度

    css ;;list-style: none;} .top{height: 100px;background-color:orange;} .max{;background-color:skyblue ...

  3. 每个成长者,必须学会可以练习 (来自ProcessOn流程图工具作者底部)

  4. UVa 11039 设计建筑物

    https://vjudge.net/problem/UVA-11039 题意: 有n个绝对值各不相同的非0整数,选出尽量多的数,排成一个序列,使得正负号交替且绝对值递增. 思路:正数存一个数组,负数 ...

  5. LINK : fatal error LNK1104: 无法打开文件“libboost_serialization-vc90-mt-gd-1_62.lib”

    boost安装:https://www.cnblogs.com/sea-stream/p/10205425.html 在vs中添加

  6. shell while 语句

    普通循环格式: while condition do command done 例子一 #!/bin/bash )) do echo $int let "int++" done 结 ...

  7. Codeforces 847E - Packmen

    847E - Packmen 思路:二分时间. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long ...

  8. 一分钟搞定:spring boot 热部署 (基于Idea)

    什么是热部署? 对于spring boot项目,修改后台的java类,不要重启整个项目,就可以测试/使用刚修改的功能! 怎么为项目添加/设置热部署 maven项目在pom.xml添加下方代码,联网引入 ...

  9. Kilani and the Game CodeForces - 1105D (bfs)

    沙茶bfs打了2小时... queue入队量太大了, 放函数里直接T了, 改成全局46ms #include <iostream> #include <algorithm> # ...

  10. Codeword CodeForces - 666C (字符串计数)

    链接 大意:求只含小写字母, 长度为n, 且可以与给定模板串匹配的字符串个数 (多组数据) 记模板串为P, 长为x, 总串为S. 设$f_i$为S为i时的匹配数, 考虑P最后一位的首次匹配位置. 若为 ...