Codeforces #340 div2

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces #340 div2相关的知识,希望对你有一定的参考价值。

A:

#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    cout<<(n-1)/5+1;
} 

B:

#include<iostream>
using namespace std;
int n;
int pos[110];
int cnt;
#define rep(i,j,k) for(int i=j;i<=k;i++)
typedef long long ll;
int main()
{
    cin>>n;
    rep(i,1,n)
    {
        int num;
        cin>>num;
        if(num==1)
        {
            cnt++;
            pos[cnt]=i;
        }
    }
    ll ans=1;
    rep(i,1,cnt-1)
    {
        ans*=(ll)(pos[i+1]-pos[i]);
    }
    if(pos[1])
    cout<<ans<<endl;
    else
    cout<<"0";
}

C:

#include<iostream>
#include<algorithm>
using namespace std;
int n;
typedef long long ll;
ll x1,y1,x2,y2;
struct fon{
    ll x,y;
    ll dis1,dis2;
}f[2010];
#define rep(i,j,k) for(int i=j;i<=k;i++)
bool cmp(fon a,fon b)
{
    return a.dis1<b.dis1;
}
int main()
{
    cin>>n>>x1>>y1>>x2>>y2;
    rep(i,1,n)
    {
        cin>>f[i].x>>f[i].y;
        f[i].dis1=(f[i].x-x1)*(f[i].x-x1)+(f[i].y-y1)*(f[i].y-y1);
        f[i].dis2=(f[i].x-x2)*(f[i].x-x2)+(f[i].y-y2)*(f[i].y-y2);
    }
    sort(f+1,f+1+n,cmp);
    ll ans=1e17;
    rep(i,0,n)
    {
        ll tmp=0;
        rep(j,i+1,n)
        {
            tmp=max(tmp,f[j].dis2);
        }
        ans=min(ans,f[i].dis1+tmp);
    }
    if(n==1)
    ans=min(f[1].dis1,f[1].dis2);
    cout<<ans;
}

D:

#include<iostream>
#include<algorithm>
using namespace std;
struct point{
    int x,y;
}p[4];
#define rep(i,j,k) for(int i=j;i<=k;i++)
int main()
{
    cin>>p[1].x>>p[1].y>>p[2].x>>p[2].y>>p[3].x>>p[3].y;
    if((p[1].x==p[2].x&&p[2].x==p[3].x)||(p[1].y==p[2].y&&p[2].y==p[3].y))
    {
        cout<<"1";
        return 0;
    }
    int tmpi=0,tmpj=0;
    rep(i,1,2)
    rep(j,i+1,3)
    {
        if(p[i].x==p[j].x)
        {
            tmpi=i;tmpj=j;
        }
    }
    if(tmpi&&tmpj)
    {
        rep(i,1,3)
        {
            if(i!=tmpi&&i!=tmpj)
            {
                if(p[i].y>=max(p[tmpi].y,p[tmpj].y)||p[i].y<=min(p[tmpi].y,p[tmpj].y))
                {
                    cout<<"2";
                    return 0;
                }
            }
        }
    }
    tmpi=tmpj=0;
    rep(i,1,2)
    rep(j,i+1,3)
    {
        if(p[i].y==p[j].y)
        {
            tmpi=i;tmpj=j;
        }
    }
    if(tmpi&&tmpj)
    {
        rep(i,1,3)
        {
            if(i!=tmpi&&i!=tmpj)
            {
                if(p[i].x>=max(p[tmpi].x,p[tmpj].x)||p[i].x<=min(p[tmpi].x,p[tmpj].x))
                {
                    cout<<"2";
                    return 0;
                }
            }
        }
    }
    cout<<"3";
}

E:

#include<iostream>
#include<algorithm>
using namespace std;
int n,m,k;
const int mxn=1e5+10;
int seq[mxn];
typedef long long ll;
struct query{
    int l,r,id;
    ll ans;
}q[mxn];
ll exist[20000000+10];
#define rep(i,j,k) for(int i=j;i<=k;i++)
bool cmp(query a,query b)
{
    if(a.l/400==b.l/400)
    return a.r<b.r;
    return a.l/400<b.l/400;
}
bool cmp2(query a,query b)
{
    return a.id<b.id;
}
int main()
{
    cin>>n>>m>>k;
    rep(i,1,n)
    {
        int num;
        scanf("%d",&num);
        seq[i]=seq[i-1]^num;
    }
    rep(i,1,m)
    {
        scanf("%d%d",&q[i].l,&q[i].r);
        q[i].id=i;
        q[i].l--;
    }
    sort(q+1,q+1+m,cmp);
    int l=q[1].l,r=q[1].r;
    ll ans=0;
    rep(i,l,r)
    {
        ans+=exist[k^seq[i]];
        exist[seq[i]]++;
    }
    q[1].ans=ans;
    rep(i,2,m)
    {
        while(r<q[i].r)
        {
            r++;
            ans+=exist[k^seq[r]];
            exist[seq[r]]++; 
        }
        while(r>q[i].r)
        {
            exist[seq[r]]--;
            ans-=exist[k^seq[r]];
            r--;
        }
        while(l>q[i].l)
        {
            l--;
            ans+=exist[k^seq[l]];
            exist[seq[l]]++;
        }
        while(l<q[i].l)
        {
            exist[seq[l]]--;
            ans-=exist[k^seq[l]];
            l++;
        }
        q[i].ans=ans;
    }
    sort(q+1,q+1+m,cmp2);
    rep(i,1,m)
    cout<<q[i].ans<<endl;
}

 

以上是关于Codeforces #340 div2的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #393 div2

Codeforces Round #326 div2

Codeforces Round #564(div2)

Codeforces Round #394 div2

codeforces597 div2 F 数位dp

Codeforces#543 div2 B. Mike and Children(暴力?)