11.7NOIP模拟赛

 

、、

/*
考虑模gcd(n,m,k)的一个剩余系 
然后检查是否每类中都有一个快乐的人. 
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>

#define ll long long

using namespace std;
ll n,m,k,a1,b1,c1,vis[100010];

ll read()
{
    ll n=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){n=n*10+c-'0';c=getchar();}
    return n*f;
}

ll gcd(ll a,ll b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}

int main()
{
    freopen("happy2.in","r",stdin);
    freopen("happy2.out","w",stdout);
    ll T=read();
    while(T--)
    {
        memset(vis,0,sizeof(vis));
        n=read(),m=read(),k=read();
        ll gc=gcd(gcd(n,m),k);
        a1=read();
        for(int i=1;i<=a1;++i)vis[read()%gc]=1;
        b1=read();
        for(int i=1;i<=b1;++i)vis[read()%gc]=1;
        c1=read();
        for(int i=1;i<=c1;++i)vis[read()%gc]=1;
        int c=1;
        for(int i=0;i<gc;++i)
            if(!vis[i])
            {
                c=0;
                break;
            }
        if(!c||a1+b1+c1==0)cout<<"No\n";
        else cout<<"Yes\n";
    }
    return 0;
}

 

/*
注意别读错题,是大于等于p! 
*/
#include<iostream>
#include<cstdio>
#include<cstring>

#define N 3001
#define ll long long 

using namespace std;
ll n,m,cnt;
ll ans;
ll pos[N*100],pos_[N][N];
struct node{
    ll x,y;
}p[N*100];

inline ll read()
{
    int x=0,f=1;char c=getchar();
    while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}

int main()
{
    freopen("suspect.in","r",stdin);
    freopen("suspect.out","w",stdout);
    ll x,y;
    n=read();m=read();
    if(m==0)
    {
        cnt=0;
        for(int i=1;i<=n;i++)
        {
            x=read();y=read();
            pos[x]++;pos[y]++;
        }
        ans=1ll*(n-1)*n/2;
    }
    else if(m==1)
    {
        cnt=0;
        for(int i=1;i<=n;i++)
        {
            x=read();y=read();
            pos[x]++;pos[y]++;
        }
        for(int i=1;i<=n;i++) 
          if(pos[i]==0) cnt++;
        ans=(n-1)*n/2-(cnt-1)*cnt/2;
    }
    else
    {
        for(int i=1;i<=n;i++)
        {
            x=read();y=read();
            pos[x]++;pos[y]++;pos_[x][y]++,pos_[y][x]++;
        }
        for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++)
        if(pos[i]+pos[j]-pos_[i][j]>=m) 
        ans++;
    }
    cout<<ans<<endl;
    fclose(stdin);fclose(stdout);
    return 0;
}
80暴力
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstdlib>
#define INF 100000000
using namespace std;
typedef long long LL;
struct Edge
{
    int from,to,pre;
}e[1000000];
int h[300005]={0},cou=0;
int c[300005],ed[300005];
void Addedge(int from,int to)
{
    cou++;
    e[cou]=((Edge){from,to,h[from]});
    h[from]=cou;
}

inline void update(int x)
{
    if(x==0)
    {
        c[0]++;
        return;
    }
    for(;x<=300000;x+=x&-x)
        c[x]++;
}
inline int get(int x)
{
    if(x==-1) return 0;
    int sum=0;
    for(;x;x-=x&-x)
        sum+=c[x];
    return sum+c[0];
}
int main()
{
    freopen("suspect.in","r",stdin);
    freopen("suspect.out","w",stdout);
    LL ans=0;
    int sum,i,n,p,a,b,v,j;
    cin>>n>>p;
    for(i=1;i<=n;i++)
    {
        scanf("%d%d",&a,&b);
        Addedge(a,b); Addedge(b,a);
        ed[a]++; ed[b]++;
    }
    for(i=1;i<=n;i++)
        update(ed[i]);
    for(i=1;i<=n;i++)
    {
        if(ed[i]>=p)
            ans+=n-1;
        else
        {
            sum=n-get(p-ed[i]-1);
            if(ed[i]>=p-ed[i]) sum--;
            for(j=h[i];j;j=e[j].pre)
            {
                v=e[j].to;
                if(ed[v]==p-ed[i]) sum--;
                ed[v]--;
            }
            for(j=h[i];j;j=e[j].pre)
            {
                v=e[j].to;
                ed[v]++;
            }
            ans+=sum;
        }
    }
    cout<<ans/2<<endl;
    return 0;
}

 

