长沙理工组队赛 第二场 只A出来五道题目,银牌最后一名。。。伤不起!!!

A题:状态压缩dp??枚举 两行???反正四个小时的比赛,没怎么敢写。。。毕竟好久没有写那个方面的题目了!!也未必能写出来。。

C题:数列。。。等差,等比,大数幂取模,就这些知识点而已

#include<iostream>
#include<cstdlib>
#include<stdio.h>
#define ll long long
using namespace std;
ll powermod(ll a,ll b,ll p)
{
    ll res=1;
    while(b)
    {
        if(b&1)res=res*a%p;
        b>>=1;
        a=a*a%p;
    }
    return res;
}
int main()
{
    int mod=100007,a,b,c,n;
    while(scanf("%d%d%d%d",&a,&b,&c,&n)!=EOF)
    {
        if((a+c)==2*b)
        {
            printf("%lld\n",(a%mod+((long long)(n-1)%mod)*((b-a)%mod))%mod);
        }
        else
        {
            int q=b/a;
            int m=n-1;
            int p=100007;
            //(a^b) % p = ((a % p)^b) % p
            //(q^m) % p = ((q % p)^m) % p
            //int ans=int((pow((q%p),m)))%p;
            printf("%lld\n",powermod(q,m,p)%mod);
        }
    }
    return 0;
}
/*
1 2 3 5
1 2 4 4
*/


E题:LIS变形,卡了两次!!!

#include<stdio.h>
#include<algorithm>
using namespace std;
#define N 20005
int a[N],dp1[N];
int n;
void LIS(int dp[],int a[])
{
    int stack[N];
    int top=0;
    stack[top]=-999999;
    for(int i=1; i<=n; i++)
    {
        //如果a[i]>栈顶部元素,则压栈
        if(a[i]<0)
        {
            dp[i]=dp[i-1];
            continue;
        }
        if(a[i]>=stack[top])
        {
            stack[++top]=a[i];
            dp[i]=top;
        }
        //如果a[i]不大于栈顶部元素,则二分查找第一个比a[i]大的元素
        else
        {
            int l=1,r=top;
            while(l<=r)
            {
                int mid=(l+r)>>1;
                if(a[i]>stack[mid])
                {
                    l=mid+1;
                }
                else
                    r=mid-1;
            }
            //替换a[i]
            stack[l]=a[i];
            dp[i]=l;
        }
    }
}
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&a[i]);
            a[i]-=i;
            dp1[i]=0;
        }
        LIS(dp1,a);
        int maxx=-1;
        for(int i=1; i<=n; i++)
        {
            if(dp1[i]>maxx)
                maxx=dp1[i];
        }
        printf("%d\n",maxx);
    }
    return 0;
}
/*
5
13 14 1 15 16
5
13 14 1 16 17
5
13 14 12 15 16
*/


F题:我用的vector  直接遍历判断,貌似有的队直接邪恶打表过的T_T,能过就是一种能力。。。

#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<vector>
using namespace std;
int n;
bool IsPrime3(int n)
{
    if ( n < 2 )
    {
        // 小于2的数即不是合数也不是素数
        return 0;
    }
    int len=sqrt(n);
    for(int i=2;i<=len;i++)
    {
        if(n%i==0)return 0;
    }
    return 1;
}
int main()
{
    vector<int>p[10];
    p[1].push_back(2);
    p[1].push_back(3);
    p[1].push_back(5);
    p[1].push_back(7);
    int i,j,k,len;
    for(i=2;i<=8;i++)
    {
         len=p[i-1].size();
        for(j=0;j<len;j++)
        {
            int v=p[i-1][j];
            for(k=1;k<=9;k+=2)
            {
                int tmp=v*10+k;
                if(IsPrime3(tmp))
                {
                    p[i].push_back(tmp);
                }
            }
        }
    }
    while(scanf("%d",&n)!=EOF)
    {
        len=p[n].size();
        for(i=0;i<len;i++)
        {
            cout<<p[n][i]<<endl;
        }
    }
    return 0;
}
 


G题:dfs   看代码 就能明白 ,队友这代码精简能力了。。。。囧~~~~

