zoukankan      html  css  js  c++  java
  • Top ShooterHDU2863&&继续xxx定律HDU3784

    继续xxx定律 HDU3784

    先看这个题目:HDU3782

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<stdio.h>
     4 #include<string.h>
     5 using namespace std;
     6 int main()
     7 {
     8     int n,s;
     9     while(scanf("%d",&n)!=EOF)
    10     {
    11         if(n==0)
    12             break;
    13         s=0;
    14         while(n!=1)
    15         {
    16             if(n%2==0)
    17             {n=n/2;s++;}
    18             else
    19             {
    20                 n=n*3+1;
    21                 n=n/2;
    22                 s++;
    23             }
    24         }
    25         printf("%d
    ",s);
    26     }
    27     return 0;
    28 }

    之后就是那个题目:YY就行了。

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<string.h>
     4 #include<stdio.h>
     5 using namespace std;
     6 struct line
     7 {
     8     int x,y;
     9 }a[505];
    10 int main()
    11 {
    12     int n,d,d1,m,m1,i,j,k;
    13     int b[5005];
    14     while(scanf("%d",&n)!=EOF)
    15     {
    16         if(n==0)
    17         break;
    18         memset(a,0,sizeof(a));
    19         for(i=0;i<n;i++)
    20         scanf("%d",&a[i].x);
    21         m1=0;
    22         for(i=n-1;i>=0;i--)
    23         {
    24             j=0;
    25             m=a[i].x;
    26             memset(b,0,sizeof(b));
    27             while(m!=1)
    28             {
    29                 if(m%2)
    30                 {
    31                     m=m*3+1;
    32                     m=m/2;
    33                     b[j++]=m;
    34                 }
    35                 else
    36                 {
    37                     m=m/2;
    38                     b[j++]=m;
    39                 }
    40             }
    41             for(j=0;j<n;j++)
    42             {
    43                 if(a[j].y==1)
    44                 continue;
    45                 d=0;d1=0;
    46                 while(b[d]!=0)
    47                 {
    48                     if(a[j].x==b[d])
    49                     {
    50                         d1=1;
    51                         break;
    52                     }
    53                     d++;
    54                 }
    55                 if(d1==1)
    56                 {
    57                     a[j].y=1;m1++;
    58                 }
    59             }
    60         }
    61         j=n-m1;
    62         if(j==1)
    63         {
    64             for(i=n-1;i>=0;i--)
    65         {
    66             if(a[i].y==0)
    67                 printf("%d
    ",a[i].x);
    68         }
    69         }
    70         else if(j!=1)
    71         {
    72             k=0;
    73             for(i=n-1;i>=0;i--)
    74         {
    75             if(a[i].y==0)
    76             {
    77                 printf("%d ",a[i].x);k++;
    78             }
    79             if(k==j-1)
    80             break;
    81         }
    82        for(j=i-1;j>=0;j--)
    83         {
    84             if(a[j].y==0)
    85             printf("%d
    ",a[j].x);
    86         }
    87         }
    88     }
    89     return 0;
    90 }

    Top ShooterHDU2863

    模拟题:

  • 相关阅读:
    Unity3D热更新
    js
    xshell安装运行时提示缺少mfc110.dll
    Linux 分区的概念
    js
    Web 安全测试
    php 获取客户端的浏览器信息
    H5 获取地理位置
    JS -判断、监听屏幕横竖屏切换事件
    css 禁用移动端部分特性
  • 原文地址:https://www.cnblogs.com/tt123/p/3385809.html
Copyright © 2011-2022 走看看