CCF-CSP 201903-3 损坏的RAID5 70分待优化

原题链接:CCF-CSP 201903-3 损坏的RAID5
在这里插入图片描述

#include <bits/stdc++.h>
using namespace std;
#define ll long long

struct Node
{
    int f;
    vector<string> v;
}node[1010];
map<int,pair<int,int>> mp;

void fun(string& t1,string t2)
{
    map<char,int> m1={{'0',0},{'1',1},{'2',2},{'3',3},{'4',4},\
    {'5',5},{'6',6},{'7',7},{'8',8},{'9',9},{'A',10},{'B',11},\
    {'C',12},{'D',13},{'E',14},{'F',15}};
    string dic="0123456789ABCDEF";
    for(int i=0;i<t1.size();i++)
    {
        int n1=m1[t1[i]];
        int n2=m1[t2[i]];
        int n3=n1^n2;
        t1[i]=dic[n3];
    }
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    int n,s,l; cin>>n>>s>>l;
    int len=0;
    while(l--)
    {
        int id;
        string str;
        cin>>id>>str;
        int i=0;
        node[id].f=1;
        while(i!=str.size())
        {
            string t;
            t=str.substr(i,8);
            node[id].v.push_back(t);
            i+=8;
        }
        len=node[id].v.size();
    }
    int p=n-1,cur=(p+1)%n,h=0;
    int cnt=0;
    while(h<len)
    {
        while(cur!=p)
        {
            pair<int,int> p=make_pair(cur,h);
            mp[cnt]=p;
            cnt+=s;
            cur=(cur+1)%n;
        }
        h+=s;
        p= p>0 ? p-1 : n-1;
        cur=(p+1)%n;
    }
    int m; cin>>m;
    while(m--)
    {
        int b; cin>>b;
        if(b>=cnt)
        {
            cout<<"-"<<endl;
            continue;
        }
        int pre=(b/s)*s;
        auto x=mp[pre];
        int id=x.first,y=x.second;
        y=y+(b-pre);
        if(node[id].f==1) cout<<node[id].v[y]<<endl;
        else
        {
            int num=0;
            string t="00000000";
            for(int i=0;i<n;i++)
            {
                if(num>1)
                {
                    cout<<"-"<<endl;
                    continue;
                }
                if(node[i].f==0) num++;
                else fun(t,node[i].v[y]);
            }
            cout<<t<<endl;
        }
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值