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 ...
随机推荐
- C#中的异步编程模式
异步编程模型(APM) 基于事件的异步编程模式 基于任务的异步模式 Async Await编程 关于C#,可以看看Learning Hard的博客
- css布局一屏幕的自适应高度
css ;;list-style: none;} .top{height: 100px;background-color:orange;} .max{;background-color:skyblue ...
- 每个成长者,必须学会可以练习 (来自ProcessOn流程图工具作者底部)
- UVa 11039 设计建筑物
https://vjudge.net/problem/UVA-11039 题意: 有n个绝对值各不相同的非0整数,选出尽量多的数,排成一个序列,使得正负号交替且绝对值递增. 思路:正数存一个数组,负数 ...
- LINK : fatal error LNK1104: 无法打开文件“libboost_serialization-vc90-mt-gd-1_62.lib”
boost安装:https://www.cnblogs.com/sea-stream/p/10205425.html 在vs中添加
- shell while 语句
普通循环格式: while condition do command done 例子一 #!/bin/bash )) do echo $int let "int++" done 结 ...
- Codeforces 847E - Packmen
847E - Packmen 思路:二分时间. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long ...
- 一分钟搞定:spring boot 热部署 (基于Idea)
什么是热部署? 对于spring boot项目,修改后台的java类,不要重启整个项目,就可以测试/使用刚修改的功能! 怎么为项目添加/设置热部署 maven项目在pom.xml添加下方代码,联网引入 ...
- Kilani and the Game CodeForces - 1105D (bfs)
沙茶bfs打了2小时... queue入队量太大了, 放函数里直接T了, 改成全局46ms #include <iostream> #include <algorithm> # ...
- Codeword CodeForces - 666C (字符串计数)
链接 大意:求只含小写字母, 长度为n, 且可以与给定模板串匹配的字符串个数 (多组数据) 记模板串为P, 长为x, 总串为S. 设$f_i$为S为i时的匹配数, 考虑P最后一位的首次匹配位置. 若为 ...