#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
bool visit[25][25][25];
int A,B,C;
bool have[25];
int ans[25],idx;
void dfs(int a,int b,int c)
{
 
    if(a==0)
    {
        if(!have[c])
        {
            have[c]=true;
            ans[idx++]=c;
        }
    }
    if(a>B-b)
    {
        if(!visit[a-B+b][B][c])
        {
            visit[a-B+b][B][c]=true;
            dfs(a-B+b,B,c);
            visit[a-B+b][B][c]=false;
        }
    }
    else
    {
        if(!visit[0][b+a][c])
        {
            visit[0][b+a][c]=true;
            dfs(0,b+a,c);
            visit[0][b+a][c]=false;
        }
    }
    if(a>C-c)
    {
        if(!visit[a-C+c][b][C])
        {
            visit[a-C+c][b][C]=true;
            dfs(a-C+c,b,C);
            visit[a-C+c][b][C]=false;
        }
    }
    else
    {
        if(!visit[0][b][c+a])
        {
            visit[0][b][c+a]=true;
            dfs(0,b,c+a);
            visit[0][b][c+a]=false;
        }
    }
    if(b>A-a)
    {
        if(!visit[A][b-A+a][c])
        {
            visit[A][b-A+a][c]=true;
            dfs(A,b-A+a,c);
            visit[A][b-A+a][c]=false;
        }
    }
    else
    {
        if(!visit[a+b][0][c])
        {
            visit[a+b][0][c]=true;
            dfs(a+b,0,c);
            visit[a+b][0][c]=false;
        }
    }
    if(b>C-c)
    {
        if(!visit[a][b-C+c][C])
        {
            visit[a][b-C+c][C]=true;
            dfs(a,b-C+c,C);
            visit[a][b-C+c][C]=false;
        }
    }
    else
    {
        if(!visit[a][0][c+b])
        {
            visit[a][0][c+b]=true;
            dfs(a,0,c+b);
            visit[a][0][c+b]=false;
        }
    }
    if(c>A-a)
    {
        if(!visit[A][b][c-A+a])
        {
            visit[A][b][c-A+a]=true;
            dfs(A,b,c-A+a);
            visit[A][b][c-A+a]=false;
        }
    }
    else
    {
        if(!visit[a+c][b][0])
        {
            visit[a+c][b][0]=true;
            dfs(a+c,b,0);
            visit[a+c][b][0]=false;
        }
    }
    if(c>B-b)
    {
        if(!visit[a][B][c-B+b])
        {
            visit[a][B][c-B+b]=true;
            dfs(a,B,c-B+b);
            visit[a][B][c-B+b]=false;
        }
    }
    else
    {
        if(!visit[a][b+c][0])
        {
            visit[a][b+c][0]=true;
            dfs(a,b+c,0);
            visit[a][b+c][0]=false;
        }
    }
}
int main()
{
    while(scanf("%d%d%d",&A,&B,&C)!=EOF)
    {
        idx=0;
        for(int i=0; i<=20; i++)
        {
            for(int j=0; j<=20; j++)
            {
                for(int k=0; k<=20; k++)
                {
                    visit[i][j][k]=false;
                }
            }
            have[i]=false;
        }
        visit[0][0][C]=true;
        dfs(0,0,C);
        sort(ans,ans+idx);
        for(int i=0;i<idx;i++)
        {
            if(i==0)
            printf("%d",ans[i]);
            else printf(" %d",ans[i]);
        }
        printf("\n");
    }
    return 0;
}

H题:bfs 我终于知道bfs 还能那么长~~~~~~~~不知道队友什么心态?!!!

