Codeforces Round #191 (Div. 2)

好久没写过CF的博客了,最近忙着考试,各种不顺,没想到这次CF却是很顺利。

A题暴力,开始看错题了。。然后发现只需要转一次。。。B题也是暴力去构造的,C题一个组合问题,话说这次终于在比赛里把组合题给A了,这题不难,但也不是很水,当时就是觉得应该是这样,感觉题意也不是很清楚,按自己的理解过了样例,应该就没问题了,用到以前用过的等比数列求和取余的模版。D题也是构造问题,只要看出一个连通块,只要一个100塔其他都是200塔就行了。DIV2里,第一次做了4个题。。

rating涨了181。。如果我之前的rating 是蓝色,而不是绿色的话,这次就可以变紫了把。。。以后还有机会,慢慢来把。

A题

 1 #include <cstdio>

 2 #include <string>

 3 #include <algorithm>

 4 #include <cstring>

 5 #include <map>

 6 #include <vector>

 7 using namespace std;

 8 int p[1001],sum[1001];

 9 int main()

10 {

11     int n,i,ans,j;

12     scanf("%d",&n);

13     for(i = 1;i <= n;i ++)

14     {

15         scanf("%d",&p[i]);

16         sum[i] = sum[i-1] + p[i];

17     }

18     ans = 0;

19     for(i = 1;i <= n;i ++)

20     {

21         for(j = i;j <= n;j ++)

22         {

23             ans = max(ans,sum[i-1]+sum[n]-sum[j]+(j-i+1-(sum[j]-sum[i-1])));

24         }

25     }

26     printf("%d\n",ans);

27     return 0;

28 }

B题

 1 #include <cstdio>

 2 #include <string>

 3 #include <algorithm>

 4 #include <cstring>

 5 #include <map>

 6 #include <vector>

 7 #include <cstdlib>

 8 #include <time.h>

 9 using namespace std;

10 #define N 3000000

11 int o[N+10];

12 int main()

13 {

14     int n,j,num,i;

15     scanf("%d",&n);

16     for(i = 1,num = 2;i <= n;i ++)

17     {

18         while(o[num])

19         num ++;

20         if(i == 1)

21         printf("%d",num);

22         else

23         printf(" %d",num);

24         for(j = num;j <= N;j += num)

25         {

26             o[j] = 1;

27         }

28         num ++;

29     }

30     printf("\n");

31     return 0;

32 }

C题

 1 #include <cstdio>

 2 #include <string>

 3 #include <algorithm>

 4 #include <cstring>

 5 #include <map>

 6 #include <vector>

 7 #include <cstdlib>

 8 #include <time.h>

 9 using namespace std;

10 #define N 3000000

11 #define MOD 1000000007

12 #define LL __int64

13 char str[200001];

14 LL bin[200001];

15 LL fastmod(LL p,LL k)

16 {

17     LL sum = 1,tmp = p;

18     while (k)

19     {

20         if (k%2 == 1) sum = (sum*tmp)%MOD;

21         tmp = (tmp*tmp)%MOD;

22         k = k/2;

23     }

24     return sum;

25 }

26 LL getnum(LL p,LL k)

27 {

28     if (k <= 0) return 1;

29     if (k%2 == 0)

30         return ((getnum(p,k/2 - 1)%MOD)*((1 + fastmod(p,k/2 + 1))%MOD) + fastmod(p,k/2)%MOD)%MOD;

31     else

32         return ((getnum(p,(k + 1)/2 - 1)%MOD)*((1 + fastmod(p,(k + 1)/2))%MOD))%MOD;

33 }

34 int main()

35 {

36     int n,i;

37     LL ans = 0,temp,k;

38     scanf("%s%I64d",str,&k);

39     n = strlen(str);

40     bin[0] = 1;

41     for(i = 1;i <= n;i ++)

42     {

43         bin[i] = (bin[i-1]*2)%MOD;

44     }

45     temp = getnum(bin[n],k-1);

46     for(i = n-1;i >= 0;i --)

47     {

48         if(str[i] == '0'||str[i] == '5')

49         {

50             ans = (ans + bin[i]*temp)%MOD;

51         }

52     }

53     printf("%I64d\n",ans);

54     return 0;

55 }

D题

 1 #include <cstdio>

 2 #include <string>

 3 #include <algorithm>

 4 #include <cstring>

 5 #include <map>

 6 #include <vector>

 7 #include <cstdlib>

 8 #include <time.h>

 9 using namespace std;

10 char p[501][501];

11 int o[501][501];

12 int a[4] = {0,0,1,-1};

13 int b[4] = {1,-1,0,0};

14 int q1[5000001],q2[5000001],q3[5000001];

15 int z,n,m,num = 0;

16 void dfs(int x,int y)

17 {

18     int i,f = 0;

19     if(z)

20     {

21         z = 0;

22         f = 1;

23     }

24     else

25     {

26         q1[num] = 1;

27         q2[num] = x+1;

28         q3[num] = y+1;

29         num ++;

30         //printf("B %d %d\n",x+1,y+1);

31     }

32     for(i = 0; i < 4; i ++)

33     {

34         if(x+a[i] >= 0&&x+a[i] < n&&y+b[i] >= 0&&y+b[i] < m&&!o[x+a[i]][y+b[i]]&&p[x+a[i]][y+b[i]] == '.')

35         {

36             o[x+a[i]][y+b[i]] = 1;

37             dfs(x+a[i],y+b[i]);

38         }

39     }

40     if(f == 0)

41     {

42         q1[num] = 2;

43         q2[num] = x+1;

44         q3[num] = y+1;

45         num ++;

46         //printf("D %d %d\n",x+1,y+1);

47         q1[num] = 3;

48         q2[num] = x+1;

49         q3[num] = y+1;

50         num ++;

51         //printf("R %d %d\n",x+1,y+1);

52     }

53 }

54 int main()

55 {

56     int i,j;

57     scanf("%d%d",&n,&m);

58     for(i = 0; i < n; i ++)

59         scanf("%s",p[i]);

60     for(i = 0; i < n; i ++)

61     {

62         for(j = 0; j < m; j ++)

63         {

64             if(p[i][j] == '.'&&!o[i][j])

65             {

66                 o[i][j] = 1;

67                 q1[num] = 1;

68                 q2[num] = i+1;

69                 q3[num] = j+1;

70                 num ++;

71                 //printf("B %d %d\n",i+1,j+1);

72                 z = 1;

73                 dfs(i,j);

74             }

75         }

76     }

77     printf("%d\n",num);

78     for(i = 0; i < num; i ++)

79     {

80         if(q1[i] == 1)

81             printf("B");

82         else if(q1[i] == 2)

83             printf("D");

84         else

85             printf("R");

86         printf(" %d %d\n",q2[i],q3[i]);

87     }

88     return 0;

89 }

 

你可能感兴趣的:(codeforces)