Hello 2020 solution to a problem

New Year's first.

Opening 2min write A, then 5min wrote B, then 4min wrote C.

Since then the brain is drawn, and thought clearly began to code D, it took 18min to finish.

Then find a buddy list of people seem to cut no more than four questions, but also to play.

Then start thinking E.

Go to the start must be asked whether a convex polygon and an integral concave polygon (there will be three cases) set of points to be counted how many times.

See the three cases can only be counted once, mind you break up ......

After 5min found that if legitimate, happens to one is legitimate, wasted a bunch of time ......

Then open code. Better than expected code. However, due to computational geometry, it still took a long time, probably 1h.

Then WA9.

To shoot not too wanted to write, still troubleshooting, check out all dead.

Abandoned treatment, the water went to the group.

……

Then naive to think long double is enough, when they send out of the penalty.

Finally sentenced reconstruction has become a cross product + quadrant wording, finally he had lost at 2:09.

E also scored less than C.

It looks pretty good to play on the IM.

(Dramatic scene: 2min finally cut tourist G turned on rk1, predictor display will still be dls two list, then the tourist of the FST G)

(Dls congratulations to the throne, this year is the first year MiFaFaOvO)


A

Getting simulation.


Code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=22;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
    char ch=getchar();ll x=0,f=0;
    while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
    while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
    return f?-x:x;
}
int n,m,q;
char s[maxn][maxn],t[maxn][maxn];
int main(){
    n=read();m=read();
    FOR(i,0,n-1) scanf("%s",s[i]+1);
    FOR(i,0,m-1) scanf("%s",t[i]+1);
    q=read();
    while(q--){
        int y=read()-1;
        printf("%s%s\n",s[y%n]+1,t[y%m]+1);
    }
}

B

How with a question of my own a bit like ......

In turn, calculate the number of illegal schemes, that is, the number of sequences does not rise.

Consider chose \ (i, j \) pieces together, then to \ (i, j \) are not ascending order, and \ (last_i \ GE first_j \) .

The sequence does not rise to carry out the enumeration \ (i \) , calculated \ (\ le last_i \) is \ (first_j \) how many. 1-2 minutes and it can be a prefix.

Time complexity \ (O (n \ log n ) \) or \ (O (n-+ \ max (A)) \) .


Code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=1000100;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
    char ch=getchar();ll x=0,f=0;
    while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
    while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
    return f?-x:x;
}
int n,l,a[maxn],s[maxn],t[maxn],m,cnt[maxn];
ll ans;
int main(){
    n=read();
    FOR(i,1,n){
        l=read();
        FOR(j,1,l) a[j]=read();
        bool flag=false;
        FOR(j,2,l) flag|=a[j-1]<a[j];
        if(!flag) cnt[a[1]]++,t[++m]=a[l];
    }
    FOR(i,1,1000000) cnt[i]+=cnt[i-1];
    ans=1ll*n*n;
    FOR(i,1,m) ans-=cnt[t[i]];
    printf("%lld\n",ans);
}

C

Consider \ ([l, r] \ ) number of occurrences as a continuous segment.

The number of rows can be easily, \ ((L-R & lt +. 1)! \) .

The remaining number of rows can be easily, \ ((N- (L-R & lt +. 1))! \) .

Select the start position of continuous segments, \ (N- (L-R & lt +. 1) + 1'd \) .

It found that for the same length \ ([l, r] \ ) as the contribution. Enumeration length, the answer is \ (\ DisplayStyle \ sum_ {I}. 1 ^ = Ni! (Ni)! (Ni +. 1) ^ 2 \) .

Time complexity \ (O (n-) \) .


Code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=250025;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
    char ch=getchar();ll x=0,f=0;
    while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
    while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
    return f?-x:x;
}
int n,mod,ans,fac[maxn];
int main(){
    n=read();mod=read();
    fac[0]=1;
    FOR(i,1,n) fac[i]=1ll*fac[i-1]*i%mod;
    FOR(i,1,n) ans=(ans+1ll*fac[n-i]*fac[i]%mod*(n-i+1)%mod*(n-i+1))%mod;
    printf("%d\n",ans); 
}

D

It found that only need to consider the size of \ (2 \) subset.

Because if there is size \ (2 \) is a subset of the conditions are not satisfied that condition is not met; if all of size \ (2 \) is a subset of the conditions are met, then obviously the whole also satisfies the condition.

The question then becomes: For any two (not sure what), or they have to pay two sections at the same time or at the same time do not pay.

Then there are about ten thousand kinds of practices.

My approach: for \ (\ texttt {A} \ ) what the interval without post judged \ (\ texttt {B} \ ) interval has not paid; for \ (\ texttt {B} \ ) what the interval is no post , it is judged \ (\ texttt {A} \ ) interval has not paid.

Here's just say the first one.

Press \ (\ texttt {A} \ ) interval left points in ascending order. Enumeration first thing to consider \ (\ texttt {A} \ ) interval is less than the right end of the enumerated \ (\ texttt {A} \ ) everything left section points, as the second thing can.

Analyzing \ (\ texttt {B} \ ) interval has not paid, may each second thing \ (\ texttt {B} \ ) interval plus do interval, and then determine the first thing \ (\ texttt { B} \) interval and whether \ (0 \) .

Time complexity \ (O (n-\ log n-) \) .


