---恢复内容开始---
题目链接:http://acm.hnu.cn/online/?action=problem&type=list&courseid=283
A:模拟3n+1问题
解题思路:数比较小,直接模拟爆
解题代码:
1 #include2 #include 3 #include
B:给你两个文件名,让你比较大小,这里数字和字母是分开比较的,有前导0而且还有大数,所以判断有点繁琐。
解题思路:模拟,暴力
解题代码:
1 #include2 #include 3 #include 4 char temp11[] = "###"; 5 char str[257] ; 6 char str1[257]; 7 int ok = 0 ; 8 void solve(int fuck) 9 { 10 int t = 0 ; 11 int t1 = 0 ; 12 int len = strlen(str); 13 int len1 = strlen(str1); 14 while(t < len && t1 < len1) 15 { 16 if(isalpha(str[t]) && isalpha(str1[t1])) 17 { 18 if(str[t] == str1[t1]) 19 { 20 t ++ ; 21 t1 ++ ; 22 continue; 23 }else if(isupper(str[t]) && islower(str1[t1])) 24 { 25 if(str[t] - 'A' < str1[t1] -'a') 26 { 27 puts("<"); 28 return; 29 } 30 else if(str[t] - 'A' > str1[t1] -'a') 31 { 32 puts(">"); 33 return; 34 }else if(fuck) 35 { 36 puts(">"); 37 return; 38 } 39 t ++ ; 40 t1 ++ ; 41 }else if(isupper(str1[t1]) && islower(str[t])) 42 { 43 if(str1[t1] - 'A' < str[t] -'a') 44 { 45 puts(">"); 46 return; 47 }else if(str1[t1] - 'A' > str[t] -'a') 48 { 49 puts("<"); 50 return; 51 }else if(fuck) 52 { 53 puts("<"); 54 return; 55 } 56 t ++ ; 57 t1 ++; 58 }else{ 59 if(str1[t1] - 'a' > str[t] - 'a') 60 { 61 puts("<"); 62 return; 63 }else{ 64 puts(">"); 65 return; 66 } 67 } 68 }else if(isdigit(str[t]) && !isdigit(str1[t1])) 69 { 70 puts("<"); 71 return; 72 }else if(isdigit(str1[t1]) && !isdigit(str[t])){ 73 puts(">"); 74 return; 75 }else{ 76 char temp[257]; 77 char temp1[257]; 78 memset(temp,0,sizeof(temp)); 79 memset(temp1,0,sizeof(temp)); 80 int p = -1; 81 int flag ; 82 if(fuck) 83 flag = 1; 84 else flag = 0 ; 85 while(isdigit(str[t])) 86 { 87 if(flag == 0 ) 88 { 89 if(str[t] != '0') 90 { 91 flag = 1; 92 p ++ ; 93 temp[p] = str[t]; 94 } 95 }else{ 96 p ++ ; 97 temp[p] = str[t]; 98 } 99 t ++ ;100 }101 p = -1;102 if(fuck)103 flag = 1; 104 else flag = 0 ;105 while(isdigit(str1[t1])) 106 {107 if(flag == 0 )108 {109 if(str1[t1] != '0')110 {111 flag = 1; 112 p ++ ; 113 temp1[p] = str1[t1]; 114 }115 }else{116 p ++ ;117 temp1[p] = str1[t1]; 118 }119 t1 ++ ;120 }121 if(!fuck)122 {123 int len = strlen(temp);124 int len1 = strlen(temp1);125 if(len1 > len)126 {127 puts("<");128 return ;129 }else if(len > len1){130 puts(">");131 return ;132 }else{133 int k = strcmp(temp,temp1);134 if(k < 0)135 {136 puts("<");137 return; 138 }else if(k > 0 ){139 puts(">");140 return;141 }142 }143 }else{144 int k = strcmp(temp,temp1);145 if(k < 0)146 {147 puts("<");148 return; 149 }else if(k > 0 ){150 puts(">");151 return;152 }153 }154 }155 }156 if(t == len && t1 != len1)157 puts("<");158 else if(t1 == len1 && t != len)159 puts(">");160 else{161 ok = 1; 162 }163 }164 int main(){165 while(scanf("%s",str) != EOF)166 {167 if(strcmp(str,temp11) == 0 )168 break;169 scanf("%s",str1);170 if(strcmp(str,str1) == 0 )171 puts("=");172 else {173 ok = 0 ; 174 solve(0);175 if(ok)176 solve(1);177 }178 }179 return 0;180 }
C:题意:给你一串只含有 A U G C 字符组成的字符串,A U 能够连线 ,G,C能够连线,相邻不能连线,且线不能交叉,问你最多能连多少根线,
解题思路:显然这个题目是DP,dp[i][j] =max( dp[i][s] + dp[s-1][j] ,dp[i][j] ,如果ij能连线,还要加上 dp[i-1][j-1] + 1) ,比赛时因为max函数消耗太大而超时
解题代码:
1 #include2 #include 3 #include
E:一个长度为 2×n 的字符串,每次有这样的变换规律,i <= n i = i *2 ; i >= n; i = (i-n)*2 +1
解题思路:可知有个2×n的循环节
解题代码:
1 // File Name: d.cpp 2 // Author: darkdream 3 // Created Time: 2014年09月12日 星期五 09时33分05秒 4 5 #include6 #include 7 #include