zoukankan      html  css  js  c++  java
  • 天梯L1-049 天梯赛座位分布

    题意就是按顺序分配,不过到最后只有一队的时候就要隔开坐,也就是当上一个分配的人是同校学生的时候,需要特判。

    我还以为是从当前的人开始隔开坐。。。的确是没理解题意。附上测试数据。

      1 #include <iostream>
      2 #include <cstdio>
      3 #include <cstring>
      4 #include <queue>
      5 #include <algorithm>
      6 #define ll long long
      7 
      8 using namespace std;
      9 
     10 int n;
     11 struct node
     12 {
     13     int m,cnt;
     14     int pos[11][11];
     15     node()
     16     {
     17         m=cnt=0;
     18     }
     19 } nodes[110];
     20 
     21 int main()
     22 {
     23     int i,j,k,last;
     24     while(scanf("%d",&n)!=EOF)
     25     {
     26         int sum=0;
     27         for(i=0; i<n; i++)
     28         {
     29             scanf("%d",&nodes[i].m);
     30             sum+=nodes[i].m;
     31             nodes[i].cnt=0;
     32         }
     33         int amt;
     34         for(i=1; i<=sum*10;)
     35         {
     36             amt=0;
     37             for(j=0; j<n; j++)
     38                 if(nodes[j].cnt==nodes[j].m*10)
     39                     amt++;
     40                 else
     41                     last=j;
     42             for(j=0; j<n; j++)
     43             {
     44                 if(nodes[j].cnt==nodes[j].m*10)
     45                 {
     46                     continue;
     47                 }
     48                 nodes[j].pos[nodes[j].cnt/10][nodes[j].cnt%10]=i;
     49                 nodes[j].cnt++;
     50                 i++;
     51                 if(nodes[j].cnt==nodes[j].m*10)
     52                     amt++;
     53                 else
     54                     last=j;
     55                 if(amt==n-1)//排到最后一个学校的时候
     56                 {
     57                     if(i==2)//特判初始只有一个学校的时候
     58                     {
     59                         nodes[last].cnt=0;
     60                         i=1;
     61                     }
     62                     if(nodes[last].cnt%10)//最后剩下几队还多一人时要隔开一个座位
     63                     {
     64                         nodes[last].pos[nodes[last].cnt/10][nodes[last].cnt%10]=i;
     65                         nodes[last].cnt++;
     66                         i++;
     67                         i++;
     68                     }
     69                     for(j=nodes[last].cnt/10; j<nodes[last].m; j++)
     70                     {
     71                         for(k=0; k<10; k++,i+=2)
     72                             nodes[last].pos[j][k]=i;
     73                     }
     74                     break;
     75                 }
     76             }
     77 
     78         }
     79         for(i=0; i<n; i++)
     80         {
     81             printf("#%d
    ",i+1);
     82             for(j=0; j<nodes[i].m; j++)
     83             {
     84                 for(k=0; k<9; k++)
     85                     printf("%d ",nodes[i].pos[j][k]);
     86                 printf("%d
    ",nodes[i].pos[j][k]);
     87             }
     88         }
     89     }
     90     return 0;
     91 }
     92 
     93 
     94 /*
     95 
     96 
     97 2
     98 1 2
     99 
    100 2
    101 2 1
    102 
    103 2
    104 1 0
    105 
    106 3
    107 3 1 1
    108 
    109 3
    110 3 4 2
    111 
    112 #1
    113 1 4 7 10 13 16 19 22 25 28
    114 31 34 37 40 43 46 49 52 55 58
    115 61 63 65 67 69 71 73 75 77 79
    116 #2
    117 2 5 8 11 14 17 20 23 26 29
    118 32 35 38 41 44 47 50 53 56 59
    119 62 64 66 68 70 72 74 76 78 80
    120 82 84 86 88 90 92 94 96 98 100
    121 #3
    122 3 6 9 12 15 18 21 24 27 30
    123 33 36 39 42 45 48 51 54 57 60
    124 
    125 
    126 */
    View Code

    这次天梯赛校内选拔37人,排名25,别人拿的分是我的两倍。真的是太菜了。之前做过的原题都没过。

  • 相关阅读:
    《杀死比尔 卷1》(Kill Bill: Volume 1)思路.未剪切全彩版.720re.DTS[HDTVRE]
    IronPython 1.0 Release Candidate 2
    Microsoft® Visual Studio® .NET™ 2003 Service Pack 1
    Vista Transformation Pack 5.0 发布
    捡到一小猫
    《魔比斯环》(Thru The Moebius Strip)[DVDScr]
    用户控件 分类列表导航栏
    MsChart<5> 累计柱状图 分类统计
    二进制流上传图片,预览,读取显示
    Ajax无刷新数据绑定
  • 原文地址:https://www.cnblogs.com/canchan/p/10504721.html
Copyright © 2011-2022 走看看