模拟钟表的时分秒针的走动,给出时间求出夹角。注意每组输出要有一个空格
以后要想好再写代码,这样一个水题做了50分钟,太弱了。。。
1 #include<cstdio> 2 #include<string> 3 #include<cstring> 4 #include<algorithm> 5 #include<iostream> 6 using namespace std; 7 8 string s; 9 int dp[200010][2]; 10 int save[200010]; 11 12 int main(){ 13 int T; 14 int cas = 0; 15 scanf("%d", &T); 16 while(T--){ 17 cin >> s; 18 memset(dp, 0, sizeof(dp)); 19 memset(save, 0, sizeof(save)); 20 for(int i = 0; i < s.length(); i++){ 21 scanf("%d", &save[i]); 22 } 23 if(s[0] == '1'){ 24 dp[0][1] += save[0]; 25 dp[0][0] = 0; 26 }else if(s[0] == '0'){ 27 dp[0][0] = dp[1][1] = 0; 28 }else{ 29 dp[0][1] += save[0]; 30 dp[0][0] = 0; 31 } 32 //printf("%d ", max(dp[0][1], dp[0][0])); 33 for(int i = 1; i < s.length(); i++){ 34 if(s[i] == '1'){ 35 if(s[i-1] == '0'){ 36 dp[i][1] = dp[i-1][0] + save[i]; 37 }else if(s[i-1] == '1'){ 38 dp[i][1] = dp[i-1][1]; 39 }else if(s[i-1] == '?'){ 40 dp[i][1] = max(dp[i-1][0] + save[i], dp[i-1][1]); 41 } 42 }else if(s[i] == '0'){ 43 if(s[i-1] == '0'){ 44 dp[i][0] = dp[i-1][0]; 45 }else if(s[i-1] == '1'){ 46 dp[i][0] = dp[i-1][1] + save[i]; 47 }else if(s[i-1] == '?'){ 48 dp[i][0] = max(dp[i-1][1] + save[i], dp[i-1][0]); 49 //printf("dp[%d][0] = %d ", dp[i][0]); 50 } 51 }else if(s[i] == '?'){ 52 if(s[i-1] == '0'){ 53 dp[i][1] = dp[i-1][0] + save[i]; 54 //printf("dp[%d][1] = %d ", i, dp[i][1]); 55 dp[i][0] = dp[i-1][0]; 56 //printf("dp[%d][0] = %d ", i, dp[i][0]); 57 }else if(s[i-1] == '1'){ 58 dp[i][0] = dp[i-1][1] + save[i]; 59 dp[i][1] = dp[i-1][1]; 60 }else if(s[i-1] == '?'){ 61 dp[i][0] = max(dp[i-1][1] + save[i], dp[i-1][0]); 62 dp[i][1] = max(dp[i-1][0] + save[i], dp[i-1][1]); 63 } 64 } 65 //printf("%d ", max(dp[i][1], dp[i][0])); 66 } 67 int n = s.length() - 1; 68 printf("Case #%d: %d ", ++cas, max(dp[n][1], dp[n][0])); 69 } 70 return 0; 71 }