2016-2017 National Taiwan University World Final Team Selection Contest C - Crazy Dreamoon
题目:
Statements
Dreamoon likes algorithm competitions very much. But when he feels crazy because he cannot figure out any solution for any problem in a competition, he often draws many meaningless straight line segments on his calculation paper.
Dreamoon's calculation paper is special: it can be imagined as the plane with Cartesian coordinate system with range [0, 2000] × [0, 2000] for the coordinates. The grid lines are all lines of the form x = c or y = c for every integer c between 0 and 2000, inclusive. So, the grid contains 2000 × 2000 squares.
Now, Dreamoon wonders how many grid squares are crossed by at least one of the lines he drew. Please help Dreamoon find the answer. Note that, to cross a square, a segment must contain an interior point of the square.
Input
The first line of input contains an integer N denoting the number of lines Dreamoon draw. The i-th line of following N lines contains four integers xi1, yi1, xi2, yi2, denoting that the i-th segment Dreamoon drew is a straight line segment between points (xi1, yi1) and (xi2, yi2).
- 1 ≤ N ≤ 2 × 103
- 0 ≤ xi1, yi1, xi2, yi2 ≤ 2 × 103
- the lengths of all line segments in input are non-zero
Output
Output one integer on a single line: how many grid squares are crossed by at least one of the line segments which Dreamoon drew.
Example
3
0 0 5 5
0 5 5 0
0 5 5 0
9
1
0 0 4 3
6
2
0 0 4 3
1 0 3 3
6 思路:
直接通过枚举y来判断直线经过哪些方格,vis标记下即可。
这题好像精度挺重要的。。。。
#include <bits/stdc++.h> using namespace std; #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; int vis[][];
struct Point
{
double x,y;
};
void solve(void)
{
Point st,se;
scanf("%lf%lf%lf%lf",&st.x,&st.y,&se.x,&se.y);
if(fabs(st.x-se.x)<eps||fabs(st.y-se.y)<eps) return;
if(st.y>se.y) swap(st,se);
double k=(se.x-st.x)/(se.y-st.y),b=st.x-k*st.y;
double tmp;
if(k>)
{
for(int i=se.y-,mx,mi;i>=st.y;i--)
{
tmp=(i+)*k+b;
mi=floor(i*k+b);
if(fabs(tmp-floor(tmp))<=eps)mx=max(,(int)tmp-);
else mx=(int)tmp;
if(mi<) while();
while(mi<=mx)
vis[mi++][i]=;
}
}
else
{
for(int i=st.y+,mx,mi;i<=se.y;i++)
{
tmp=(i-)*k+b;
mi=floor(i*k+b);
if(fabs(tmp-floor(tmp))<=eps)mx=max(,(int)tmp-);
else mx=(int)tmp;
if(mi<) while();
while(mi<=mx)
vis[mi++][i-]=;
}
}
}
int main(void)
{
int n,cnt=;
scanf("%d",&n);
for(int i=;i<=n;i++)
solve();
for(int i=;i<;i++)
for(int j=;j<;j++)
cnt+=vis[i][j];
printf("%d\n",cnt);
return ;
}
2016-2017 National Taiwan University World Final Team Selection Contest C - Crazy Dreamoon的更多相关文章
- 2016-2017 National Taiwan University World Final Team Selection Contest
A. Hacker Cups and Balls 二分答案,将$\geq mid$的数看成$1$,$<mid$的数看成$0$,用线段树进行区间排序检查即可.时间复杂度$O(n\log^2n)$. ...
- 2016-2017 National Taiwan University World Final Team Selection Contest (Codeforces Gym) 部分题解
D 考虑每个点被删除时其他点对它的贡献,然后发现要求出距离为1~k的点对有多少个. 树分治+FFT.分治时把所有点放一起做一遍FFT,然后减去把每棵子树单独做FFT求出来的值. 复杂度$nlog^ ...
- 2016-2017 National Taiwan University World Final Team Selection Contest J - Zero Game
题目: You are given one string S consisting of only '0' and '1'. You are bored, so you start to play w ...
- 2016-2017 National Taiwan University World Final Team Selection Contest A - Hacker Cups and Balls
题目: Dreamoon likes algorithm competitions very much. But when he feels crazy because he cannot figur ...
- sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)
The Android University ACM Team Selection Contest Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里 ...
- 【转】2016/2017 Web 开发者路线图
链接:知乎 [点击查看大图] 原图来自LearnCodeAcademy最火的视频,learncode是YouTube上最火的Web开发教学频道,介绍包括HTML/CSS/JavaScript/Subl ...
- Moscow Pre-Finals Workshop 2016. National Taiwan U Selection
A. As Easy As Possible 每个点往右贪心找最近的点,可以得到一棵树,然后倍增查询即可. 时间复杂度$O((n+m)\log n)$. #include <bits/stdc+ ...
- Mindjet MindManager 2016/2017 折腾记录
https://community.mindjet.com/mindjet/topics/ensure-2017-64-bit-version-installation Mindmanager sho ...
- [SinGuLaRiTy] COCI 2016~2017 #5
[SinGuLaRiTy-1012] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 最近神犇喜欢考COCI...... 测试题目 对于所有的 ...
随机推荐
- 【mysql-python】安装+基本使用
安装:从SourceForge.net上下载最新的MySQLdb,http://sourceforge.net/projects/mysql-python/ 运行exe文件 使用 From:http: ...
- 电脑端与iPad 端如何共享ChemDraw结构
在日常生活中,我们使用的电脑会有好几种系统,很多的软件不能做好各个系统的兼容.但是ChemDraw软件很好的解决了这个问题,可以应用于Mac.Windows两个电脑客户端以及Chem3D for iP ...
- MathType中空格个数怎么显示
在使用Word文档的时候很时候用原软件自带的公式编辑器不是很好用,也不方法.MathType就是来解决这个问题的,但是一些用户在使用过程中发现不会看究竟输了多少空格,只能估摸大概.下面本MathTyp ...
- 数据降维PCA——学习笔记
PCA主成分分析 无监督学习 使方差(数据离散量)最大,更易于分类. 可以对隐私数据PCA,数据加密. 基变换 投影->内积 基变换 正交的基,两个向量垂直(内积为0,线性无关) 先将基化成各维 ...
- Makefile foreach(转)
原文出处:http://blog.csdn.net/cjsycyl/article/details/8064871 foreach 函数和别的函数非常的不一样.因为这个函数是用来做循环用的,Makef ...
- 教你在Ubuntu上体验Mac风格
导读 老实说,我是个狂热的 Ubuntu 迷,我喜欢 Ubuntu 默认的 Unity 主题样式外观.此外,还有很多关于 Ubuntu 14.04 的漂亮图标主题样式 可用来美化默认的外观.但正如我上 ...
- Layui前后台交互数据获取java
Layui简介 Layui是一款适用于后台程序员的UI框架,学习成本低.Json数据格式交互前后台,并且也相当适用单页面开发.有兴趣的朋友可以看看layui官网. Layui前后台数据交互 layui ...
- 使用Mac App Store更新、下载软件时出现未知错误的解决方法
很多果迷在使用 Mac App Store 更新/下载软件时,可能都曾被”未知错误”困扰过,怎么解决也不行.然而,过一段时间不知道做了什么又自己好了.今天我们提供两个解决这个问题的方法,下次遇到这个问 ...
- Imageview如何设置背景颜色
ImageView.setBackgroundColor(android.graphics.Color.parseColor("#ffffff")); ImageView.setB ...
- SPS读书笔记1——均值比较(T检验,方差检验,非参数检验汇总)
均值比较.单样本T检验(One-sample Test))目的:检验单个变量的均值与给定的某个常数是否一致.)判断标准:p<0.05;t>1.98即认为是有显著差异的..独立样本T检验(I ...