#include<iostream>
#include<stdio.h>
#include<stack>
#include<string.h>
#include<math.h>
using namespace std;
bool visit[5][5][5][5][5][5][5][5][5];
struct node
{
    int a[3][3];
    int type;
    int step;
    int parent;
} cur,nod,tmpb,q[1000000];
int b[3][3],tmpa[3][3];
int ans;
void A()
{
    if((b[0][0]+3)%12==0)
        b[0][0]=12;
    else
        b[0][0]=(b[0][0]+3)%12;
}
void B()
{
    if((b[0][1]+3)%12==0)
        b[0][1]=12;
    else
        b[0][1]=(b[0][1]+3)%12;
}
void C()
{
    if((b[0][2]+3)%12==0)
        b[0][2]=12;
    else
        b[0][2]=(b[0][2]+3)%12;
}
void D()
{
    if((b[1][0]+3)%12==0)
        b[1][0]=12;
    else
        b[1][0]=(b[1][0]+3)%12;
}
void E()
{
    if((b[1][1]+3)%12==0)
        b[1][1]=12;
    else
        b[1][1]=(b[1][1]+3)%12;
}
void F()
{
    if((b[1][2]+3)%12==0)
        b[1][2]=12;
    else
        b[1][2]=(b[1][2]+3)%12;
}
void G()
{
    if((b[2][0]+3)%12==0)
        b[2][0]=12;
    else
        b[2][0]=(b[2][0]+3)%12;
}
void H()
{
    if((b[2][1]+3)%12==0)
        b[2][1]=12;
    else
        b[2][1]=(b[2][1]+3)%12;
}
void I()
{
    if((b[2][2]+3)%12==0)
        b[2][2]=12;
    else
        b[2][2]=(b[2][2]+3)%12;
}
void f1()
{
    A();
    B();
    D();
    E();
}
void f2()
{
    A();
    B();
    C();
}
void f3()
{
    B();
    C();
    E();
    F();
}
void f4()
{
    A();
    D();
    G();
}
void f5()
{
    B();
    D();
    E();
    F();
    H();
}
void f6()
{
    C();
    F();
    I();
}
void f7()
{
    D();
    E();
    G();
    H();
}
void f8()
{
    G();
    H();
    I();
}
void f9()
{
    E();
    F();
    H();
    I();
}
bool is(node t)
{
    int i,j;
    for(i=0; i<3; i++)
    {
        for(j=0; j<3; j++)
        {
            if(t.a[i][j]!=12)
                return false;
        }
    }
    return true;
}
bool vis(int aa[3][3])
{
    return visit[aa[0][0]/3][aa[0][1]/3][aa[0][2]/3][aa[1][0]/3][aa[1][1]/3][aa[1][2]/3][aa[2][0]/3][aa[2][1]/3][aa[2][2]/3];
}
void bfs()
{
    for(int i=0; i<3; i++)
    {
        for(int j=0; j<3; j++)
        {
            nod.a[i][j]=tmpa[i][j];
        }
    }
    nod.step=0;
    nod.parent=-1;
    int front=0,rear=0;
    //visit[]=true;
    //q.push(nod);
    q[rear++]=nod;
    while(front<rear)
    {
        //cout<<":dsfs"<<endl;
        cur=q[front++];
        if(is(cur))
        {//cout<<"sdfs"<<endl;
            //printf("%d\n",cur.step);
            ans=front-1;
            return;
        }
        /
        for(int k=0; k<3; k++)
        {
            for(int p=0; p<3; p++)
                b[k][p]=cur.a[k][p];
        }
        f1();//cout<<"dsf"<<endl;
        if(!vis(b))
        {
            for(int k=0; k<3; k++)
            {
                for(int p=0; p<3; p++)
                    tmpb.a[k][p]=b[k][p];
            }
            tmpb.type=1;
            tmpb.parent=front-1;
            tmpb.step=cur.step+1;
            //visit[tmpb]=true;
            visit[b[0][0]/3][b[0][1]/3][b[0][2]/3][b[1][0]/3][b[1][1]/3][b[1][2]/3][b[2][0]/3][b[2][1]/3][b[2][2]/3]=true;
            q[rear++]=tmpb;
        }
        //
        for(int k=0; k<3; k++)
        {
            for(int p=0; p<3; p++)
                b[k][p]=cur.a[k][p];
        }
        f2();
        if(!vis(b))
        {
            for(int k=0; k<3; k++)
            {
                for(int p=0; p<3; p++)
                    tmpb.a[k][p]=b[k][p];
            }
            tmpb.type=2;
            tmpb.parent=front-1;
            tmpb.step=cur.step+1;
            visit[b[0][0]/3][b[0][1]/3][b[0][2]/3][b[1][0]/3][b[1][1]/3][b[1][2]/3][b[2][0]/3][b[2][1]/3][b[2][2]/3]=true;
            q[rear++]=tmpb;
        }
        /
        for(int k=0; k<3; k++)
        {
            for(int p=0; p<3; p++)
                b[k][p]=cur.a[k][p];
        }
        f3();
        if(!vis(b))
        {
            for(int k=0; k<3; k++)
            {
                for(int p=0; p<3; p++)
                    tmpb.a[k][p]=b[k][p];
            }
            tmpb.type=3;
            tmpb.parent=front-1;
            tmpb.step=cur.step+1;
            visit[b[0][0]/3][b[0][1]/3][b[0][2]/3][b[1][0]/3][b[1][1]/3][b[1][2]/3][b[2][0]/3][b[2][1]/3][b[2][2]/3]=true;
            q[rear++]=tmpb;
        }
        /
        for(int k=0; k<3; k++)
        {
            for(int p=0; p<3; p++)
                b[k][p]=cur.a[k][p];
        }
        f4();
        if(!vis(b))
        {
            for(int k=0; k<3; k++)
            {
                for(int p=0; p<3; p++)
                    tmpb.a[k][p]=b[k][p];
            }
            tmpb.type=4;
            tmpb.parent=front-1;
            tmpb.step=cur.step+1;
            visit[b[0][0]/3][b[0][1]/3][b[0][2]/3][b[1][0]/3][b[1][1]/3][b[1][2]/3][b[2][0]/3][b[2][1]/3][b[2][2]/3]=true;
            q[rear++]=tmpb;
        }
        ///
        for(int k=0; k<3; k++)
        {
            for(int p=0; p<3; p++)
                b[k][p]=cur.a[k][p];
        }
        f5();
        if(!vis(b))
        {
            for(int k=0; k<3; k++)
            {
                for(int p=0; p<3; p++)
                    tmpb.a[k][p]=b[k][p];
            }
            tmpb.type=5;
            tmpb.parent=front-1;
            tmpb.step=cur.step+1;
            visit[b[0][0]/3][b[0][1]/3][b[0][2]/3][b[1][0]/3][b[1][1]/3][b[1][2]/3][b[2][0]/3][b[2][1]/3][b[2][2]/3]=true;
            q[rear++]=tmpb;
        }
        /
        for(int k=0; k<3; k++)
        {
            for(int p=0; p<3; p++)
                b[k][p]=cur.a[k][p];
        }
        f6();
        if(!vis(b))
        {
            for(int k=0; k<3; k++)
            {
                for(int p=0; p<3; p++)
                    tmpb.a[k][p]=b[k][p];
            }
            tmpb.type=6;
            tmpb.parent=front-1;
            tmpb.step=cur.step+1;
            visit[b[0][0]/3][b[0][1]/3][b[0][2]/3][b[1][0]/3][b[1][1]/3][b[1][2]/3][b[2][0]/3][b[2][1]/3][b[2][2]/3]=true;
            q[rear++]=tmpb;
        }
        /
        for(int k=0; k<3; k++)
        {
            for(int p=0; p<3; p++)
                b[k][p]=cur.a[k][p];
        }
        f7();
        if(!vis(b))
        {
            for(int k=0; k<3; k++)
            {
                for(int p=0; p<3; p++)
                    tmpb.a[k][p]=b[k][p];
            }
            tmpb.type=7;
            tmpb.parent=front-1;
            tmpb.step=cur.step+1;
            visit[b[0][0]/3][b[0][1]/3][b[0][2]/3][b[1][0]/3][b[1][1]/3][b[1][2]/3][b[2][0]/3][b[2][1]/3][b[2][2]/3]=true;
            q[rear++]=tmpb;
        }
        //
        for(int k=0; k<3; k++)
        {
            for(int p=0; p<3; p++)
                b[k][p]=cur.a[k][p];
        }
        f8();
        if(!vis(b))
        {
            for(int k=0; k<3; k++)
            {
                for(int p=0; p<3; p++)
                    tmpb.a[k][p]=b[k][p];
            }
            tmpb.type=8;
            tmpb.parent=front-1;
            tmpb.step=cur.step+1;
            visit[b[0][0]/3][b[0][1]/3][b[0][2]/3][b[1][0]/3][b[1][1]/3][b[1][2]/3][b[2][0]/3][b[2][1]/3][b[2][2]/3]=true;
            q[rear++]=tmpb;
        }
        ///
        for(int k=0; k<3; k++)
        {
            for(int p=0; p<3; p++)
                b[k][p]=cur.a[k][p];
        }
        f9();
        if(!vis(b))
        {
            for(int k=0; k<3; k++)
            {
                for(int p=0; p<3; p++)
                    tmpb.a[k][p]=b[k][p];
            }
            tmpb.type=9;
            tmpb.parent=front-1;
            tmpb.step=cur.step+1;
            visit[b[0][0]/3][b[0][1]/3][b[0][2]/3][b[1][0]/3][b[1][1]/3][b[1][2]/3][b[2][0]/3][b[2][1]/3][b[2][2]/3]=true;
            q[rear++]=tmpb;
        }
        //
    }
}
int main()
{
    for(int i=0; i<3; i++)
        for(int j=0; j<3; j++)
        {
            scanf("%d",&tmpa[i][j]);
        }
    memset(visit,false,sizeof(visit));
    visit[tmpa[0][0]/3][tmpa[0][1]/3][tmpa[0][2]/3][tmpa[1][0]/3][tmpa[1][1]/3][tmpa[1][2]/3][tmpa[2][0]/3][tmpa[2][1]/3][tmpa[2][2]/3]=true;
    bfs();
    int s[100000];
    int idx=0;
    for(int i=ans;;)
    {
        if(q[i].parent==-1)
        break;
        //s.push(q[i].type);
        s[idx++]=q[i].type;
        i=q[i].parent;
    }
    cout<<s[idx-1];
    for(int i=idx-2;i>=0;i--)
    {
        cout<<" "<<s[i];
    }
    cout<<endl;
    return 0;
}
/*
9 9 12
6 6 6
6 3 6
*/



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值