现在的位置: 首页 > 综合 > 正文

组队赛130930 – from lanshui_Yang

2019年01月07日 ⁄ 综合 ⁄ 共 2642字 ⁄ 字号 评论关闭

BNU 27542 (LA 4875)Just The Simple Fax 

        大模拟,不再详述,但是此题的输入还是有技巧的,可以借鉴。直接上代码:

#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>

#define mem(a , b) memset(a , b , sizeof(a))
#define MAX 1000
#define INF 1e8
using namespace std ;
const int HU = 80 ;
const int MAXN = 10005 ;
int pan1 = 1 << 3 ;
int b0 = 7 ;
char s[MAXN] ;
char ans[MAXN] ;
int t[MAXN] ;
int ca ;
int B ;
int n ;
int k ;
int len ;
int cnt ;
char tmp[MAXN] ;
char zf(int x)
{
    if(x >= 10)
        return 'A' + x - 10 ;
    return '0' + x ;
}
void init()  // 输入
{
    int i ;
    for(i = 0 ; i < n ; i ++)
    {
        scanf("%s" , s + i * 80) ;  // 技巧性
    }
}
void prechu()
{
    len = strlen(s) ;
    int i ;
    for(i = 0 ; i < len ;) 
    {
        int st = i ;
        int e = i ;
        char a , b ;
        a = s[st] ;
        b = s[st + 1] ;
        int sum = 0 ;
        while (1)
        {
            if(e < len && s[e] == a && s[e + 1] == b)
            {
                sum ++ ;
                e += 2 ;
            }
            else
                break ;
        }
        int j ;
        for(j = st ; j < e ; j ++)
        {
            t[j] = sum ;
        }
        i = e ;
    }
}
void midchu()
{
    int i ;
    int k ;
    for(i = 0 ; i < len ;) 
    {
        k = 0 ;
        int st = i ;
        int e = i ;
        char a , b ;
        a = s[st] ;
        b = s[st + 1] ;
        if(t[e] <= 2)
        {
            while (e < len && t[e] <= 2)
            {
                if(k == 128)
                {
                    break ;
                }
                k ++ ;
                e += 2 ;
            }
            int tg = k - 1 ;
            tg = k - 1 ;
            tg = tg >> 4 ;
            ans[cnt ++] = zf(tg) ;
            tg = k - 1 ;
            tg = tg & 15 ;
            ans[cnt ++] = zf(tg) ;
            for(int tk = st ; tk < e ;) 
            {
                ans[cnt ++] = s[tk ++] ;
            }
            i = e ;
        }
        else
        {
            while (e < len && s[e] == a && s[e + 1] == b)
            {
                if(k == 130)
                {
                    break ;
                }
                k ++ ;
                e += 2 ;
            }
            if(k >= 3)
            {
                k -= 3 ;
                int tg = k ;
                tg = tg | (1 << 7) ;
                int tg1 = tg >> 4 ;
                ans[cnt ++] = zf(tg1) ;
                tg1 = tg & 15 ;
                ans[cnt ++] = zf(tg1) ;
                ans[cnt ++] = a ;
                ans[cnt ++] = b ;
            }
            else
            {
                int tg = k - 1 ;
                tg = k - 1 ;
                tg = tg >> 4 ;
                ans[cnt ++] = zf(tg) ;
                tg = k - 1 ;
                tg = tg & 15 ;
                ans[cnt ++] = zf(tg) ;
                for(int tk = 0 ; tk < k ; tk ++)
                {
                    ans[cnt ++] = a ;
                    ans[cnt ++] = b ;
                }
            }
            i = e ;
        }
    }
}
void solve()
{
    prechu() ;
    midchu() ;
    printf("%d %d\n" , ca , cnt / 2) ;
    int i ;
    for(i = 0 ; i < cnt ; i ++)
    {
        if(i % HU == 0 && i > 0) puts("") ;
        printf("%c" , ans[i]) ;
    }
    puts("") ;
}
int main()
{
    int T ;
    scanf("%d" , &T) ;
    while (T --)
    {
        scanf("%d%d" , &ca , &B) ;
        B += B ;
        cnt = 0 ;
        n = B / HU ;
        if(B % HU != 0)
            n ++ ;
        init() ;
        solve() ;
    }
    return 0;
}


LA 4876 Show Me The Fax (和上题互为逆过程,不过此题较简单)

      直接上代码:

#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>

#define mem(a , b) memset(a , b , sizeof(a))
#define MAX 1000
#define INF 1e8
using namespace std ;
const int HU = 80 ;
const int MAXN = 10005 ;
int pan1 = 1 << 3 ;
int b0 = 7 ;
char s[MAXN] ;
char ans[MAXN] ;
int ca ;
int B ;
int n ;
int k ;
int len ;
int cnt ;
int isUp(char x)
{
    if(x >= 'A' && x <= 'Z')
        return 1 ;
    return 0 ;
}
void init()
{
    int i ;
    for(i = 0 ; i < n ; i ++)
    {
        scanf("%s" , s + i * 80) ;
    }
}
void solve()
{
    len = strlen(s) ;
    int i , j ;
    for(j = 0 ; j < len ;) 
    {
        int a , b ;
        if(isUp(s[j]))
        {
            a = s[j] - 'A' + 10 ;
        }
        else
        {
            a = s[j] - '0' ;
        }
        j ++ ;
        if(isUp(s[j]))
        {
            b = s[j] - 'A' + 10 ;
        }
        else
        {
            b = s[j] - '0' ;
        }
        int ts = 0 ;
        if(a & pan1)
        {
            a &= b0 ;
            a = a << 4 ;
            ts = a + b ;
            ts += 3 ;
            for(k = 0 ; k < ts ; k ++)
            {
                ans[cnt ++ ] = s[j + 1] ;
                ans[cnt ++ ] = s[j + 2] ;
            }
            j += 3 ;
        }
        else
        {
            a = a << 4 ;
            ts = a + b ;
            ts ++ ;
            for(k = 0 ; k < ts ; k ++)
            {
                j ++ ;
                ans[cnt ++ ] = s[j] ;
                j ++ ;
                ans[cnt ++ ] = s[j] ;
            }
            j ++ ;
        }
    }
    printf("%d %d\n" , ca , cnt / 2) ;
    for(i = 0 ; i < cnt ; i ++)
    {
        if(i % HU == 0 && i > 0) puts("") ;
        printf("%c" , ans[i]) ;
    }
    puts("") ;
}
int main()
{
    int T ;
    scanf("%d" , &T) ;
    while (T --)
    {
        scanf("%d%d" , &ca , &B) ;
        B += B ;
        cnt = 0 ;
        n = B / HU ;
        if(B % HU != 0)
            n ++ ;
        init() ;
        solve() ;
    }
    return 0;
}








抱歉!评论已关闭.