题目:
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

Input
3
0 0 5 5
0 5 5 0
0 5 5 0
Output
9
Input
1
0 0 4 3
Output
6
Input
2
0 0 4 3
1 0 3 3
Output
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的更多相关文章

  1. 2016-2017 National Taiwan University World Final Team Selection Contest

    A. Hacker Cups and Balls 二分答案,将$\geq mid$的数看成$1$,$<mid$的数看成$0$,用线段树进行区间排序检查即可.时间复杂度$O(n\log^2n)$. ...

  2. 2016-2017 National Taiwan University World Final Team Selection Contest (Codeforces Gym) 部分题解

      D 考虑每个点被删除时其他点对它的贡献,然后发现要求出距离为1~k的点对有多少个. 树分治+FFT.分治时把所有点放一起做一遍FFT,然后减去把每棵子树单独做FFT求出来的值. 复杂度$nlog^ ...

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

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

  5. sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)

    The Android University ACM Team Selection Contest Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里 ...

  6. 【转】2016/2017 Web 开发者路线图

    链接:知乎 [点击查看大图] 原图来自LearnCodeAcademy最火的视频,learncode是YouTube上最火的Web开发教学频道,介绍包括HTML/CSS/JavaScript/Subl ...

  7. Moscow Pre-Finals Workshop 2016. National Taiwan U Selection

    A. As Easy As Possible 每个点往右贪心找最近的点,可以得到一棵树,然后倍增查询即可. 时间复杂度$O((n+m)\log n)$. #include <bits/stdc+ ...

  8. Mindjet MindManager 2016/2017 折腾记录

    https://community.mindjet.com/mindjet/topics/ensure-2017-64-bit-version-installation Mindmanager sho ...

  9. [SinGuLaRiTy] COCI 2016~2017 #5

    [SinGuLaRiTy-1012] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 最近神犇喜欢考COCI...... 测试题目 对于所有的 ...

随机推荐

  1. Python爬虫(六)

    源码: import requests import re from my_mysql import MysqlConnect # 获取问答信息 def get_contents(page,heade ...

  2. 转载 -- iOS中SDK的简单封装与使用

    一.功能总述 在博客开始的第一部分,我们先来看一下我们最终要实现的效果.下图中所表述的就是我们今天博客中要做的事情,下方的App One和App Two都植入了我们将要封装的LoginSDK, 两个A ...

  3. 那些在BAE上部署node.js碰到的坑

    在BAE上使用node.js半年多了,其中碰到了不少因为BAE云环境限制碰到的坑 写下来大家碰到了,也不用那么麻烦的去看好几天代码了,直接对症下药 官方公布的坑有: BAE是使用package.jso ...

  4. 在Sql2000 sql2005 sql2008 下已能实现事务复制的强制订阅,但请求订阅始终不能实现总有下列错误提示

    硬件环境 : 一台服务器 安装了 sqlserver2008 数据库 局域网还有一台机器 安装了 sqlserver2000数据库 两台server 通信 共享均没有问题 同步过程中遇到的问题  : ...

  5. 第九篇:使用 AdaBoost 元算法提高分类器性能

    前言 有人认为 AdaBoost 是最好的监督学习的方式. 某种程度上因为它是元算法,也就是说它会是几种分类器的组合.这就好比对于一个问题能够咨询多个 "专家" 的意见了. 组合的 ...

  6. 【BZOJ3831】[Poi2014]Little Bird 单调队列

    [BZOJ3831][Poi2014]Little Bird Description In the Byteotian Line Forest there are   trees in a row. ...

  7. netty接收大文件的方法

    参考:http://blog.csdn.net/linuu/article/details/51371595 https://www.jianshu.com/p/a0a51fd79f62 netty默 ...

  8. JAVA编程你必须知道的那些英文单词

    第一章:  JDK(Java Development Kit) java开发工具包  JVM(Java Virtual Machine) java虚拟机  Javac  编译命令           ...

  9. CodeForces 24B F1 Champions(排序)

    B. F1 Champions time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  10. [iOS微博项目 - 4.5] - 每条微博的底部工具条

    github: https://github.com/hellovoidworld/HVWWeibo A.每条微博的底部工具条 1.需求 每条微博底部都有一个工具条 显示3个按钮:评论.转发.赞 按钮 ...