zoukankan      html  css  js  c++  java
  • NOIP模拟水题集锦

    大蒟蒻又来水题啦

    NOIP2016玩具谜题

     1 #include<stdio.h>
     2 #include<string>
     3 #include<iostream>
     4 using namespace std;
     5 int n,m;
     6 struct toy
     7 {
     8     int dir;
     9     string name;
    10 };
    11 struct order
    12 {
    13     int dir;
    14     int num;
    15 };
    16 toy toys[100005];
    17 order orders[100005];
    18 int main()
    19 {
    20     scanf("%d%d",&n,&m);
    21     int i;
    22     for(i=1;i<=n;i++)
    23     {
    24         scanf("%d",&toys[i].dir);
    25         cin>>toys[i].name;
    26     }
    27     for(i=1;i<=m;i++)
    28         scanf("%d%d",&orders[i].dir,&orders[i].num);
    29     int now = 1;
    30     for(i=1;i<=m;i++)//0 in 1 out 0 left 1 right
    31     {
    32         if(orders[i].dir)//right
    33         {
    34             if(toys[now].dir)//out
    35             {
    36                 now-= orders[i].num;
    37                 if(now<=0)now+=n;
    38             }
    39             else//in
    40             {
    41                 now+=orders[i].num;
    42                 if(now>n) now-=n;
    43             }
    44         }
    45         else//left
    46         {
    47             if(toys[now].dir)
    48             {
    49                 now+=orders[i].num;
    50                 if(now>n) now-=n;
    51             }
    52             else
    53             {
    54                 now-= orders[i].num;
    55                 if(now<=0)now+=n;
    56             }
    57         }
    58     }
    59     cout<<toys[now].name;
    60     return 0;
    61 }
    View Code

    NOIP2015神奇的幻方

     1 #include<stdio.h>
     2 int hf[40][40],n,n2;
     3 int main()
     4 {
     5     scanf("%d",&n); n2 = n*n;
     6     hf[1][(n>>1)+1] = 1;
     7     int prex = 1,prey = (n>>1)+1;
     8     int nowx,nowy;
     9     int i,j;
    10     for(i=2;i<=n2;i++)
    11     {
    12         if(prex==1&&prey!=n)
    13         {nowx=n;nowy=prey+1;}
    14         else if(prey==n&&prex!=1)
    15         {nowy=1;nowx=prex-1;}
    16         else if(prex==1&&prey==n)
    17         {nowx=2;nowy=n;}
    18         else if(prex!=1&&prey!=n)
    19         {
    20             if(!hf[prex-1][prey+1])
    21             {nowx=prex-1;nowy=prey+1;}
    22             else{nowx=prex+1;nowy=prey;}
    23         }
    24         hf[nowx][nowy] = i;
    25         prex = nowx;prey = nowy;
    26     }
    27     for(i=1;i<=n;i++)
    28     {
    29         for(j=1;j<=n;j++)
    30             printf("%d ",hf[i][j]);
    31         printf("
    ");
    32     }
    33     return 0;
    34 }
    View Code
  • 相关阅读:
    java+selenium自动化-IE浏览器搭建自动化环境
    python中的opencv
    随机森林参数说明
    剑指offer
    Python中常用的包--sklearn
    Anaconda安装,jupyter notebook 使用说明
    C++中的Public 、Private、Protected 区别
    C++类中的Static关键字二
    C++类中的Static关键字
    c语言二级指针内存模型
  • 原文地址:https://www.cnblogs.com/hzs2000/p/7300178.html
Copyright © 2011-2022 走看看