TZOJ 2519 Regetni(N个点求三角形面积为整数总数)
描述
Background
Hello Earthling. We're from the planet Regetni and need your help to make lots of money. Maybe we'll even give you some of it.
You
see, the problem is that in our world, everything is about integers.
It's even enforced by law. No other numbers are allowed for anything.
That said, it shouldn't surprise you that we use integer coordinate
systems to plan our cities. So far only axis-aligned rectangular plots
of land have been sold, but our professor Elgnairt recently had the
revolutionary idea to sell triangular plots, too. We believe that the
high society will love this concept and it'll make us rich.
Unfortunately
the professor patented his idea and thus we can't just do it. We need
his permission and since he's a true scientist, he won't give it to us
before we solve some damn riddle. Here's where you come in,because we
heard that you're a genius.
Problem
The professor's riddle
goes like this: Given some possible corners for the triangles, determine
how many triangles with integral size can be built with them.
Degenerated triangles with empty area (i.e. lines) have to be counted,
too, since 0 is an integer. To be more precise, count the number of
triangles which have as corners three different points from the input
set of points. All points in a scenario will be distinct, i.e. there
won't be duplicates. Here are some examples:
Example
a) shows a triangle with integral area (namely 3), b) shows one with
non-integral size, c) shows a degenerated triangle with empty area (i.e.
zero, so count it!), d) shows four points of which you can choose any
three to build an integral area triangle and e) shows four points where
you can't build any integral area triangles at all.
Hint: The area A of a triangle with corners (x1, y1), (x2, y2) and (x3, y3) can be computed like this:
A=|x1y2 - y1x2 + x2y3 - y2x3 + x3y1 - y3x1|/2
Try to make clever use of this formula.
输入
The
first line contains the number of scenarios. For each scenario, there
is one line containing first the number N of distinct points in that
scenario (0 <= N <= 10000) and after that N pairs of integers,
each pair describing one point (xi, yi) with -100000 <= xi, yi <=
100000. All these numbers are separated by single blanks.
输出
Start
the output for every scenario with a line containing "Scenario #i:",
where i is the number of the scenario starting at 1. Then print a single
line containing the number of triangles with integral area whose three
distinct corners are among the points given. Terminate the output for
each scenario with a blank line.
样例输入
6
3 0 0 2 0 1 -3
3 0 0 2 1 1 -3
3 0 0 2 2 3 3
4 0 0 2 0 0 2 2 2
4 0 0 1 0 0 1 1 1
9 0 0 0 1 0 2 1 0 1 1 1 2 2 0 2 1 2 2
样例输出
Scenario #1:
1
Scenario #2:
0
Scenario #3:
1
Scenario #4:
4
Scenario #5:
0
Scenario #6:
48
题意
给你N个点,求三角形面积为整数的总数
题解
A=|x1y2 - y1x2 + x2y3 - y2x3 + x3y1 - y3x1|/2
要使公式为整数,|x1y2 - y1x2 + x2y3 - y2x3 + x3y1 - y3x1|为偶
三个点P(x1,y1),Q(x2,y2),C(x3,y3)
可以发现上面的公式和PQC三点的x和y的奇偶性有关
令0=x偶y偶,1=x偶y奇,2=x奇y偶,3=x奇y奇。
打表完后利用组合数求个和。
代码
#include<bits/stdc++.h>
using namespace std; struct point
{
int p,q,c;
bool operator<(const point &d)const{
if(p<d.p)return true;
else if(p==d.p)
{
if(q<d.q)return true;
else if(q==d.q)
{
if(c<d.c)return true;
}
}
return false;
}
};
set<point>v;
void cs()
{
pair<int,int>po[];
po[]={,};
po[]={,};
po[]={,};
po[]={,};
for(int p=;p<;p++)
for(int q=;q<;q++)
for(int c=;c<;c++)
{
int x1,x2,x3,y1,y2,y3;
x1=po[p].first;y1=po[p].second;
x2=po[q].first;y2=po[q].second;
x3=po[c].first;y3=po[c].second;
if((x1*y2-y1*x2+x2*y3-y2*x3+x3*y1-y3*x1)%==)
{
int d[];
d[]=p;
d[]=q;
d[]=c;
sort(d,d+);
v.insert({d[],d[],d[]});
}
}
}
long long C(int n,int m)
{
if(m>n)return ;
long long sum=;
for(int i=;i<=m;i++)
sum=sum*(n-i+)/i;
return sum;
}
int main()
{
cs();
int t,n,ca=;
scanf("%d",&t);
while(t--)
{
int d[]={};
scanf("%d",&n);
for(int i=;i<n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
if(x%==&&y%==)d[]++;
if(x%==&&y%!=)d[]++;
if(x%!=&&y%==)d[]++;
if(x%!=&&y%!=)d[]++;
}
long long sum=;
for(auto x:v)
{
int p=x.p;
int q=x.q;
int c=x.c;
printf("%d %d %d\n",p,q,c);
int f[]={};
f[p]++;f[q]++;f[c]++;
sum+=C(d[],f[])*C(d[],f[])*C(d[],f[])*C(d[],f[]);
}
printf("Scenario #%d:\n%lld\n\n",ca++,sum);
}
return ;
}
TZOJ 2519 Regetni(N个点求三角形面积为整数总数)的更多相关文章
- UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)
Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...
- hdu 4709:Herding(叉积求三角形面积+枚举)
Herding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- Maximal Area Quadrilateral CodeForces - 340B || 三点坐标求三角形面积
Maximal Area Quadrilateral CodeForces - 340B 三点坐标求三角形面积(可以带正负,表示向量/点的不同相对位置): http://www.cnblogs.com ...
- hdu4709求三角形面积
Herding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- HDU 2036 叉乘求三角形面积
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s) ...
- golang实现已知三角形三点坐标,求三角形面积
代码如下: func GetTriangleAreaByVector(x vector.Vector3,y vector.Vector3,z vector.Vector3) float64 { //根 ...
- 【C语言】已知三角形三边长,求三角形面积
一. 数学基础: 已知三角形的三边,计算三角形面积,需要用到海伦公式: 即p=(a+b+c)/2 二. 算法: 输入三个边长,套用海伦公式计算面积,并输出. 可以先判断是否可以构成三角形,即任意两边之 ...
- java求三角形面积以及周长---封装
/*时间: 2012-10-08作者: 烟大程序要求: 1.封装一类三角形对象Triangle,该类对象具有三条边的属性, 具有初始化三角形的功能.修改边长的功能.判断三条边能否构成三角形的功能. 求 ...
- POJ 2954 /// 皮克定理+叉积求三角形面积
题目大意: 给定三角形的三点坐标 判断在其内部包含多少个整点 题解及讲解 皮克定理 多边形面积s = 其内部整点in + 其边上整点li / 2 - 1 那么求内部整点就是 in = s + 1 - ...
随机推荐
- Nuget调用简单封装.
1. 项目引用Dapper作为直接访问, 为了使用方便, 封装一下.达到效果: - 数据库连接配置在webconfig.xml中. - 常用调用方法封装. 调用: //可以采用单例模式. //全局实 ...
- hex转mif文件 verilog
用FPGA来跑ARM 核的时候,刚开始将Keil编译产生的hex文件拿来仿真和下到板子上的时候,发现程序运行不正确.细细观察仿真波形发现,在Altera的ROM IP中直接调用Keil产生的hex文件 ...
- android 中activity重启的方法
private void reLoadActivity(){ Intent intent = new Intent(context, SettingsActivity.class); intent.s ...
- memset与fill的区别
简介与区别 memset函数 按照字节填充某字符 在头文件<cstring>里面 fill函数 按照单元赋值,将一个区间的元素都赋同一个值 在头文件<algorithm>里面 ...
- [STM31F103]独立看门狗
独立看门狗步骤: l 取消寄存器写保护: n IWDG_WriteAccessCmd(); l 设置独立看门狗的预分频系数,确定时钟: n IWDG_SetPrescaler(); l 设置看门狗重装 ...
- HTML中的坐标系及其在MouseEvent和元素Box中的应用
HTML中的坐标系及其在MouseEvent和元素中的应用 HTML有四个坐标系统: Screen, Page,Client和offset, 用于描述DOM元素的Box尺寸和MouseEvent中的位 ...
- Python 内置函数math,random
内置函数的一些操作 - math(数学模块) - random(随机模块) - 使用内置函数时注意需要导入 math - (ceil)向上取整,返回取整数 # 向上取整,返回向上取整的数 import ...
- 《2018面向对象程序设计(Java)课程学习进度条》
周次 (阅读/编写)代码行数 发布博客量/博客评论数量 课堂/课余学习时间(小时) 最满意的编程任务 第一周 50/40 1/0 6/4 九九乘法表 第二周 100/80 1/0 6/8 实验5,6, ...
- ucos之互斥信号量及优先级反转
在ucos常使用共享资源来作为任务之间的通信方式,其中有:消息队列,信号量,邮箱,事件.信号量中又分二值信号,多值信号,互斥信号.这次主要讲二值信号与互斥信号之间区别和使用. 首先了解一下ucos的任 ...
- python学习笔记---环境的安装,pip命令,数据类型,运算
1.进入python环境: python 2:py -2 python 3:py -3 2.退出python环境 exit()/quit()/ctrl+z+enter ctrl+z+enter没有尝试 ...