A

记得以前做过 当时好像没做对 就是找个子串 满足括号的匹配 []最多的

开两个栈模拟 标记下就行

  1. #include <iostream>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<cstdio>
  5. #include<stdlib.h>
  6. #include<cmath>
  7. #include<vector>
  8. #include<queue>
  9. #include<stack>
  10. using namespace std;
  11. #define N 100010
  12. char s[N];
  13. char st[N];
  14. int sn[N][];
  15. int main()
  16. {
  17. int i,k,top=;
  18. cin>>s;
  19. k = strlen(s);
  20. sn[][] = -;sn[][] = -;
  21. for(i = ;i < k ;i++)
  22. {
  23. if(s[i]=='('||s[i]=='[')
  24. {
  25. st[++top] = s[i];
  26. sn[top][] = i;
  27. sn[top][] = ;
  28. sn[top][] = i;
  29. }
  30. else
  31. {
  32. if(s[i]==')')
  33. {
  34. if(top&&st[top]=='(')
  35. {
  36. top--;
  37. sn[top][] += sn[top+][];
  38. sn[top][] = i;
  39. }
  40. else
  41. {
  42. st[++top] = s[i];
  43. sn[top][] = i;
  44. sn[top][] = ;
  45. sn[top][] = i;
  46. }
  47. }
  48. else
  49. {
  50. if(top&&st[top]=='[')
  51. {
  52. top--;
  53. sn[top][] += sn[top+][]+;
  54. sn[top][] = i;
  55. }
  56. else
  57. {
  58. st[++top] = s[i];
  59. sn[top][] = i;
  60. sn[top][] = ;
  61. sn[top][] = i;
  62. }
  63. }
  64. }
  65. }
  66. int maxz=,x=;
  67. for(i = ; i <= top ; i++)
  68. {
  69. if(maxz<sn[i][])
  70. {
  71. maxz = sn[i][];
  72. x = i;
  73. }
  74. }
  75. cout<<maxz<<endl;
  76. for(i = sn[x][]+ ; i <= sn[x][] ; i++)
  77. cout<<s[i];
  78. puts("");
  79. return ;
  80. }

B

这题。。描述的很抽象。 按我的话来说 就是对于每一个s[i]总能找到一个子串包含它 而且与t串相等 t串还必须包含了s串的所有字母

做法:开个标记数组 标记每个字母向前以及向后最大的匹配位置 是否大于等于t串的长度

  1. #include <iostream>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<cstdio>
  5. #include<stdlib.h>
  6. #include<cmath>
  7. #include<vector>
  8. #include<queue>
  9. #include<stack>
  10. using namespace std;
  11. #define N 200010
  12. char s[N],t[N];
  13. int o[N],f[],w[N];
  14. int main()
  15. {
  16. int i,j,k,tk;
  17. while(cin>>s)
  18. {
  19. memset(o,,sizeof(o));
  20. memset(w,,sizeof(w));
  21. memset(f,,sizeof(f));
  22. k = strlen(s);
  23. cin>>t;
  24. tk = strlen(t);
  25. for(i = tk- ; i >= ; i--)
  26. {
  27. f[t[i]-'a'] = ;
  28. }
  29. for(i = k- ; i >= ; i--)
  30. {
  31. if(!f[s[i]-'a']) break;
  32. }
  33. if(i!=-||s[]!=t[])
  34. {
  35. puts("No");
  36. continue;
  37. }
  38. j = ;
  39. for(i = ; i < k ;i++)
  40. {
  41. if(s[i]==t[j])
  42. {
  43. j++;
  44. o[i] = j;
  45. f[s[i]-'a'] = j;
  46. }
  47. else
  48. {
  49. o[i] = f[s[i]-'a'];
  50. }
  51. }
  52. memset(f,,sizeof(f));
  53. j = tk-;
  54. for(i = k- ; i >= ;i--)
  55. {
  56. if(s[i]==t[j])
  57. {
  58. j--;
  59. w[i] = tk--j;
  60. f[s[i]-'a'] = tk--j;
  61. }
  62. else
  63. {
  64. w[i] = f[s[i]-'a'];
  65. }
  66. }
  67. for(i = ; i < k ;i++)
  68. {
  69. if(o[i]+w[i]<=tk) break;
  70. //cout<<o[i]<<" "<<w[i]<<endl;
  71. }
  72. if(i==k)
  73. puts("Yes");
  74. else puts("No");
  75. }
  76. return ;
  77. }

C 数论题

无奈数论太差 研究题解研究了好久。。可以推公式 我把具体的推法写一下 具体公式是对于第i个数来说 k次转换的结果 是 c(k+j-1,j)个a[j]之和 (j<=i) 就是当前的数 是由多个个a[j]组成的

比如 a[i]都为1  n为5 吧  初始为 1 1 1 1 1

就可以推了 k=1时  第一个数  1     =1           k = 2  第一个数  1     =1                                 ===》 1

         第二个数   1 1 (代表1个a[1] 1个a[j]) =2                 第二个数   2 1          (代表2个a[1] 1个a[j]) =3      ===》  3 1

         第三个数   1 1 1          = 3      +(2,1)  ===>            第三个数   3 2 1          = 6                                ===》  6 3 1

         第四个数 1 1 1 1        = 4      +(3,2,1) ====>        第四个数 4 3 2 1        = 10                                  ====》 10 6 3 1

         第五个数   1 1 1 1 1      =5      +(4,3,2,1)====>      第五个数   5 4 3 2 1     = 15                                =====》  15 10 6 3 1

差不多基本可以看下了 题解说可以看出规律为。。。 说实话我没看出来。。。  不过我验证了它的规律。。。 对于k此操作 对应的用去a[j]的个数 为o[j] = c(k+j-1,j);

