zoukankan      html  css  js  c++  java
  • NOIP模拟赛(洛谷11月月赛)

    T1  终于结束的起点

    题解:枚举啊...

    斐波那契数 第46个爆int,第92个爆long long....

    发现结果一般是m的几倍左右....不用担心T。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    
    int M,N;
    
    int t,f1,f2;
    
    int main()
    {
        scanf("%d",&M);f1=1;f2=1;
        for(int i=3;i;i++)
        {
            t=(f1+f2)%M;
            f1=f2%M;
            f2=t;
            if(f1%M==0&&f2%M==1)
            {
                printf("%d
    ",i-1);
                break;
            }
        }
        return 0;
    }

    T2跳跳!

     

     题解:贪心。

    从当前没跳过的最高的和最低的之间来回跳。

    //预计10分 
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #define LL long long
    using namespace std;
    
    int n;
    
    int h[320],vis[320];
    
    LL ans;
    
    void dfs(int now,int a,LL scor)
    {
        if(a==n)
        {
            ans=max(ans,scor);
            return ;
        }
        for(int i=1;i<=n;i++)
        {
            if(vis[i]) continue;
            vis[i]=true;
            dfs(i,a+1,scor+(h[now]-h[i])*(h[now]-h[i]));
            vis[i]=false;
        }
    }
    
    int main()
    {
        freopen("rand.txt","r",stdin);
        freopen("baoli.txt","w",stdout);
        scanf("%d",&n);
        for(int i=1;i<=n;i++) scanf("%d",&h[i]);
        dfs(0,0,0);
        cout<<ans<<endl;
        return 0;
    }
    20
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #define LL long long
    using namespace std;
    
    int n;
    
    int L,R;
    
    int h[320];
    
    LL ans;
    
    int main()
    {
        scanf("%d",&n);L=0;R=n;
        for(int i=1;i<=n;i++) scanf("%d",&h[i]);
        sort(h,h+n+1);
        while(L<R)
        {
            ans=ans+(h[R]-h[L])*(h[R]-h[L]);
            L++;
            ans=ans+(h[R]-h[L])*(h[R]-h[L]);
            R--;
        }
        cout<<ans<<endl;
        return 0;    
    } 

    T3 抱歉没读懂题目

    T4 不围棋

     题解:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #define N 605
    using namespace std;
    
    int cnt,g,flag,n;
    
    int a[N][N],qx[N*N],qy[N*N],vis[N][N];
    
    int h,t;
    
    int dx[4]={0,1,0,-1},
    
        dy[4]={-1,0,1,0};
    
    char b[N][N];
    
    struct B
    {
        int x,y;
    }c[N*N];
    
    bool canGo(int x,int y,int flag)
    {
        a[x][y]=(flag%2==0?1:-1);              //先放上要走的棋子  
        memset(vis,0,sizeof(vis));
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(vis[i][j]||a[i][j]==0) continue;                    //*****
                h=1;t=0;int js=0;           //扫描联通块 
                qx[++t]=i;qy[t]=j;
                while(h<=t)
                {    
                    int nowx=qx[h],nowy=qy[h];h++;vis[nowx][nowy]=true;
                    for(int v=0;v<4;v++)                                       //*****
                    {
                    
                        int nxtx=nowx+dx[v],nxty=nowy+dy[v]; //遍历四周     
                        if(nxtx<=0||nxty<=0||nxtx>n||nxty>n||vis[nxtx][nxty]) continue;     //*****
                        if(!a[nxtx][nxty]) js++;              //存在气 
                        if(a[nxtx][nxty]==a[nowx][nowy])    
                        {
                            qx[++t]=nxtx;qy[t]=nxty;                            //*****
                        }
                    }
                }
            //    cout<<"--------------"<<endl;
                if(!js)                   //扫描的联通块没有气 
                {
                    a[x][y]=0;            //尝试失败 
                    return false;
                }
            }
        }
        return true;
    }
    
    int main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            cin>>b[i];
            for(int j=1;j<=n;j++)
            {
                if(b[i][j-1]=='.')             //若为空 
                {
                    a[i][j]=0;
                    c[++cnt].x=i;c[cnt].y=j;     //标记空位 
                }
                if(b[i][j-1]=='X') a[i][j]=-1;     //若为黑棋 -1 
                if(b[i][j-1]=='O') a[i][j]=1;      //若为白棋 1 
            }
        }
        if(n==1){printf("-1 -1
    ");return 0;}      //棋盘只有一个空位,先手没法走 
        while(1)
        {
          flag++;g=0;                          //flag标记当前是黑棋还是白棋走 
          for(int i=1;i<=cnt;i++)             //找一个能走的空位 
          {
              int xx,yy;xx=c[i].x;yy=c[i].y;
              if(a[xx][yy]) continue;
              if(canGo(xx,yy,flag)) 
             {
                  printf("%d %d
    ",xx,yy);
                  g=true;a[xx][yy]=(flag%2==0?1:-1);
                  break;
            }
          }
          if(!g)
          {
              printf("-1 -1
    ");
              return 0;
          }
        }
        return 0;
    } 
    30
  • 相关阅读:
    Dockfile编写常见命令
    coreDNS域名无法解析问题
    开源软件
    容器相关
    日常工具
    持续集成
    mysql主从同步
    生产环境MySQL5.7-my.cnf 配置文件 for linux (转)
    工作交接流程引导图
    文章记录
  • 原文地址:https://www.cnblogs.com/zzyh/p/9903973.html
Copyright © 2011-2022 走看看