zoukankan      html  css  js  c++  java
  • 洛谷P1124 文件压缩 模拟

    洛谷P1124 文件压缩
    模拟

     1 #include <bits/stdc++.h> 
     2 #define For(i,j,k) for(int i=j;i<=k;i++)
     3 using namespace std ; 
     4 
     5 const int N = 10011 ; 
     6 int n,mid,p ; 
     7 char s[N] ; 
     8 int le[N],ri[N],sum[N],ans[N] ; 
     9 
    10 inline int read() 
    11 {
    12     int x = 0 , f = 1 ; 
    13     char ch = getchar() ; 
    14     while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar(); } 
    15     while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar(); } 
    16     return x * f ; 
    17 }
    18 
    19 int main() 
    20 {
    21     n = read() ; mid = n ; 
    22     scanf("%s",s+1) ; 
    23     For(i,1,n) 
    24         le[ i ] = ri[ i ] = s[ i ] - 96 ;         //  这题  p 会等于  0  
    25     p = read() ;  
    26     if(n==1) {
    27         printf("%c",ri[ n ]+96) ; 
    28         return 0 ; 
    29     }
    30     sort(le+1,le+n+1) ; 
    31     printf("%c",ri[ p ]+96) ;    
    32     For(i,1,n) 
    33         sum[ le[ i ] ] = i ;           
    34         
    35     For(i,1,n) 
    36         if(le[i]==ri[p]) {
    37             ans[ n ] = ri[ i ] ;   
    38             p = ri[ i ] ;  
    39             break ; 
    40         }
    41     
    42     while(1) {
    43         if(n<=2) break ; 
    44         n-- ; 
    45         ans[ n ] = ri[ sum[ p ] ] ; 
    46         sum[p]-- ; 
    47         p = ans[ n ] ; 
    48     }
    49     For(i,2,mid) printf("%c",ans[ i ]+96) ; 
    50     return 0 ; 
    51 }
  • 相关阅读:
    java UDP传输
    InetAddress与Socket
    TCP和UDP的联系和用途
    网络通讯要素
    什么是网络编程?
    java 合并流(SequenceInputStream)
    最长上升子序列之基础
    《Linux Device Drivers》第十五章 内存映射和DMA——note
    HDU 5092 DP
    NGUI: UIPanel控件
  • 原文地址:https://www.cnblogs.com/third2333/p/7221027.html
Copyright © 2011-2022 走看看