/*
80暴力。by lpy
怕不是数据结构学傻了。考试写的线段树。还忘了离散化,挂25分。 
*/
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
int sum[1010][1010];
int sum0[300010],sum1[300010];
int a[300010],b[300010],num[300010];
inline int read()
{
    int x=0,f=1;char c=getchar();
    while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
int main()
{
    freopen("xor.in","r",stdin);
    freopen("xor.out","w",stdout);
    n=read();
    int num1=0;
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        b[i]=a[i];
        if(a[i]<=1)    num1++;
    }
    sort(b+1,b+1+n);
    int bnum=unique(b+1,b+1+n)-b-1;
    if(bnum==n)
    {
        m=read();
        for(int i=1; i<=m; i++)
        {
            int l=read();
            int r=read();
            puts("0");
        }
    }
    else if(num1==n)
    {
        for(int i=1; i<=n; i++)
        {
            if(a[i]==1)
            {
                sum0[i]=sum0[i-1];
                sum1[i]=sum1[i-1]+1;
            }
            if(a[i]==0)
            {
                sum1[i]=sum1[i-1];
                sum0[i]=sum0[i-1]+1;
            }
        }
        m=read();
        for(int i=1; i<=m; i++)
        {
            int l=read();
            int r=read();
            int xx=sum1[r]-sum1[l-1];
            int yy=sum0[r]-sum0[l-1];
            if(xx%2==0&&yy%2==0&&xx!=0&&yy!=0) puts("1");
            else if(xx%2==0&&xx!=0)    puts("1");
            else if(yy%2==0&&yy!=0)    puts("0");
            else puts("0");
        }
    }
    else if(n<=1000)
    {
        for(int i=1; i<=n; i++)
        {
            int x=a[i];
            a[i]=lower_bound(b+1,b+1+bnum,a[i])-b;
            num[a[i]]=x;
        }
        for(int i=1; i<=n; i++)
            for(int j=1; j<=bnum; j++)
            {
                if(a[i]==j)    sum[i][j]=sum[i-1][j]+1;
                else sum[i][j]=sum[i-1][j];
            }
        m=read();
        for(int i=1; i<=m; i++)
        {
            int l=read();int r=read();
            int ans=0;
            for(int j=1; j<=bnum; j++)
            {
                int xx=sum[r][j]-sum[l-1][j];
                if(xx%2==0&&xx!=0)    ans=ans^num[j];
            }
            printf("%d\n",ans);
        }
    }
}
80暴力
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstdlib>
#include<string>
#include<bitset>
#include<iomanip>
#include<deque>
#include<utility>
#define INF 1000000000
#define fi first
#define se second
#define N 1000005
#define P 1000000007
#define debug(x) cerr<<#x<<"="<<x<<endl
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
int c[N],now,sum,a[N],b[N],ans[N],nxt[N],n;
map<int,int> vis,pre;
vector<pii> Q[N];

void Add(int x,int w)
{
    for(;x<=n;x+=x&-x)
        c[x]^=w;
}

int Get(int x)
{
    int s=0;
    for(;x;x-=x&-x)
        s^=c[x];
    return s;
}

int main()
{
    int i,m,ql,qr,j;
    freopen("xor.in","r",stdin);
    freopen("xor.out","w",stdout);
    cin>>n;
    now=0;
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        vis[a[i]]++;
        nxt[pre[a[i]]]=i;
        pre[a[i]]=i;
        if(vis[a[i]]>1)
            now^=a[i];
        b[i]=now;
        //debug(b[i]);
    }
    cin>>m;
    for(i=1;i<=m;i++)
    {
        scanf("%d%d",&ql,&qr);
        Q[ql].push_back(MP(qr,i));
    }
    for(i=1;i<=n;i++)
    {
        //debug(sum);
        for(j=0;j<Q[i].size();j++)
            ans[Q[i][j].se]=Get(Q[i][j].fi)^b[Q[i][j].fi];
        ql=nxt[i];
        if(ql)
        {
            sum^=a[i];
            Add(ql,a[i]);
        }
    }
    for(i=1;i<=m;i++)
        printf("%d\n",ans[i]);
    return 0;
}

 

应付了一篇解题报告~

posted @ 2018-11-07 19:10  安月冷  阅读(304)  评论(0编辑  收藏  举报