• HDU 5071 Chat (14鞍山区域赛 B) 模拟


    题意:无力写了。

    解题思路:纯模拟

    解题代码:

      1 // File Name: b.cpp
      2 // Author: darkdream
      3 // Created Time: 2014年10月22日 星期三 15时51分59秒
      4 
      5 #include<vector>
      6 #include<list>
      7 #include<map>
      8 #include<set>
      9 #include<deque>
     10 #include<stack>
     11 #include<bitset>
     12 #include<algorithm>
     13 #include<functional>
     14 #include<numeric>
     15 #include<utility>
     16 #include<sstream>
     17 #include<iostream>
     18 #include<iomanip>
     19 #include<cstdio>
     20 #include<cmath>
     21 #include<cstdlib>
     22 #include<cstring>
     23 #include<ctime>
     24 #define LL long long
     25 
     26 using namespace std;
     27 struct node{
     28    int x;
     29    LL v ;
     30    int ne , la; 
     31 }a[6004];
     32 char str[10];
     33 int first;
     34 int last ;
     35 int top = 0 ;
     36 void print()
     37 {
     38    for(int i = a[0].ne;i  != 6000 ;i = a[i].ne)
     39    {
     40      printf("%d %lld
    ",a[i].x, a[i].v);
     41    }
     42 }
     43 int find(int x)
     44 {
     45    //printf("%d
    ",a[0].ne);
     46    for(int i = a[0].ne;i  != 6000 ;i = a[i].ne)
     47    {
     48        if(a[i].x == x)
     49            return i ;
     50    }
     51    return 0 ; 
     52 }
     53 int L;
     54 void add(int x )
     55 {
     56    if(find(x))
     57    {
     58      printf("same priority.
    ");
     59    }else {
     60      printf("success.
    ");
     61      L ++ ;
     62      a[L].x = x; 
     63      a[L].v = 0 ; 
     64      a[L].ne = last;
     65      a[L].la = a[last].la;
     66      a[a[last].la].ne = L;
     67      a[last].la = L; 
     68    }
     69 }
     70 void chat(int x)
     71 {
     72    if(a[first].ne == 6000)
     73    {
     74       printf("empty.
    ");
     75       return;
     76    }
     77    printf("success.
    ");
     78    if(top)
     79    {
     80       a[top].v += x;   
     81    }else {
     82        a[a[first].ne].v += x; 
     83    }
     84 }
     85 void close(int x)
     86 {
     87    int k = find(x);
     88    if(k)
     89    {
     90       printf("close %d with %lld.
    ",a[k].x,a[k].v);
     91       a[a[k].la].ne = a[k].ne;
     92       a[a[k].ne].la = a[k].la;
     93       if(a[k].x == top)
     94       {
     95         top = 0 ; 
     96       }
     97    }else {
     98      printf("invalid priority.
    ");
     99    }
    100 }
    101 void rotata(int x)
    102 {
    103    int t = 1 ; 
    104    for(int i = a[first].ne ;i != last;i = a[i].ne)
    105    {
    106        if(t == x)
    107        {
    108            a[a[i].la].ne = a[i].ne;
    109            a[a[i].ne].la = a[i].la;
    110            
    111            a[i].ne = a[first].ne;
    112            a[i].la = first;
    113            a[a[first].ne].la = i;
    114            a[first].ne = i; 
    115            printf("success.
    ");
    116            return;
    117        }
    118        t ++;
    119    }
    120    printf("out of range.
    ");
    121 }
    122 void Prior()
    123 {
    124    if(a[first].ne == last)
    125    {
    126      printf("empty.
    ");
    127      return;
    128    }
    129    int mx = 0 ; 
    130    int site = 0;
    131    for(int i = a[first].ne ;i != last;i = a[i].ne)
    132    {
    133       if(a[i].x  > mx)
    134       {
    135          site = i ; 
    136          mx = a[i].x; 
    137       }
    138    }
    139            a[a[site].la].ne = a[site].ne;
    140            a[a[site].ne].la = a[site].la;
    141            
    142            a[site].ne = a[first].ne;
    143            a[site].la = first;
    144            a[a[first].ne].la = site;
    145            a[first].ne = site; 
    146    printf("success.
    ") ;  
    147 }
    148 void  choose(int x)
    149 {
    150     int site = find(x);
    151     if(site == 0 )
    152     {
    153       printf("invalid priority.
    ");
    154       return;
    155     }
    156            a[a[site].la].ne = a[site].ne;
    157            a[a[site].ne].la = a[site].la;
    158            
    159            a[site].ne = a[first].ne;
    160            a[site].la = first;
    161            a[a[first].ne].la = site;
    162            a[first].ne = site; 
    163    printf("success.
    ") ;  
    164 }
    165 void Top(int x)
    166 {
    167     int site = find(x);
    168     if(site == 0 )
    169     {
    170       printf("invalid priority.
    ");
    171       return;
    172     }
    173     top = site;
    174     printf("success.
    ") ;  
    175 }
    176 void Untop()
    177 {
    178    if(top == 0 )
    179    {
    180      printf("no such person.
    ");
    181      return;
    182    }
    183    top = 0 ; 
    184     printf("success.
    ") ;  
    185 }
    186 void say()
    187 {
    188   if(top)
    189   {
    190    if(a[top].v != 0 )
    191      printf("Bye %d: %lld
    ",a[top].x,a[top].v);
    192   }
    193   for(int i = a[0].ne;i != last;i  = a[i].ne)
    194   {
    195     if(i != top && a[i].v != 0 )
    196      printf("Bye %d: %lld
    ",a[i].x,a[i].v);
    197   }
    198 }
    199 int main(){
    200     int t; 
    201     scanf("%d",&t);
    202     while(t--)
    203     {
    204       int n ;
    205       memset(a,0,sizeof(a));
    206       scanf("%d",&n);
    207       a[0].ne = 6000 ; 
    208       a[0].la = 6000; 
    209       a[6000].ne = 0;
    210       a[6000].la = 0;
    211       first = 0 ; 
    212       last = 6000;
    213       top = 0 ; 
    214       int tmp;
    215       L = 0 ; 
    216       for(int i = 1;i <= n;i ++)
    217       {
    218           scanf("%s",str);
    219           printf("Operation #%d: ",i);
    220           if(str[0] == 'A')
    221           {
    222             scanf("%d",&tmp) ;
    223             add(tmp);
    224           }else if(str[0] == 'C' && str[1] == 'l')
    225           {
    226             scanf("%d",&tmp);
    227             close(tmp);    
    228           }else if(str[0] == 'C' && str[1] == 'h' && str[2] == 'a')
    229           {
    230             scanf("%d",&tmp);
    231             chat(tmp);    
    232           }else if(str[0] == 'R' && str[1] == 'o')
    233           {
    234             scanf("%d",&tmp);
    235             rotata(tmp);    
    236           }else if(str[0] == 'P' && str[1] == 'r')
    237           {
    238              Prior();
    239           }else if(str[0] == 'C' && str[1] == 'h' && str[2] == 'o')
    240           {
    241              scanf("%d",&tmp);
    242              choose(tmp);
    243           }else if(str[0] == 'T')
    244           {
    245               scanf("%d",&tmp);
    246               Top(tmp);
    247           }else{
    248              Untop();
    249           }
    250           //print();
    251       }
    252       say();
    253     }
    254     return 0;
    255 }
    View Code
    没有梦想,何谈远方
  • 相关阅读:
    不同品牌交换机设置telnet方法
    Oracle 11G RAC For Windows 2008 R2部署手册(亲测,成功实施多次)
    oracle 11g ADG实施手册(亲测,已成功部署多次)
    如何正确的使用uwsgi
    debian小巧好看的桌面
    zsh中home键失灵问题
    C#_Markov_心得感想
    NLP—WordNet——词与词之间的最小距离
    这不算爬虫吧?!
    Table-Driven Design 表驱动设计
  • 原文地址:https://www.cnblogs.com/zyue/p/4044072.html
Copyright © 2020-2023  润新知