Integer to Roman & Roman to Integer

class Solution {
public:
    const string romans[4][10] = {  
        {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"},  
        {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"},  
        {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"},  
        {"", "M", "MM", "MMM", "", "", "", "", "", ""}  
    };
    string intToRoman(int num) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function    
        int p=0;
        string res="";
        while (num>0) {
            int n=num%10;
            num/=10;
            res=romans[p][n]+res;
            p++;
        }
        return res;
    }
};

1/17/14:

greedy:

class Solution {
public:
    string intToRoman(int num) {
        string roman[] = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};    
        int nums[] = {1000,900,500,400,100,90,50,40,10,9,5,4,1};
        string res="";
        int cur=num;
        int i=0;
        while (cur>0) {
            for (; i<13; i++) {
                if (cur>=nums[i]) {
                    break;
                }
            }
            res.append(roman[i]);
            cur -=nums[i];
        }
        return res;
    }
};

Roman to Integer

class Solution {
public:
    const string romans[4][10] = {  
        {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"},  
        {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"},  
        {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"},  
        {"", "M", "MM", "MMM", "", "", "", "", "", ""}  
    };
    int singleValue(char c) {
        switch (c) {
            case 'I': return 1;
            case 'V': return 5;
            case 'X': return 10;
            case 'L': return 50;
            case 'C': return 100;
            case 'D': return 500;
            case 'M': return 1000;
        }
    }
    int romanToInt(string s) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        int res=0;
        int i=0;
        int pre=singleValue(s[0]);
        for (; i<s.size(); i++) {
            int now=singleValue(s[i]);
            if (pre<now) {
                res=res-2*pre+now;
            }else {
                res+=now;
            }
            pre=now;
            
        }
        return res;
    }
};

1/17/14: traverse backwards, if current one is smaller than the previous one, subtract the current number form the result, otherwise, add it to the result.

class Solution {
public:
    int romanToInt(string s) {
        map<char, int> m;
        m['M'] = 1000;
        m['D'] = 500;
        m['C'] = 100;
        m['L'] = 50;
        m['X'] = 10;
        m['V'] = 5;
        m['I'] = 1;
        
        int res=m[s[s.size()-1]];
        for (int i=s.size()-2; i>=0; i--) {
            if (m[s[i]]>=m[s[i+1]]) {
                res +=m[s[i]];
            }else {
                res -=m[s[i]];
            }
        }
        return res;
    }
};


基于共轭转移与噬菌体介导的 CRISPR 系统对抗耐药菌的建模研究(Matlab代码实现)内容概要:本文围绕&ldquo;基于共轭转移与噬菌体介导的CRISPR系统对抗耐药菌&rdquo;的生物医学工程建模研究展开,重点介绍了利用Matlab进行系统建模与仿真分析的技术路线。研究结合合成生物学与微生物基因编辑机制,构建了描述共轭转移、噬菌体感染及CRISPR-Cas系统靶向清除耐药菌的动力学模型,旨在通过数学建模手段揭示该复合系统的抗菌效率与稳定性特征。文中提供了完整的Matlab代码实现,便于复现和进一步优化,体现了理论建模与实验设计之间的桥梁作用。; 适合人群:具备一定生物信息学、系统生物学或控制工程背景,熟悉Matlab编程,从事交叉学科科研工作的研究生、青年科研人员及生物工程领域开发者。; 使用场景及目标:①用于理解并模拟CRISPR系统在微生物群体中传播与调控的动态行为;②支持抗菌策略的设计与优化,特别是在应对多重耐药菌感染方面提供理论依据;③适用于科研教学、项目原型开发及学术论文复现。; 阅读建议:建议读者结合分子生物学基础知识与Matlab编程实践同步学习,重点关注模型假设的合理性、微分方程构建逻辑及参数敏感性分析部分,以便深入掌握建模思想并灵活迁移至其他生物系统仿真任务中。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值