1 solutions

  • 0
    @ 2025-3-3 16:29:41

    C++ :

    #include <iostream>
    using namespace std;
    
    //a数组存放部分肥胖基因染色,如果一段基因被之前的基因染色,那么就不需要锁 
    //b数组用来对肥胖基因全部染色 
    int n,m,a[1000010],b[1000010];
    string s,w;//s存放基因序列,w存放肥胖基因序列 
    int len,c;//len表示染色长度,c:代表基因锁个数 
    bool f;//判断基因是否染色 
    
    int main(){
    	cin>>n>>m;
    	cin>>s>>w;
    	int i,j;
    	//循环每个基因字符
    	for(i = 0;i < n;i++){
    		//如果当前连续m个字符不是肥胖基因 
    		if(s.substr(i,m) != w) continue;
    		
    		f = false;//假设该基因没有染色过,那么就需要锁
    		for(j = i;j < i + m;j++){
    			//如果该基因染色过,那么可以连带染色 
    			if(a[j] == 1){
    				f = true;
    				break;
    			}
    			a[j] = 1;//为基因染色 
    		} 
    		
    		//标记染色 
    		for(j = i;j < i + m;j++){
    			b[j] = 1;
    		} 
    		
    		//如果基因完全没有染色,则需要1把锁 
    		if(f == false) c++; 
    	}
    	
    	//计算肥胖基因长度
    	for(i = 0;i < n;i++){
    		if(b[i] == 1) len++;
    	} 
    	
    	cout<<len<<" "<<c<<endl;
    }
    
    
    • 1

    Information

    ID
    10295
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By