コード例 #1
0
ファイル: 1834.cpp プロジェクト: gutioliveira/Algorithms
    bool intersect(const Segment& s) const
    {
        auto d1 = D(A, B, s.A);
        auto d2 = D(A, B, s.B);

        if ((equals(d1, 0) && contains(s.A)) || (equals(d2, 0) && contains(s.B)))
            return true;

        auto d3 = D(s.A, s.B, A);
        auto d4 = D(s.A, s.B, B);

        if ((equals(d3, 0) && s.contains(A)) || (equals(d4, 0) && s.contains(B)))
            return true;

        return (d1 * d2 < 0) && (d3 * d4 < 0);
    }
コード例 #2
0
int main() {
    int64_t n, x0, y0;
    cin >> n >> x0 >> y0;
    Point p = {x0, y0};
    Segment ray = {p, {inf, y0 + 1}};

    vector<Point> points(n);
    for (int i = 0; i < n; i++) {
        Point p;
        cin >> p.x >> p.y;
        points[i] = p;
    }
    int count = 0;
    bool onBound = false;
    for (int i = 0; i < n; i++) {
        Segment s = {points[i], points[(i + 1) % n]};
        if (s.contains(p)) {
            onBound = true;
            break;
        }
        if (ray.intersects(s)) {
            count++;
        }
    }
    cout << (onBound || count % 2 == 1 ? "YES" : "NO") << endl;

    return 0;
}
コード例 #3
0
ファイル: mydata.cpp プロジェクト: pulsa/t.hex
bool HexDoc::ReplaceAt(uint64 ToReplaceIndex, uint32 ToReplaceLength, const uint8 *pReplaceWith, uint32 ReplaceWithLength)
{
    if (!CanReplaceAt(ToReplaceIndex, ToReplaceLength, ReplaceWithLength))
        return false;

    if (ToReplaceLength > ReplaceWithLength)
    {
        //! is this a good idea?
        RemoveAt(ToReplaceIndex + ReplaceWithLength, ToReplaceLength - ReplaceWithLength, SUPPRESS_UPDATE);
        ToReplaceLength = ReplaceWithLength;
    }

    // Quick optimization:
    // If affected range is entirely inside one writeable Segment and size doesn't change,
    // just write data.
    //! is this a good idea?
    uint64 segmentStart;
    Segment *ts = GetSegment(ToReplaceIndex, &segmentStart);
    if (ts && ts->type == Segment::MEM && ToReplaceLength == ReplaceWithLength)
    {
        if (ts->contains(ToReplaceIndex, ToReplaceLength, segmentStart))
        {
            memcpy(&ts->pData[ToReplaceIndex - segmentStart], pReplaceWith, ToReplaceLength);
            return true;
        }
    }

    if (!RemoveAt(ToReplaceIndex, ToReplaceLength, SUPPRESS_UPDATE))
        return false;
    if (!InsertAt(ToReplaceIndex, pReplaceWith, ReplaceWithLength, 1, SUPPRESS_UPDATE))
        return false;

/*    THSIZE lengthDiff = (THSIZE)ToReplaceLength - (THSIZE)ReplaceWithLength; // overflow doesn't matter
    for (size_t n = FindModified(ToReplaceIndex, true); n < modRanges.size(); n++)
    {
        ByteRange& tr = modRanges[n];
        if (tr.start > ToReplaceIndex)
            tr.start += lengthDiff;
        tr.end += lengthDiff;
    }*/

    m_iChangeIndex++;
    if (hw)
        hw->OnDataChange(ToReplaceIndex, ToReplaceLength, ReplaceWithLength);
    return true;
}
コード例 #4
0
ファイル: SegmentInformation.cpp プロジェクト: Aakash-729/vlc
static void insertIntoSegment(std::vector<Segment *> &seglist, size_t start,
                              size_t end, mtime_t time)
{
    std::vector<Segment *>::iterator segIt;
    for(segIt = seglist.begin(); segIt < seglist.end(); ++segIt)
    {
        Segment *segment = *segIt;
        if(segment->getClassId() == Segment::CLASSID_SEGMENT &&
           segment->contains(end + segment->getOffset()))
        {
            SubSegment *subsegment = new SubSegment(segment,
                                                    start + segment->getOffset(),
                                                    end + segment->getOffset());
            segment->addSubSegment(subsegment);
            segment->startTime.Set(time);
            break;
        }
    }
}
コード例 #5
0
ファイル: mydata.cpp プロジェクト: pulsa/t.hex
bool HexDoc::RemoveAt(uint64 nIndex, uint64 nSize, int flags /*= 0*/)
{
    if (!(flags & SUPPRESS_UPDATE) && !CanReplaceAt(nIndex, nSize, 0))
        return false;

    m_curSeg = NULL;

    if (nIndex == this->size)
        return nSize == 0;

    int n = FindSegment(nIndex), firstAffected = -1;
    THSIZE base = bases[n];
    const THSIZE removeSize = nSize; // nSize gets modified

    while (nSize)
    {
        Segment* ts = segments[n];
        if (ts->contains(nIndex - 1, base) && ts->contains(nIndex + nSize, base))
        { //---xxx---
            n++;
            Segment* ts2 = ts->RemoveMid(nIndex - base, nSize);
            InsertSegment2(n, nIndex, ts2);
            firstAffected = n + 1; // skip updating the newly inserted segment
            break;
        }
        else if (ts->contains(nIndex - 1, base))
        { // ---xxx
            nSize -= ts->size - (nIndex - base);
            ts->RemoveRight(nIndex - base);
            base += ts->size;
            firstAffected = n;
            n++;
        }
        else if (ts->contains(nIndex + nSize, base))
        { // xxx---
            ts->RemoveLeft(nSize);
            if (firstAffected == -1)
                firstAffected = n + 1;
            break;
        }
        else
        { // xxx
            nSize -= ts->size;
            delete ts;
            RemoveSegment(n);
            if (firstAffected == -1)
                firstAffected = n;
        }
    }

    m_iChangeIndex++;
    if (hw && !(flags & SUPPRESS_UPDATE))
        hw->OnDataChange(nIndex, removeSize, 0);

    if (firstAffected == -1)
        firstAffected = 0;
    for (n = firstAffected; n < (int)bases.size(); n++)
        bases[n] -= removeSize; //! this belongs somewhere else, or at least inside SUPPRESS_UPDATE check.

    this->size -= removeSize;

    return true;
}