A

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

开两个栈模拟 标记下就行

 #include <iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<stdlib.h>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define N 100010
char s[N];
char st[N];
int sn[N][];
int main()
{
int i,k,top=;
cin>>s;
k = strlen(s);
sn[][] = -;sn[][] = -;
for(i = ;i < k ;i++)
{
if(s[i]=='('||s[i]=='[')
{
st[++top] = s[i];
sn[top][] = i;
sn[top][] = ;
sn[top][] = i;
}
else
{
if(s[i]==')')
{
if(top&&st[top]=='(')
{
top--;
sn[top][] += sn[top+][];
sn[top][] = i;
}
else
{
st[++top] = s[i];
sn[top][] = i;
sn[top][] = ;
sn[top][] = i;
}
}
else
{
if(top&&st[top]=='[')
{
top--;
sn[top][] += sn[top+][]+;
sn[top][] = i;
}
else
{
st[++top] = s[i];
sn[top][] = i;
sn[top][] = ;
sn[top][] = i;
}
}
}
}
int maxz=,x=;
for(i = ; i <= top ; i++)
{
if(maxz<sn[i][])
{
maxz = sn[i][];
x = i;
}
}
cout<<maxz<<endl;
for(i = sn[x][]+ ; i <= sn[x][] ; i++)
cout<<s[i];
puts("");
return ;
}

B

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

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

 #include <iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<stdlib.h>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define N 200010
char s[N],t[N];
int o[N],f[],w[N];
int main()
{
int i,j,k,tk;
while(cin>>s)
{
memset(o,,sizeof(o));
memset(w,,sizeof(w));
memset(f,,sizeof(f));
k = strlen(s);
cin>>t;
tk = strlen(t);
for(i = tk- ; i >= ; i--)
{
f[t[i]-'a'] = ;
}
for(i = k- ; i >= ; i--)
{
if(!f[s[i]-'a']) break;
}
if(i!=-||s[]!=t[])
{
puts("No");
continue;
}
j = ;
for(i = ; i < k ;i++)
{
if(s[i]==t[j])
{
j++;
o[i] = j;
f[s[i]-'a'] = j;
}
else
{
o[i] = f[s[i]-'a'];
}
}
memset(f,,sizeof(f));
j = tk-;
for(i = k- ; i >= ;i--)
{
if(s[i]==t[j])
{
j--;
w[i] = tk--j;
f[s[i]-'a'] = tk--j;
}
else
{
w[i] = f[s[i]-'a'];
}
}
for(i = ; i < k ;i++)
{
if(o[i]+w[i]<=tk) break;
//cout<<o[i]<<" "<<w[i]<<endl;
}
if(i==k)
puts("Yes");
else puts("No");
}
return ;
}

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  这个式子显然成立  证完

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 2010
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
#define LL long long
#define mod 1000000007
LL a[N],v[N],o[N];
LL cn(int n,int m)
{
int i;
LL s = ;
for(i = ; i <= m ;i++)
{
s = ((s*v[i])%mod*(n-i+))%mod;//除法取余 乘其逆元
}
return s;
}
int main()
{
int i,j,n,k;
cin>>n>>k;
for(i = ; i < n ; i++)
cin>>a[i];
if(k==)
{
for(i = ; i< n ;i++)
cout<<a[i]<<" ";
puts("");
return ;
}
v[] = v[] = ;
for(i = ; i < n ; i++)
v[i] = ((-mod/i*v[mod%i])%mod+mod)%mod;
for(i = ; i < n ;i++)
{
o[i] = cn(i+k-,i);
}
for(i = ; i < n; i++)
{
LL ans=;
for(j = ; j <= i ; j++)
ans=(ans+a[j]*o[i-j])%mod;
cout<<ans<<" ";
}
puts("");
return ;
}

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. react 项目中 引入 bootstrap

    react-bootstrap是一个非常受欢迎的针对react封装过的bootstrap,它本身不包含css,所以也是需要使用bootstrap原生库. 在create-react-app建的项目目录 ...

  2. struts2的文件上传机制

    Struts2的上传(基本流程例如以下) 1.Struts2默认採用了apache commons-fileupload 2.Struts2支持三种类型的上传组件 3.须要引入commons-file ...

  3. 李洪强iOS开发之性能优化技巧

    李洪强iOS开发之性能优化技巧 通过静态 Analyze 工具,以及运行时 Profile 工具分析性能瓶颈,并进行性能优化.结合本人在开发中遇到的问题,可以从以下几个方面进行性能优化. 一.view ...

  4. MySQL运行计划不准确 -概述

    为毛 MySQL优化器的运行计划 好多时候都不准确,不是最优的呢(cpu+io)??? 因素太多了:: 存在information_schema的信息是定期刷新上去的,好多时候不是最真的,甚至相差好大 ...

  5. Visual Studio Code Unit Testing

    1.NUnit project.json { "version": "1.0.0-*", "testRunner": "nunit ...

  6. pip 安装速度慢解决办法

    https://blog.csdn.net/liujingclan/article/details/50176597 https://blog.csdn.net/rytyy/article/detai ...

  7. oracle的日期蛋

    一切都是扯鸡巴蛋. 在网上查oracle的日期函数用法,得到一大堆语法,林林总总,都是扯鸡巴蛋,没能解决我的问题. 其实,我想写这么一条语句:查找某个日期(不含时分秒)产生或有关的记录.咋写? SQL ...

  8. high-level operations on files and collections of files

    11.10. shutil — High-level file operations — Python 3.6.5 documentation https://docs.python.org/3/li ...

  9. os 2大功能

    支撑功能 中断管理 时钟管理 原语操作  primitive 资源管理功能 进程管理 存储器管理 设备管理

  10. hdu 5119 (类似于划分数的状态定义) (DP中的计数问题)

    题目描述:求n个数中异或值大于m的方案数有多少个? 设状态f[i][j]代表前i个数异或值为j的方案数有f[i][j]种,那么对于j来说要么选第i个数与前面的i-1个数中的某些数构成j,f[i-1][ ...