当前位置:网站首页>Ccf-csp 201903-3 damaged RAID5 70 points to be optimized

Ccf-csp 201903-3 damaged RAID5 70 points to be optimized

2022-06-09 02:42:00 Confident little screw

Original link :CCF-CSP 201903-3 The damaged RAID5
 Insert picture description here

#include <bits/stdc++.h>
using namespace std;
const int N=1e3+10;

struct node
{
    
    int exist=0;
    string str;
    vector<string> kuai;
    node()
    {
    
        exist=0;
        str="";
        kuai={
    };
    }
}raid[N];

map<int,pair<int,int>> mp;
vector<int> ex;

string change(string s1,string s2)
{
    
    string dict="0123456789ABCDEF";
    unordered_map<char,int> tmp={
    {
    '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 res;
    for(int i=0;i<s1.size();i++)
    {
    

        int n1=tmp[s1[i]];
        int n2=tmp[s2[i]];
        int n3=n1^n2;
        res+=dict[n3];
    }
    return res;
}

int main()
{
    
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,s,l;
    cin>>n>>s>>l;
    int len=0,num=0;
    for(int i=0;i<l;i++)
    {
    
        string str;
        int id;
        cin>>id>>str;
        ex.push_back(id);
        raid[id].str=str;
        raid[id].exist=1;
        int j=0;
        len=str.size()/8;
        while(j<str.size())
        {
    
            string t;
            t=str.substr(j,8);
            raid[id].kuai.push_back(t);
            j+=8;
        }
    }
    int cur=0,h=0,p=n;
    int sum=0;
    while(sum<n*len)
    {
    
        if(p==0) p=n-1;
        else p--;
        int cnt=(p+1+n)%n;
        //cout<<"p:"<<p<<endl;
        while(cnt!=p)
        {
    
            for(int i=h;i<h+s;i++)
            {
    
                pair<int,int> tmp=make_pair(cnt,i);
                //cout<<cnt<<" "<<i<<" "<<cur<<endl;
                mp[cur]=tmp;
                cur++;
            }
            cnt=(cnt+1+n)%n;
        }
        h+=s;
        sum+=n*s;
    }
    //cout<<"cur:"<<cur<<endl;
    int m; cin>>m;
    for(int i=0;i<m;i++)
    {
    
        int bi;
        cin>>bi;
        if(bi>=cur)
        {
    
            cout<<"-"<<endl;
            continue;
        }
        int id=mp[bi].first;
        int pos=mp[bi].second;
        //cout<<id<<" "<<pos<<endl;
        if(raid[id].exist==1)
        {
    
            cout<<raid[id].kuai[pos]<<endl;
        }
        else
        {
    
            if(l<n-1)
            {
    
                cout<<"-"<<endl;
                continue;
            }
            string res="00000000";
            for(int j=0;j<ex.size();j++)
            {
    
                res=change(res,raid[ex[j]].kuai[pos]);
            }
            cout<<res<<endl;
        }
    }
	return 0;
}


原网站

版权声明
本文为[Confident little screw]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/159/202206081210204604.html