Codeforces Round #138 (Div. 1)
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)的更多相关文章
- Codeforces Round #138 (Div. 2)
A. Parallelepiped 枚举其中一边,计算其他两条边. B. Array 模拟. C. Bracket Sequence 栈. D. Two Strings \(pre[i]\)表示第i个 ...
- Codeforces Round #138 (Div. 2) ACBDE
A.Parallelepiped 题意:给一个六面体三面的面积,求12条边的长度和. 题解:因为都是整数,设边长分别为a,b,c,面积为xyz,那么可设x=a*b,y=b*c,z=c*a,简单解方程就 ...
- Codeforces Round #138 (Div. 2) A. Parallelepiped
A. Parallelepiped time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- 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 ...
随机推荐
- AnkhSVN介绍
AnkhSVN介绍 Posted on 2012-11-15 23:24 ArRan 阅读(3120) 评论(1) 编辑 收藏 AnkhSVN是一款在VS中管理Subversion的插件,您可以在VS ...
- 开发指南专题二:JEECG微云高速开发平台JEECG框架初探
开发指南专题二:JEECG微云高速开发平台JEECG框架初探 2.JEECG框架初探 2.1演示系统 打开浏览器输入JEECG演示环境界址:http://demo.jeecg.org:8090/能够看 ...
- Android不刷机下的app2sd方法(dex cache占空间解决篇)
抱着5年的HTC G7这个古董,一直没有想法去换换. 近期微信.支付宝什么的apk应用都開始走程序巨型化,一次性就来个50MB的空间占用,让还是Android 2.2的手机怎样吃的消? 看看100多M ...
- api多版本方案(URL)
api多版本方案(URL) 1.利用url https://www.taofen8.com/api/v2/getXXX 2.利用自定义请求头 api-version https://www.taofe ...
- 2016/3/10 PHP (超文本预处理器) 是什么?
PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言.语法吸收了C语言.Java和Perl的特点,利于学习,使用广泛,主要适用于W ...
- beyond compare 比较文本 standard alignment VS unaligned
在Rules里面 Standard Alignment 这种方式会比较找出相同的部分,可能会跨行找相同的 Unaligned 这种比较直接每一行之间相互比较,不跨行找相同的
- 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 ...
- IE、W3C两种CSS盒子模型
利用CSS来布局页面布局DIV有点逻辑性!重点理解盒子模型,标准流和非标准流的区别,还有定位原理!把这3个攻破了,就非常简单了!多实践多参考!最后就是兼容问题了,在实践中自然就有经验了!这些兼容技巧都 ...
- 【monkey】
在Android文件系统中的存放路径是:/system/framework/monkey.jarMonkey.jar 程序是由一个名为“monkey”的Shell脚本来启动执行,shell脚本在And ...
- RDD的基本命令
1 创建RDD intRDD=sc.parallelize([3,1,2,5,6]) intRDD.collect()[4, 2, 3, 6, 7] 2 单RDD转换 (1) MAP def addo ...