博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SRM 396(1-250pt)
阅读量:6678 次
发布时间:2019-06-25

本文共 3915 字,大约阅读时间需要 13 分钟。

DIV1 250pt

题意:对于一个字符串s,若对于每一个i = 0 to s.size()-p-1都有s[i] = s[i+p]则称字符串s是p循环的。"CATCATC", "CATCAT", "ACTAC" , "ACT"都是3循环。给定字符串s和一个数字ma,问至少修改多少个s中字符才能使得s变为k循环的,且k <= ma。

解法:水题,暴力枚举k = 1 to ma即可。

tag:think

1 // BEGIN CUT HERE  2 /*  3  * Author:  plum rain  4  * score :  5  */  6 /*  7   8  */  9 // END CUT HERE 10 #line 11 "DNAString.cpp" 11 #include 
12 #include
13 #include
14 #include
15 #include
16 #include
17 #include
18 #include
19 #include
20 #include
21 #include
22 #include
23 #include
24 #include
25 #include
26 #include
27 #include
28 #include
29 #include
30 #include
31 #include
32 #include
33 #include
34 35 using namespace std; 36 37 #define clr0(x) memset(x, 0, sizeof(x)) 38 #define clr1(x) memset(x, -1, sizeof(x)) 39 #define pb push_back 40 #define sz(v) ((int)(v).size()) 41 #define all(t) t.begin(),t.end() 42 #define zero(x) (((x)>0?(x):-(x))
VI; 49 typedef vector
VS; 50 typedef vector
VD; 51 typedef pair
pii; 52 typedef long long int64; 53 54 const double eps = 1e-8; 55 const double PI = atan(1.0)*4; 56 const int inf = 2139062143 / 2; 57 58 string s; 59 int d[10]; 60 string temp = "ACTG"; 61 62 int gao(int x) 63 { 64 int ret = 0; 65 for (int i = 0; i < x; ++ i){ 66 clr0 (d); 67 int j = i; 68 while (j < sz(s)){ 69 for (int t = 0; t < 4; ++ t) 70 if (temp[t] == s[j]) ++ d[t]; 71 j += x; 72 } 73 int ma = 0, sum = 0; 74 for (int k = 0; k < 4; ++ k) 75 ma = max(ma, d[k]), sum += d[k]; 76 ret += sum - ma; 77 } 78 return ret; 79 } 80 81 class DNAString 82 { 83 public: 84 int minChanges(int m, vector
dna){ 85 s = accumulate(dna.begin(), dna.end(), string("")); 86 int ans = inf; 87 for (int i = 1; i <= m; ++ i) ans = min(ans, gao(i)); 88 return ans; 89 } 90 91 // BEGIN CUT HERE 92 public: 93 void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); } 94 private: 95 template
string print_array(const vector
&V) { ostringstream os; os << "{ "; for (typename vector
::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); } 96 void verify_case(int Case, const int &Expected, const int &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } } 97 void test_case_0() { int Arg0 = 3; string Arr1[] = { "ATAGATA"}; vector
Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); int Arg2 = 1; verify_case(0, Arg2, minChanges(Arg0, Arg1)); } 98 void test_case_1() { int Arg0 = 2; string Arr1[] = { "ACGTGCA"}; vector
Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); int Arg2 = 3; verify_case(1, Arg2, minChanges(Arg0, Arg1)); } 99 void test_case_2() { int Arg0 = 13; string Arr1[] = { "ACGCTGACAGATA"}; vector
Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); int Arg2 = 0; verify_case(2, Arg2, minChanges(Arg0, Arg1)); }100 void test_case_3() { int Arg0 = 1; string Arr1[] = { "AAAATTTCCG"}; vector
Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); int Arg2 = 6; verify_case(3, Arg2, minChanges(Arg0, Arg1)); }101 void test_case_4() { int Arg0 = 12; string Arr1[] = { "ACGTATAGCATGACA","ACAGATATTATG","ACAGATGTAGCAGTA","ACCA","GAC"}; vector
Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); int Arg2 = 20; verify_case(4, Arg2, minChanges(Arg0, Arg1)); }102 103 // END CUT HERE104 105 };106 107 // BEGIN CUT HERE108 int main()109 {110 // freopen( "a.out" , "w" , stdout ); 111 DNAString ___test;112 ___test.run_test(-1);113 return 0;114 }115 // END CUT HERE
View Code

 

转载于:https://www.cnblogs.com/plumrain/p/srm_396.html

你可能感兴趣的文章
[转]Linux(centOS6.5)下SVN的安装、配置及开机启动
查看>>
putchar()
查看>>
050:navie时间和aware时间详解
查看>>
itertools
查看>>
centos7修改密码
查看>>
nodejs将PDF文件转换成txt文本,并利用python处理转换后的文本文件
查看>>
python笔记 第十一天 面向对象
查看>>
系统升级shell
查看>>
具体数学第二版第三章习题(3)
查看>>
JAVA版-微信高清语音.speex转.wav格式
查看>>
第8周编程总结
查看>>
cocos2d-x中本地推送消息
查看>>
转:架构师之路16年精选50篇
查看>>
滑动窗口
查看>>
蓝桥杯 马虎的算式(全排列)
查看>>
Oracle修改表字段类型(number-->varchar2(len)),亲测可用
查看>>
编译错误(WDK).warning treated as error - no ‘object’ file generated
查看>>
数据库表中批量替换某个字段的方法
查看>>
典型用户和场景
查看>>
碎点小结
查看>>