zoukankan      html  css  js  c++  java
  • 关于军训的模拟赛

    关于军训的模拟赛

      晚上的模拟赛,表示体验极差,考试的时候都快睡着了,感觉要完。没想到大家都很困都在各种失误...平常到21点左右我就开始看课件看书了,但是考试考到22点。不过考试本身还是可以的,希望下次能够早一点考。

      后来又考了R2,是上午考的,起晚了导致少考了半个小时,不过这就是我自己的问题了...

      点击此处查看R2

      T1:回文平方数

      给出一个b$2<=b<=20$,求1-300中哪些数在b进制下的平方是回文数。

      
     1 # include <cstdio>
     2 # include <iostream>
     3 
     4 using namespace std;
     5 
     6 int b;
     7 int a[1000],cnt;
     8 char num[30];
     9 
    10 bool check (int x)
    11 {
    12     cnt=0;
    13     x=x*x;
    14     while (x)
    15     {
    16         a[++cnt]=x%b;
    17         x/=b;
    18     }
    19     for (int i=1;i<=cnt/2;++i)
    20         if(a[i]!=a[cnt-i+1]) return false;
    21     return true;
    22 }
    23 
    24 void write (int x)
    25 {
    26     cnt=0;
    27     while (x)
    28     {
    29         a[++cnt]=x%b;
    30         x/=b;
    31     }
    32     for (int i=cnt;i>=1;--i)
    33         printf("%c",num[ a[i] ]);
    34 }
    35 
    36 void init()
    37 {
    38     for (int i=0;i<=9;++i)
    39         num[i]=i+'0';
    40     for (int i=10;i<=20;++i)
    41         num[i]=i-10+'A';
    42 }
    43 
    44 int main()
    45 {
    46     freopen("palsquare.in","r",stdin);
    47     freopen("palsquare.out","w",stdout);
    48 
    49     scanf("%d",&b);
    50     init();
    51     for (int i=1;i<=300;++i)
    52     {
    53         if(check(i))
    54         {
    55             write(i);
    56             printf(" ");
    57             write(i*i);
    58             printf("
    ");
    59         }
    60     }
    61     
    62     fclose(stdin);
    63     fclose(stdout);
    64     return 0;
    65 }
    回文平方数

      签到题,但是由于前面所说的种种原因,有无数dalao倒在了这道题上。

      T2:house

      十分麻烦的大模拟,无法概述题意,不过好像是个奶牛题,应该还是可以找到原题的。

      https://www.luogu.org/problemnew/show/P1457

      首先bfs找联通块并算出大小,再枚举推哪一面墙。这种题一般也就考试的时候做一做了,平时哪有心情做这种=_=

      

      
      1 # include <cstdio>
      2 # include <iostream>
      3 # include <queue>
      4 
      5 using namespace std;
      6 
      7 const int dx[]={0,-1,0,1};
      8 const int dy[]={-1,0,1,0};
      9 int ans,g[55][55],x,n,m,col[55][55],siz[55*55],cnt=0;
     10 bool to[55][55][5]; //0->西,1->北.2->东,3->南; 
     11 queue <int> qx;
     12 queue <int> qy;
     13 
     14 void bfs (int x,int y)
     15 {
     16     col[x][y]=++cnt;
     17     while (qx.size()) qx.pop();
     18     while (qy.size()) qy.pop();
     19     qx.push(x);
     20     qy.push(y);
     21     int nx,ny,xx,yy;
     22     while (qx.size())
     23     {
     24         nx=qx.front();
     25         ny=qy.front();
     26         qx.pop();
     27         qy.pop();
     28         for (int i=0;i<4;++i)
     29         {
     30             if(to[nx][ny][i]) continue;
     31             xx=nx+dx[i];
     32             yy=ny+dy[i];
     33             if(col[xx][yy]) continue;
     34             col[xx][yy]=cnt;
     35             qx.push(xx);
     36             qy.push(yy);
     37         }
     38     }
     39 }
     40 
     41 int main()
     42 {
     43     scanf("%d%d",&m,&n);
     44     for (int i=1;i<=n;++i)
     45         for (int j=1;j<=m;++j)
     46         {
     47             scanf("%d",&x);
     48             for (int k=0;k<4;++k)
     49             {
     50                 to[i][j][k]=x%2;
     51                 x/=2;
     52             }
     53         }
     54     for (int i=1;i<=n;++i)
     55         for (int j=1;j<=m;++j)
     56             if(!col[i][j]) bfs(i,j);
     57     printf("%d
    ",cnt);
     58     for (int i=1;i<=n;++i)
     59         for (int j=1;j<=m;++j)
     60             siz[ col[i][j] ]++;
     61     for (int i=1;i<=cnt;++i)
     62         ans=max(ans,siz[i]);
     63     printf("%d
    ",ans);
     64     ans=0;
     65     int xx,yy,ansx,ansy,ansk;
     66     for (int j=1;j<=m;++j)
     67         for (int i=n;i>=1;--i)
     68         {
     69             for (int k=1;k<=2;++k)
     70             {
     71                 if(to[i][j][k]==false) continue;
     72                 xx=i+dx[k];
     73                 yy=j+dy[k];
     74                 if(col[xx][yy]==col[i][j])
     75                 {
     76                     if(siz[ col[xx][yy] ]>ans)
     77                     {
     78                         ans=siz[ col[xx][yy] ];
     79                         ansx=i;
     80                         ansy=j;
     81                         ansk=k;
     82                     }
     83                 }
     84                 else
     85                 {
     86                     if(siz[ col[xx][yy] ]+siz[ col[i][j] ]>ans)
     87                     {
     88                         ans=siz[ col[xx][yy] ]+siz[ col[i][j] ];
     89                         ansx=i;
     90                         ansy=j;
     91                         ansk=k;
     92                     }
     93                 }
     94             }
     95         }
     96     printf("%d
    ",ans);
     97     printf("%d %d ",ansx,ansy);
     98     if(ansk==1) printf("N");
     99     else printf("E");
    100     return 0;
    101 }
    house

      T3:prime

      把一个4位质数改成另一个四位质数至少需要几步?具体地说,每次只能改一位上的一个数字,且要求每步改完以后都是质数,不能有前导零。

      bfs,瞎搜一气。

      
     1 # include <cstdio>
     2 # include <iostream>
     3 # include <cmath>
     4 # include <cstring>
     5 
     6 using namespace std;
     7 
     8 int a,b,ans;
     9 bool pri[10000];
    10 int min_step[10000];
    11 int q[100000],h,t;
    12 
    13 bool check (int x)
    14 {
    15     for (int i=2;i*i<=x;++i)    
    16         if(x%i==0) return false;
    17     return true;
    18 }
    19 
    20 int bfs()
    21 {
    22     memset(min_step,-1,sizeof(min_step));
    23     min_step[a]=0;
    24     h=t=1;
    25     q[1]=a;
    26     int beg,begg,w[5],x;
    27     while (t-h>=0)
    28     {
    29         begg=beg=q[h];
    30         h++;
    31         if(beg==b) return min_step[beg];
    32         for (int i=1;i<=4;++i)
    33             w[i]=begg%10,begg/=10;
    34         for (int i=1;i<=4;++i)
    35         {
    36             for (int j=0;j<=9;++j)
    37             {
    38                 if(i==4&&j==0) continue;
    39                 x=w[i];
    40                 w[i]=j;
    41                 if(pri[ w[1]+w[2]*10+w[3]*100+w[4]*1000 ]==false) 
    42                 {
    43                     w[i]=x;
    44                     continue;
    45                 }
    46                 if(min_step[ w[1]+w[2]*10+w[3]*100+w[4]*1000 ]==-1)
    47                 {
    48                     min_step[ w[1]+w[2]*10+w[3]*100+w[4]*1000 ]=min_step[beg]+1;
    49                     q[++t]=w[1]+w[2]*10+w[3]*100+w[4]*1000;
    50                 }
    51                 w[i]=x;
    52             }
    53         }
    54     }
    55     return -1;
    56 }
    57 
    58 int main()
    59 {
    60     freopen("prime.in","r",stdin);
    61     freopen("prime.out","w",stdout);
    62 
    63     for (int i=1000;i<=9999;++i)
    64         if(check(i)) pri[i]=true;
    65     scanf("%d%d",&a,&b);
    66     ans=bfs();
    67     if(ans!=-1) printf("%d",ans);
    68     else printf("Impossible");
    69     fclose(stdin);
    70     fclose(stdout);
    71     return 0;
    72 }
    prime

      

      T4:fish

      一道年代久远的题目,数据包显示是1998年创建的。甚至题面都仅仅是一张模糊的照片。(赛后某同学发现如果打开裁剪按钮把图片被剪掉的地方恢复回来,里面还写有pascal的题解...)

      来感受一下上世纪的OI吧。

      

       

      很遗憾,这道题的样例和题面必有一个是错的,后来老师说输出最小方案,可是数据包又成了最大方案导致全场近乎爆零。虽然之前几道题我一直尝试保持清醒,但是这道题挂的很惨,搜索写成死循环;m的限制直接没看见...

      
     1 # include <cstdio>
     2 # include <iostream>
     3 
     4 using namespace std;
     5 
     6 int m,n;
     7 int v[35],rk,val;
     8 int t[35],x,y,firs[35],h;
     9 int ans[35],tot=0,num=0,vis[35];
    10 struct edge
    11 {
    12     int too,nex;
    13 }g[32*32];
    14 
    15 void add (int x,int y)
    16 {
    17     g[++h].too=y;
    18     g[h].nex=firs[x];
    19     firs[x]=h;
    20 }
    21 
    22 bool check (int x)
    23 {
    24     for (int i=firs[x];i;i=g[i].nex)
    25         if(vis[ g[i].too ]) return false;
    26     return true;
    27 }
    28 
    29 void dfs (int x,int co,int cnt)
    30 {
    31     if(co>m) return ;
    32     if(x==n+1)
    33     {
    34         if(cnt>tot||(cnt==tot&&co<num))
    35         {
    36             tot=cnt;
    37             num=co;
    38         }
    39         return ;
    40     }
    41     dfs(x+1,co,cnt);
    42     if(check(x))
    43     {
    44         vis[x]=true;
    45         dfs(x+1,co+v[x],cnt+1);
    46         vis[x]=false;
    47     }
    48 }
    49 
    50 int main()
    51 {
    52     freopen("fish.in","r",stdin);
    53     freopen("fish.out","w",stdout);
    54 
    55     scanf("%d%d",&m,&n);
    56     for (int i=1;i<=n;++i)
    57     {
    58         scanf("%d%d",&rk,&val);    
    59         v[rk]=max(v[rk],val);        
    60     }
    61     scanf("%d%d",&x,&y);
    62     while (x&&y)
    63     {
    64         add(x,y);
    65         add(y,x);
    66         scanf("%d%d",&x,&y);
    67     }
    68     dfs(1,0,0);
    69     printf("%d %d
    ",tot,num);
    70     fclose(stdin);
    71     fclose(stdout);
    72     return 0;
    73 }
    fish(改后)

      

      考前还专门背了对拍,然而搜索拍搜索又有什么意思呢。

      最后,"关于军训的模拟赛",军训在哪里啊?很简单,考好了就不用去军训了。然而...感到悲凉。

      ---shzr

  • 相关阅读:
    复选框与全选框的选中状态的联动
    用localStorage在页面间传值
    移动端页面输入法挡住input输入框的解决方法
    input[type=file]上传图片及转为base64码以及预览
    截取url参数
    图片加载完成再执行事件
    每天记录一点点
    图片懒加载
    @ font-face 引入本地字体文件
    vue 仿zTree折叠树
  • 原文地址:https://www.cnblogs.com/shzr/p/9466252.html
Copyright © 2011-2022 走看看