注意这里不要用反  例如上面最后一组 是15个a[0] 10个a[1]..1个a[4]

另外一些数论的知识 因为涉及到组合数 又涉及到取余 所以涉及到了逆元  对于除法的逆元  a/b = ab^-1%mod   b^-1为其逆元

逆元又涉及到一递推公式  i的逆元 nv[i]=(-MOD/i*nv[MOD%i]);    验证:两边同乘i nv[i]*i = (-mod/i*nv[mod%i])*i;     逆元性质 a*nv[a]%MOD=1 1 = (-mod/i)*i*1/(mod%i)

so i*(-MOD/i) == (MOD%i)%MOD

-(MOD-MOD%i) == (MOD%i)%MOD  这个式子显然成立  证完

  1. #include <iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<stdlib.h>
  6. #include<vector>
  7. #include<cmath>
  8. #include<queue>
  9. #include<set>
  10. using namespace std;
  11. #define N 2010
  12. const double eps = 1e-;
  13. const double pi = acos(-1.0);
  14. const double inf = ~0u>>;
  15. #define LL long long
  16. #define mod 1000000007
  17. LL a[N],v[N],o[N];
  18. LL cn(int n,int m)
  19. {
  20. int i;
  21. LL s = ;
  22. for(i = ; i <= m ;i++)
  23. {
  24. s = ((s*v[i])%mod*(n-i+))%mod;//除法取余 乘其逆元
  25. }
  26. return s;
  27. }
  28. int main()
  29. {
  30. int i,j,n,k;
  31. cin>>n>>k;
  32. for(i = ; i < n ; i++)
  33. cin>>a[i];
  34. if(k==)
  35. {
  36. for(i = ; i< n ;i++)
  37. cout<<a[i]<<" ";
  38. puts("");
  39. return ;
  40. }
  41. v[] = v[] = ;
  42. for(i = ; i < n ; i++)
  43. v[i] = ((-mod/i*v[mod%i])%mod+mod)%mod;
  44. for(i = ; i < n ;i++)
  45. {
  46. o[i] = cn(i+k-,i);
  47. }
  48. for(i = ; i < n; i++)
  49. {
  50. LL ans=;
  51. for(j = ; j <= i ; j++)
  52. ans=(ans+a[j]*o[i-j])%mod;
  53. cout<<ans<<" ";
  54. }
  55. puts("");
  56. return ;
  57. }

Codeforces Round #138 (Div. 1)的更多相关文章

  1. Codeforces Round #138 (Div. 2)

    A. Parallelepiped 枚举其中一边,计算其他两条边. B. Array 模拟. C. Bracket Sequence 栈. D. Two Strings \(pre[i]\)表示第i个 ...

  2. Codeforces Round #138 (Div. 2) ACBDE

    A.Parallelepiped 题意:给一个六面体三面的面积,求12条边的长度和. 题解:因为都是整数,设边长分别为a,b,c,面积为xyz,那么可设x=a*b,y=b*c,z=c*a,简单解方程就 ...

  3. Codeforces Round #138 (Div. 2) A. Parallelepiped

    A. Parallelepiped time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  4. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  5. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  6. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  7. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  8. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  9. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

随机推荐

  1. AnkhSVN介绍

    AnkhSVN介绍 Posted on 2012-11-15 23:24 ArRan 阅读(3120) 评论(1) 编辑 收藏 AnkhSVN是一款在VS中管理Subversion的插件,您可以在VS ...

  2. 开发指南专题二:JEECG微云高速开发平台JEECG框架初探

    开发指南专题二:JEECG微云高速开发平台JEECG框架初探 2.JEECG框架初探 2.1演示系统 打开浏览器输入JEECG演示环境界址:http://demo.jeecg.org:8090/能够看 ...

  3. Android不刷机下的app2sd方法(dex cache占空间解决篇)

    抱着5年的HTC G7这个古董,一直没有想法去换换. 近期微信.支付宝什么的apk应用都開始走程序巨型化,一次性就来个50MB的空间占用,让还是Android 2.2的手机怎样吃的消? 看看100多M ...

  4. api多版本方案(URL)

    api多版本方案(URL) 1.利用url https://www.taofen8.com/api/v2/getXXX 2.利用自定义请求头 api-version https://www.taofe ...

  5. 2016/3/10 PHP (超文本预处理器) 是什么?

    PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言.语法吸收了C语言.Java和Perl的特点,利于学习,使用广泛,主要适用于W ...

  6. beyond compare 比较文本 standard alignment VS unaligned

    在Rules里面 Standard Alignment 这种方式会比较找出相同的部分,可能会跨行找相同的 Unaligned 这种比较直接每一行之间相互比较,不跨行找相同的

  7. inexact rename detection was skipped due to too many files

    https://stackoverflow.com/a/28064699 error: add_cacheinfo failed to refresh for path 'LISA.Kentico.U ...

  8. IE、W3C两种CSS盒子模型

    利用CSS来布局页面布局DIV有点逻辑性!重点理解盒子模型,标准流和非标准流的区别,还有定位原理!把这3个攻破了,就非常简单了!多实践多参考!最后就是兼容问题了,在实践中自然就有经验了!这些兼容技巧都 ...

  9. 【monkey】

    在Android文件系统中的存放路径是:/system/framework/monkey.jarMonkey.jar 程序是由一个名为“monkey”的Shell脚本来启动执行,shell脚本在And ...

  10. RDD的基本命令

    1 创建RDD intRDD=sc.parallelize([3,1,2,5,6]) intRDD.collect()[4, 2, 3, 6, 7] 2 单RDD转换 (1) MAP def addo ...