首页 > 代码库 > Codeforces Round #265 (Div. 2) 题解

Codeforces Round #265 (Div. 2) 题解

A:给你一个二进制数,问你加一以后改变多少位

解题思路:乱搞

解题代码:

 1 // File Name: a.cpp 2 // Author: darkdream 3 // Created Time: 2014年09月07日 星期日 23时27分31秒 4  5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #include<deque>10 #include<stack>11 #include<bitset>12 #include<algorithm>13 #include<functional>14 #include<numeric>15 #include<utility>16 #include<sstream>17 #include<iostream>18 #include<iomanip>19 #include<cstdio>20 #include<cmath>21 #include<cstdlib>22 #include<cstring>23 #include<ctime>24 #define LL long long25 26 using namespace std;27 int a[200];28 int main(){29   int n , m ;30   scanf("%d",&n);31   for(int i =1;i <= n;i ++)32   {33      scanf("%1d",&a[i]);34   }35   int ans = 0; 36   int temp = 1; 37   for( int i = 1;i <= n;i ++)38   {39      temp = (a[i] + temp)/2;40      if(temp == 0 || a[i] == 0)41         {42           ans = i ; 43           break;44         }45   }46   if(ans == 0 )47       ans = n ;48   printf("%d\n",ans);49 return 0;50 }
View Code

B:给你邮件列表,有些邮件已读,有些没读,给你三种操作

1.点开这个邮件

2.退出这封邮件

3.在这封邮件里面点开上一封和下一封邮件。

解题代码:

 1 // File Name: b.cpp 2 // Author: darkdream 3 // Created Time: 2014年09月07日 星期日 23时39分39秒 4  5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #include<deque>10 #include<stack>11 #include<bitset>12 #include<algorithm>13 #include<functional>14 #include<numeric>15 #include<utility>16 #include<sstream>17 #include<iostream>18 #include<iomanip>19 #include<cstdio>20 #include<cmath>21 #include<cstdlib>22 #include<cstring>23 #include<ctime>24 #define LL long long25 26 using namespace std;27 int a[1004];28 int main(){29   int n;30   scanf("%d",&n);31   scanf("%d",&a[1]);32   int sum = 0 ; 33   if(a[1] == 1 )34       sum = 1; 35   for(int i =2 ;i <= n;i++)36   {37     scanf("%d",&a[i]);38     if(a[i] == 0 && a[i-1] == 1)39     {40       sum ++;    41     }42     if(a[i] == 1)43     {44        sum ++ ;45     }46   }47   if(a[n] == 0 )48   {49     sum = max(sum-1,0) ; 50   }51   printf("%d\n",sum);52 return 0;53 }
View Code

C:给你一个不包含回文子串,问你最多使用前p个字母且长度等于这个字符串且字典序比这个序列大而且不包含回文子串的的字符串。

解题思路:枚举改变第几位就行

解题代码:

 1 // File Name: c.cpp 2 // Author: darkdream 3 // Created Time: 2014年09月07日 星期日 23时55分52秒 4  5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #include<deque>10 #include<stack>11 #include<bitset>12 #include<algorithm>13 #include<functional>14 #include<numeric>15 #include<utility>16 #include<sstream>17 #include<iostream>18 #include<iomanip>19 #include<cstdio>20 #include<cmath>21 #include<cstdlib>22 #include<cstring>23 #include<ctime>24 #define LL long long25 26 using namespace std;27 int a[1005];28 int b[1005];29 char str[1005];30 int main(){31    int n , p ;32    scanf("%d %d",&n,&p);33    scanf("%s",&str[1]); 34    memset(a,0,sizeof(a));35    memset(b,0,sizeof(b));36    for(int i = 1;i <= n;i ++)37    {38      a[i] =  str[i] - a + 1;39    }40    int ans = 0 ;41    //for(int i =1 ;i <= n;i++)42      //  printf("%d ",a[i]);43    for(int i = n;i >= 1 ;i --)44    {45      int j ;46      int s; 47      for(s = a[i] + 1 ; s <= p ;s ++)48      {49         if(s != a[i-1] &&( i-2 == -1 || (s != a[i-2]) ))50         {51            b[i] = s; 52            b[i-1] = a[i-1];53            break;54         }55      }56      if(s == p + 1)57          continue;58      //printf("\n%d %d\n",i,s);59      for( j = i+1;j<= n;j ++)60      {61         for( s = 1; s <= p;s ++) 62         {63           if(s != b[j-1] && s!= b[j-2]) 64           {65               b[j] = s;66               //printf("%d***\n",s);67               break;68           }69         }70         if(s == p + 1)71         {72           break;73         }74      }75      if(j == n+1)76      {77        ans = i;78        break;79      }80     }81    if(!ans)82    {83      printf("NO\n");84      return 0 ; 85    }86    for(int i = 1;i <= ans -1;i ++)87        printf("%c",a[i] + a -1 );88    for(int j = ans ;j <= n;j ++)89        printf("%c",b[j] + a -1);90 91 return 0;92 }
View Code

 

Codeforces Round #265 (Div. 2) 题解