Code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=222222;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
    char ch=getchar();ll x=0,f=0;
    while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
    while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
    return f?-x:x;
}
struct seg{
    int la,ra,lb,rb;
}s1[maxn],s2[maxn];
int n,la[maxn],ra[maxn],lb[maxn],rb[maxn],tmpa[maxn],tla,tmpb[maxn],tlb;
ll b1[maxn],b2[maxn];
inline bool cmpla(const seg &x,const seg &y){return x.la<y.la;}
inline bool cmpra(const seg &x,const seg &y){return x.ra<y.ra;}
inline bool cmplb(const seg &x,const seg &y){return x.lb<y.lb;}
inline bool cmprb(const seg &x,const seg &y){return x.rb<y.rb;}
inline void update(ll *bit,int p,ll v){
    for(int i=p;i<=max(tla,tlb);i+=i&-i) bit[i]+=v;
}
inline ll query(ll *bit,int p){
    ll s=0;
    for(int i=p;i;i-=i&-i) s+=bit[i];
    return s;
}
inline void update(int p,ll v){
    update(b1,p,v);
    update(b2,p,1ll*p*v);
}
inline ll query(int p){
    return 1ll*(p+1)*query(b1,p)-query(b2,p);
}
inline void update(int l,int r,ll v){
    update(l,v);update(r+1,-v);
}
inline ll query(int l,int r){
    return query(r)-query(l-1);
}
int main(){
    n=read();
    FOR(i,1,n){
        la[i]=read();ra[i]=read();lb[i]=read();rb[i]=read();
        tmpa[++tla]=la[i];tmpa[++tla]=ra[i];
        tmpb[++tlb]=lb[i];tmpb[++tlb]=rb[i];
    }
    sort(tmpa+1,tmpa+tla+1);tla=unique(tmpa+1,tmpa+tla+1)-tmpa-1;
    sort(tmpb+1,tmpb+tlb+1);tlb=unique(tmpb+1,tmpb+tlb+1)-tmpb-1;
    FOR(i,1,n){
        la[i]=lower_bound(tmpa+1,tmpa+tla+1,la[i])-tmpa;
        ra[i]=lower_bound(tmpa+1,tmpa+tla+1,ra[i])-tmpa;
        lb[i]=lower_bound(tmpb+1,tmpb+tlb+1,lb[i])-tmpb;
        rb[i]=lower_bound(tmpb+1,tmpb+tlb+1,rb[i])-tmpb; 
        s1[i]=s2[i]=(seg){la[i],ra[i],lb[i],rb[i]};
    }
    sort(s1+1,s1+n+1,cmpla);
    sort(s2+1,s2+n+1,cmpra);
    int cur=1;
    FOR(i,1,n){
        while(cur<=n && s2[cur].ra<s1[i].la){
            update(s2[cur].lb,s2[cur].rb,1);
            cur++;
        }
        if(query(s1[i].lb,s1[i].rb)) return puts("NO"),0;
    }
    MEM(b1,0);MEM(b2,0);
    sort(s1+1,s1+n+1,cmplb);
    sort(s2+1,s2+n+1,cmprb);
    cur=1;
    FOR(i,1,n){
        while(cur<=n && s2[cur].rb<s1[i].lb){
            update(s2[cur].la,s2[cur].ra,1);
            cur++;
        }
        if(query(s1[i].la,s1[i].ra)) return puts("NO"),0;
    }
    puts("YES");
}

E

Calculated for each point \ (p \) contribution. Found that in the remaining four selected points, all in the can after the \ (p \) does not satisfy the conditions of a side of a straight line.

From the back calculation, the total number of (in the remaining four selected points) scheme, after subtracting the energy in the whole \ (P \) side of a straight line.

The \ (P \) as the origin, the remaining ordered sequence polar angle point.

Enumeration most counterclockwise (should know what it means) points, three points should be able to rest in a randomly selected interval. This interval can be calculated by double pointer.

Time complexity \ (O (n-2 ^ \ n-log) \) .

Note, do not use atan2, it is preferably determined by the cross product.


Code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=5050;
const long double pi=3.141592653589793238;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
    char ch=getchar();ll x=0,f=0;
    while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
    while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
    return f?-x:x;
}
inline int at(int x,int y){
    if(x>=0 && y>0) return 0;
    if(x<0 && y>=0) return 1;
    if(x<=0 && y<0) return 2;
    if(x>0 && y<=0) return 3;
    return -1;
}
struct point{
    int x,y;
    point(int xx=0,int yy=0):x(xx),y(yy){}
    point operator+(const point &p)const{return point(x+p.x,y+p.y);}
    point operator-(const point &p)const{return point(x-p.x,y-p.y);}
    point operator-()const{return point(-x,-y);}
    ll operator*(const point &p)const{return 1ll*x*p.y-1ll*y*p.x;}
    bool operator<(const point &p)const{
        if(at(x,y)!=at(p.x,p.y)) return at(x,y)<at(p.x,p.y);
        return *this*p>0;
    }
}p[maxn],q[maxn];
int n;
ll ans;
int main(){
    n=read();
    FOR(i,1,n) p[i].x=read(),p[i].y=read();
    FOR(i,1,n){
        FOR(j,1,n) if(j!=i) q[j-(j>i)]=p[j]-p[i];
        sort(q+1,q+n);
        FOR(j,1,n-1) q[j+n-1]=q[j];
        ans+=1ll*(n-1)*(n-2)*(n-3)*(n-4)/24;
        int cur=1;
        FOR(j,1,n-1){
            cur=max(cur,j);
            while(cur<2*n-2 && q[cur+1]*(-q[j])>0) cur++;
            int x=cur-j;
            ans-=1ll*x*(x-1)*(x-2)/6;
        }
    }
    printf("%lld\n",ans);
}

F/G

No, the cushions.

Guess you like

Origin www.cnblogs.com/1000Suns/p/12150949.html