National Day make mention two

naipc 2019

This question need to use scan lines of thought.

First, we save something with structure, it is stored on the bottom of the rectangle

This is what we read in each pair of coordinates, there

b [++ tot] = {x1 , x2, y1, -1} following an

b [++ tot] = {x1 , x2, y2,1} above a

Then we have the basis of this y from small to large order so down, it can be seen as the following screen

 

That this -1 , 1 action, with the segment tree is used to

For example, we now have a rectangular shape, as shown, is read into the first, we will update, the segment tree contains the coordinates 3 , 4 at this point

Value of -1 ;

Then the second side is read, update 3 , 4 , a value of 1 , and it will find the interval to 0 , the interval, and that is not 0 , it shows that other sides of the rectangle to the insertion of an idea to insert ,

Also known as intersected.

If this is not merely judged not to include the contents of this state, which is the subject of this case is not to say the following,

 

So we are single-point update, so that when other lines of inquiry this line needs to include live below the line of coordinates, check out this will have is not equal to 0 value, which is expressed intersection

Then is his coordinates too wide, so we have to discrete at the x -coordinate.

Then is,

First query and then update the bottom edge, the top edge of the query would have to re-update query.

If you imagine a lower base of inquiry after the update no sense, then the top edge is used to offset a rectangular section, so we have to update the query again

/

G - Intersecting Rectangles 

that Italy: Given n vertex coordinate values of the rectangle do not overlap, and asked whether the intersection has a rectangular (including not included). 

Solution: tree line scan lines. Each rectangle is split into upper and lower two lines, the lower end points of the line of +1, of the upper end points of the line 1. If a sweep line discovery interval is not zero, then the intersection. We need to coordinate discrete. 

#include <Vector> 
#include <cstdio> 
#include <algorithm> 
#define fopi The freopen ( "in.txt", "R & lt", stdin) 
#define fopo The freopen ( "out.txt", "W", stdout) 
the using STD namespace; 
typedef Long Long LL; 
typedef Long Double LD; 
const int = 2E5 + MAXN 10; 

struct Seg { 
    int L, R & lt, H, ID; 
    BOOL operator <(const Seg & RHS) { 
        return H <rhs.h; 
    } 
}; 
Vector <Seg> S; 
Vector <int> V;

    }t[maxn*4];

    void build(int id, int l, int r) {
        t[id].l = l, t[id].r = r;
        if (l == r) return;
        int mid = (l+r) / 2;
        build(id*2, l, mid);
        build(id*2+1, mid+1, r);
    }

    void update(int id, int x, int val) {
        if (t[id].l == t[id].r) { t[id].sum += val; return;}
        int mid = (t[id].l + t[id].r) / 2;
        if (x <= mid) update(id*2, x, val);
        else update(id*2+1, x, val);
        t[id].sum = t[id*2].sum + t[id*2+1].sum;
    }

    int query(int id, int l, int r) {
        if (t[id].l == l && t[id].r == r) return t[id].sum;
        int mid = (t[id].l + t[id].r) / 2;
        if (r <= mid) return query(id*2, l, r);
        else if (l > mid) return query(id*2+1, l, r);
        else return query(id*2, l, mid) + query(id*2+1, mid+1, r);
    }
}ST;

bool cmp(Seg a, Seg b) {
    return a.h < b.h;
}

int n, x1, y1, x2, y2;
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
        S.push_back({x1, x2, y1, 1});
        S.push_back({x1, x2, y2, -1});
        V.push_back(x1), V.push_back(x2);
    }

    n *= 2;

    ST.build(1, 1, n);

    sort(S.begin(), S.end(), cmp);
    sort(V.begin(), V.end());

    int ans = 0;
    for (auto s : S) {
        int x = lower_bound(V.begin(), V.end(), s.l) - V.begin() + 1,
            y = lower_bound(V.begin(), V.end(), s.r) - V.begin() + 1;

        if (s.id == 1) ans |= ST.query(1, x, y) != 0;
        ST.update(1, x, s.id);
        ST.update(1, y, s.id);
        if (s.id == -1) ans |= ST.query(1, x, y) != 0;
    }

    printf("%d\n", ans != 0);
}

J - Subsequences in Substrings

The meaning of problems: Given two strings, the first string find how many sub-string contains the second sequence of character strings.

Direct violence

  

#include<cstdio>
#include<string>
#include<iostream>
using namespace std;
typedef long long ll;
string s,t;
const int maxn = 4e5+10;
void solve()
{
    cin>>s;
    cin>>t;
    ll lenn=s.size();
    ll lenm=t.size();
    ll ans=0,pos=-1;
    while(1)
    {
        int star,endd;
        star=s.find(t[0],pos+1);
        if(star==-1)break;
        endd=star;
        for(int i=1;i<lenm;i++){
        endd=s.find(t[i],endd+1);
        if(endd==-1)break;
        }
        if(endd==-1)break;
        ans+=(star-pos)*(lenn-endd);
        pos=star;
    }
    printf("%lld\n",ans);
}
int main()
{
    ios::sync_with_stdio(false);

    solve();
    return 0;
}

 D - It's a Mod, Mod, Mod, Mod World

Euclid class template https://www.cnblogs.com/asdfsag/p/11393783.html

 

 

题意:计算∑i=1n[(p⋅i)modq]




#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
int p,q,n;
ll f(ll a,ll b,ll c,ll n) {
    if(!a)return (n+1)*(b/c);
    if(a>=c||b>=c)return f(a%c,b%c,c,n)+n*(n+1)/2*(a/c)+(n+1)*(b/c);
    ll m=(a*n+b)/c;
    return n*m-f(c,c-b-1,a,m-1);
}
int main() {
    int T;
    for(scanf("%d",&T); T--;) {
        scanf("%d%d%d",&p,&q,&n);
        printf("%lld\n",(ll)n*(n+1)/2*p-f(p,0,q,n)*q);
    }
    return 0;
}

  

The meaning of problems: from n selecting n points K K points in the polygons, an area Q desired.

Solution: If the two points can be determined, it can be selected from between two points K - 2 K-2 to form a point K K gon. It is possible to enumerate two points to calculate the probability that two points was elected to constitute the convex hull and the area of the convex hull contribution.

#include <bits/stdc++.h>
#define fopi freopen("in.txt", "r", stdin) #define fopo freopen("out.txt", "w", stdout) using namespace std; typedef long long LL; typedef long double ld; const int maxn = 2500 + 10; struct Point { ld x, y; }a[maxn]; ld C[maxn][maxn]; void getC(int n) { C[0][0] = 1; for (int i = 1; i <= n; i++) { C[i][0] = 1; for (int j = 1; j <= i; j++) C[i][j] = C[i-1][j] + C[i-1][j-1]; } } ld Cross(Point a, Point b) { return a.x*b.y - a.y*b.x; } int n, k; int main() { ios::sync_with_stdio(false); cin >> n >> k; getC(n); for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y; ld ans = 0; for (int i = 1; i <= n; i++) for (int j = k-1; j <= n-1; j++) { int t = i+j; if (t > n) t -= n; ans += Cross(a[i], a[t]) * C[j-1][k-2] / C[n][k]; } printf("%.7Lf\n", ans/2); }

 

Guess you like

Origin www.cnblogs.com/hgangang/p/11621105.html