---
id: 702
lang: en
translation_of: index.md
source_sha256: e690c917fb62daf4c09f481897132c059f3690746b863c5d278e561a93595f69
title: "[Fortuna OJ] Three Lines — Solution"
description: "Three lines are either all parallel or two parallel and one perpendicular; a map of y-coordinate counts decides which works."
tags: ["OI","Coordinate Compression","Mapping"]
translated: 2026-11-27
translator: Claude Opus 5.5
translator_model: claude-opus-5-5
translation_notes:
  - "标化问题 rendered literally as “normalize the problem”."
---

## Main Idea

This is a problem that leans toward thinking; I guess in the eyes of <span class="slang" data-zh="巨佬" data-gloss="jùlǎo, “huge guy”. A very skilled contestant; used with admiration.">a big shot</span> it's the kind of problem that gets <span class="slang" data-zh="秒切" data-gloss="miǎo qiē, “cut in a second”. To solve a problem instantly, almost without thinking.">insta-solved</span>. We can split the three lines into two cases:

- All three lines are parallel
- Two are parallel, one is perpendicular

By transforming the $x,y$ coordinates we can normalize the problem, then use a map to record how many times each $y$ coordinate appears, and compare how the $y$ coordinates change before and after deleting one vertical line to make the call.

## Code

```cpp
// FOJ2929.cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1001000;
map<int, int> mp;
pair<int, int> pts[MAX_N];
int n, dist;
void add(int x)
{
    if (mp[x] == 0)
        dist++;
    mp[x]++;
}
void remove(int x)
{
    mp[x]--;
    if (mp[x] == 0)
        dist--;
}
bool judge()
{
    sort(pts + 1, pts + 1 + n);
    dist = 0, mp.clear();
    for (int i = 1; i <= n; i++)
        add(pts[i].second);
    if (dist <= 3)
        return true;
    int i = 1, i1 = 1;
    while (i <= n)
    {
        while (pts[i].first == pts[i1].first && i1 <= n)
            i1++;
        for (int i2 = i; i2 < i1; i2++)
            remove(pts[i2].second);
        if (dist <= 2)
            return true;
        for (int i2 = i; i2 < i1; i2++)
            add(pts[i2].second);
        i = i1;
    }
    return false;
}
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d%d", &pts[i].first, &pts[i].second);
    if (judge())
        puts("1");
    else
    {
        for (int i = 1; i <= n; i++)
            swap(pts[i].first, pts[i].second);
        if (judge())
            puts("1");
        else
            puts("0");
    }
    return 0;
}
```
