codeforces 183B - Zoo
/*
题意:给出n,m。
n表示给出的n个横坐标为1-n,y为0的坐标m表示以下有m个坐标,在横坐标上的点
向各个角度看,在可以看到最多的点在同一条直线上的点的做多值为横坐标这一点的值,最后各个
横坐标的值的和为多少
思路:由于m的值为枚举随意的两个点连成的直线,看在直线上的点有多少,看这条线和横坐标的值为
多少。是否是整值点。假设是就记录这个整值点的最大值
*/
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6 +5;
const double eps =1e-3;
int b[maxn];
struct Point
{
double x,y;
Point(double x=0,double y=0):x(x),y(y) {}
};
typedef Point Vector;
Vector operator - (Point A,Point B)
{
return Vector(A.x-B.x,A.y-B.y);
}
Vector operator +(Vector A,Vector B)
{
return Vector(A.x+B.x,A.y+B.y);
}
Vector operator * (Vector A,double p)
{
return Vector(A.x*p,A.y*p);
}
double Cross(Vector A,Vector B)
{
return A.x*B.y-A.y*B.x;
}
int dcmp(double x)
{
if(fabs(x)<eps) return 0;
return x>eps?
1:-1;
}
struct Line
{
Point p;
Vector v;
};
int GetLineIntersection(Line L1,Line L2)
{
if(dcmp(Cross(L1.v,L2.v))==0)
return 0;
Vector u=L1.p-L2.p;
int t=Cross(L2.v,u)/Cross(L1.v,L2.v);
Point answer;
answer=L1.p+L1.v*t;
int temp=(int)(answer.x+0.5);
if(dcmp(answer.x)>0&&dcmp(answer.x-temp)==0&&dcmp(answer.y)==0&&temp<=1000000)
return temp;
return 0;
}
int main()
{
int n,m;
Point a[300];
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(b,0,sizeof(b));
for(int i=0; i<m; i++)
scanf("%lf%lf",&a[i].x,&a[i].y);
Line ox;
ox.p.x=0;
ox.p.y=0;
ox.v.x=1;
ox.v.y=0;
Line l1;
for(int i=0; i<m; i++)
{
for(int j=i+1; j<m; j++)
{
int have=2;
for(int k=j+1; k<m; k++)
{
if(dcmp(Cross(a[i]-a[j],a[k]-a[j]))==0)
have++;
}
l1.p=a[i];
l1.v=a[i]-a[j];
int flag=GetLineIntersection(ox,l1);
if(flag)
{
a[299].x=flag;
a[299].y=0;
if(dcmp(Cross(a[i]-a[j],a[299]-a[j]))==0)
b[flag]=max(b[flag],have);
}
}
}
int sum=0;
for(int i=1; i<=n; i++)
if(b[i])
sum+=b[i];
else
sum++;
cout << sum << endl;
}
return 0;
}
codeforces 183B - Zoo的更多相关文章
- Codeforces Round #250 (Div. 1) B. The Child and Zoo 并查集
B. The Child and Zoo Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/438/ ...
- Codeforces 437D The Child and Zoo(贪心+并查集)
题目链接:Codeforces 437D The Child and Zoo 题目大意:小孩子去參观动物园,动物园分非常多个区,每一个区有若干种动物,拥有的动物种数作为该区的权值.然后有m条路,每条路 ...
- Codeforces 437D The Child and Zoo - 树分治 - 贪心 - 并查集 - 最大生成树
Of course our child likes walking in a zoo. The zoo has n areas, that are numbered from 1 to n. The ...
- Codeforces Round #359 (Div. 2) B. Little Robber Girl's Zoo 水题
B. Little Robber Girl's Zoo 题目连接: http://www.codeforces.com/contest/686/problem/B Description Little ...
- Codeforces 437D The Child and Zoo(并查集)
Codeforces 437D The Child and Zoo 题目大意: 有一张连通图,每个点有对应的值.定义从p点走向q点的其中一条路径的花费为途径点的最小值.定义f(p,q)为从点p走向点q ...
- Codeforces Round#250 D. The Child and Zoo(并差集)
题目链接:http://codeforces.com/problemset/problem/437/D 思路:并差集应用,先对所有的边从大到小排序,然后枚举边的时候,如果某条边的两个顶点不在同一个集合 ...
- Codeforces 437 D. The Child and Zoo 并查集
题目链接:D. The Child and Zoo 题意: 题意比较难懂,是指给出n个点并给出这些点的权值,再给出m条边.每条边的权值为该条路连接的两个区中权值较小的一个.如果两个区没有直接连接,那么 ...
- Codeforces D - The Child and Zoo
D - The Child and Zoo 思路: 并查集+贪心 每条边的权值可以用min(a[u],a[v])来表示,然后按边的权值从大到小排序 然后用并查集从大的边开始合并,因为你要合并的这两个联 ...
- Codeforces Round #250 (Div. 2) D. The Child and Zoo 并查集
D. The Child and Zoo time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
随机推荐
- [BZOJ 4060] Word Equations
Link: BZOJ 4060 传送门 Solution: 可以发现字符串间的关系可以构成一棵树 于是我们先用字符串哈希建树,再树形$dp$即可 设$dp[i][j]$为第$i$个节点从$P$字符串的 ...
- POJ 3688 Cheat in the Game(博弈论)
[题目链接] http://poj.org/problem?id=3688 [题目大意] 有俩人玩一个取石子的游戏,你是裁判. 游戏中有W块石头和N张卡片,卡片上分别写着数字Ai. 玩家随机抽走一张卡 ...
- 【点分治】bzoj1468 Tree
同poj1741. 换了个更快的姿势,不会重复统计然后再减掉什么的啦~ #include<cstdio> #include<algorithm> #include<cst ...
- python中json与dict之间转换
Python之dict(或对象)与json之间的互相转化 在Python语言中,json数据与dict字典以及对象之间的转化,是必不可少的操作. 在Python中自带json库.通过import js ...
- 收藏起来,史上最全的 MySQL 高性能优化实战总结!
转自:https://mp.weixin.qq.com/s/sRsJzFO9dPtKhovJNWN3Dg 一.前言 MySQL 对于很多 Linux 从业者而言,是一个非常棘手的问题,多数情况都是因为 ...
- 爬取维基百科人物介绍,并使用pymysql存储到数据库
代码如下: from urllib.request import urlopen from bs4 import BeautifulSoup import re import datetime imp ...
- Android Studio 生成aar包多Module引用问题
问题描述: 有个arr文件被放到Module A中引用,现在Module B又依赖了Module A,则在编译过程中会发生错误,Module B找不到aar文件. 解决办法: 使用相对路径来找到这个a ...
- 继续推荐几款VisualStudio的插件(二)
今天晚上闲着的时候逛了一下,发现了几款不错的VisualStudio插件,这里推荐一下: Exception Breaker 在调试的时候,为了及时发现错误,我们常常会打开"总是引发所有CL ...
- golang之bufio包的使用
原文地址:http://www.niu12.com/article/38 github地址:https://github.com/ZQCard/go_api_practice // 参考:https: ...
- EL表达式介绍(1)
1. 产生背景: 在MVC体系结构中,JSP页面只是用来显示数据,但JSP脚本中的表达式功能不够强大,它不能直接对隐式对象中某对象的属性进行显示,需要配合 scriptlet才能显示数据,很是麻烦,如 ...