zoukankan      html  css  js  c++  java
  • 天梯赛座位分配

    题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805081289900032

    自己模拟死活出错,用了vector后就比较轻松,充分说明数据结构的优越性

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 const int inf=1<<30;
     4 typedef long long ll;
     5 const double pi=acos(-1);
     6 const int mod=1e8+7;
     7 const int maxn=110;
     8 int m[maxn];int n;
     9 int id[10001];
    10 int main(){
    11     scanf("%d",&n);
    12     for(int i=1;i<=n;i++){
    13         scanf("%d",&m[i]);
    14     }
    15     vector< vector<int> > v(n+1);//设一个向量组,提前已经有0-n个向量空间分配了
    16     int cnt=1;
    17     while(1){
    18         bool flag=true;
    19         for(int i=1;i<=n;i++){
    20             if(v[i].size()<m[i]*10){
    21                 if(id[cnt-1]!=i){
    22                     id[cnt]=i;
    23                     v[i].push_back(cnt);
    24                     cnt++;
    25                 }
    26                 else if(id[cnt-1]==i){
    27                     id[cnt+1]=i;
    28                     v[i].push_back(cnt+1);
    29                     cnt+=2;
    30                 }
    31                 flag=false;
    32             }
    33         }
    34         if(flag) break;
    35     }
    36     for(int i=1;i<=n;i++){
    37         printf("#%d
    ",i);
    38         for(int j=0;j<v[i].size();j++){            
    39             if(j!=0&&j%10==0) cout<<endl;
    40             else if(j!=0&&j%10!=0) cout<<" ";
    41             cout<<v[i][j];
    42         }
    43         cout<<endl;
    44     }
    45     return 0;
    46 }
  • 相关阅读:
    YL杯超级篮球赛 (Standard IO)
    Window (Standard IO)
    toj1026 Network 双连通分量
    poj3177 Redundant Paths 双连通分量
    poj1144 Network 双连通分量
    bzoj1269
    bzoj1800
    CF911D
    CF910C
    CF910B
  • 原文地址:https://www.cnblogs.com/qingjiuling/p/10470879.html
Copyright © 2011-2022 走看看