【CQ18高一暑假前挑战赛2】标程
【昨晚打校赛,5个小时打完很累了,所以搞忘出题了。。。对不起学弟们,不过出的题都亲自写过一遍,可以保证题目和代码长度都不长,题目难度不大】
【A:bush博弈】
#include<bits/stdc++.h>
using namespace std;
int main()
{
int T,N,K;
scanf("%d",&T);
while(T--){
scanf("%d%d",&N,&K);
if(N%(K+)==) puts("B");
else puts("A");
}
return ;
}
【B:DP求最长公共子序列,可以反推前缀】
#include<bits/stdc++.h>
using namespace std;
const int maxn=;
char a[maxn],b[maxn],ans[maxn];
int dp[maxn][maxn];
int main()
{
int L1,L2,i,j,k;
scanf("%s%s",a+,b+);
L1=strlen(a+); L2=strlen(b+);
for(i=;i<=L1;i++)
for(j=;j<=L2;j++){
dp[i][j]=max(dp[i-][j],dp[i][j-]);
if(a[i]==b[j]) dp[i][j]=max(dp[i][j],dp[i-][j-]+);
}
i=L1;j=L2;k=;
while(i>=&&j>=){
if(a[i]==b[j]) ans[++k]=a[i],i--,j--;
else if(dp[i-][j]>=dp[i][j-]) i--;
else j--;
}
for(i=k;i>=;i--) cout<<ans[i];
return ;
}
【C:nlogn的算法求最长递增子序列】
#include<bits/stdc++.h>
using namespace std;
const int maxn=;
int a[maxn];
int main()
{
int N,x,i,L=,pos=;
scanf("%d",&N);
for(i=;i<=N;i++){
scanf("%d",&x);
pos=upper_bound(a+,a+L+,x)-a;
a[pos]=x;
L=max(L,pos);
}
cout<<L<<endl;
return ;
}
【D:简单处理矩阵:求最大的区间全是1】:问题转化为枚举上下边界,然后连续的一块算。
#include<bits/stdc++.h>
using namespace std;
const int maxn=;
int a[maxn][maxn],sum[maxn][maxn];
int main()
{
int N,M,i,j,k,ans=;
scanf("%d%d",&N,&M);
for(i=;i<=N;i++)
for(j=;j<=M;j++){
scanf("%d",&a[i][j]);
sum[i][j]=sum[i-][j]+a[i][j];
}
for(i=;i<=N;i++)
for(j=i;j<=N;j++){
int L=;
for(k=;k<=M;k++)
if(sum[j][k]-sum[i-][k]==j-i+){ L++;ans=max(ans,(j-i+)*L);}
else L=;
}
printf("%d\n",ans);
return ;
}
【E:区间DP求最长回文,更优的算法有manecher等】
#include<bits/stdc++.h>
using namespace std;
const int maxn=;
char c[maxn];
int dp[maxn][maxn];
int main()
{
int L,i,j,ans=;
scanf("%s",c+);
L=strlen(c+);
for(i=L;i>=;i--){
for(j=i;j<=L;j++){
if(j-i+==) dp[i][j]=;
else if(j-i+==) dp[i][j]=(c[i]==c[j]?:);
else if(dp[i+][j-]!=&&c[i]==c[j]) dp[i][j]=dp[i+][j-]+;
ans=max(ans,dp[i][j]);
}
}
printf("%d\n",ans);
return ;
}
【CQ18高一暑假前挑战赛2】标程的更多相关文章
- 【CQ18高一暑假前挑战赛5】标程
[A:暴力] #include<bits/stdc++.h> using namespace std; ; int a[maxn],vis[maxn],N,M; int main() { ...
- 【CQ18高一暑假前挑战赛4】标程
[二分或者STL] 二分: #include<bits/stdc++.h> using namespace std; ; int a[maxn]; int main() { ,pos; s ...
- 【CQ18高一暑假前挑战赛3.5】标程
[A:快速幂相关] #include<bits/stdc++.h> using namespace std; int qpow(int a,int x){ a%=;; while(x){ ...
- 【CQ18高一暑假前挑战赛3】标程
[A:LCM] #include<bits/stdc++.h> using namespace std; #define ll long long int main() { ll a,b, ...
- 【CQ18高一暑假前挑战赛1】标程
[A] #include<bits/stdc++.h> using namespace std; #define ll long long ll qpow(ll a,ll x,ll Mod ...
- [转]关于一些SPFA的标程
SPFA算法 求单源最短路的SPFA算法的全称是:Shortest Path Faster Algorithm. 最短路径快速算法-SPFA算法是西南交通大学段凡丁于1994年发表的. 适用范围:给定 ...
- [求助][SPOJ MARIOGAM]-高斯消元(内含标程,数据等)
小蒟蒻开始做概率的题之后,遇到了这道题,然而,他发现自己的程序调试了无数次也无法通过,系统总是返回令人伤心的WA, 于是,他决定把这一天半的时间收集到的资料放在网上, 寻求大家的帮助, 也可以节省后来 ...
- hdu6435 Problem J. CSGO标程讲解以及改正标程的一个错误(本来第一个样例过不了2333) 以及 poj2926 五维曼哈顿距离模板
比赛的时候抄poj2926的模板,但改不来啊orz #include <iostream> #include <cstdio> #include <cstring> ...
- 暑假前的flag
暑假到了,为了简便新开了一个博客,供暑假刷体放一些题解,玩acm1年多了,cf还是蓝名,真是菜的一笔,明年就大三了,马上就要毕业了,然而还是啥也不会,兼职和智障没什么两样,当初大一吹的牛逼说要成为学校 ...
随机推荐
- linux下命令行的查找顺序
由下可知,linux通过$PATH的路径顺序,由左至由依次查找某个程序,如果有两个路径下都有这个程序,以先找到的为准 [rpc_server]$ which 23/usr/bin/which: no ...
- 托管和非托管转换新方法:Marshaling Library(zz) 【转】
托管和非托管转换新方法:Marshaling Library(zz) 托管和非托管转换新方法:Marshaling Library(zz) http://hi.baidu.com/superql/bl ...
- python numpy实现多次循环读取文件 等间隔过滤数据
numpy的np.fromfile会出现如下的问题,只能一次性读取文件的内容,不能追加读取,连续两次的np.fromfile读到的东西一样 如果数据文件太大(几个G或以上)不能一次性全读进去,需要追加 ...
- [LeedCode OJ]#85 Maximal Rectangle
[ 声明:版权全部,转载请标明出处.请勿用于商业用途. 联系信箱:libin493073668@sina.com] 题目链接:https://leetcode.com/problems/maxima ...
- 在.NET中怎样取得代码行数
文章目的 介绍在.NET中取得代码行数的方法 代码 [STAThread] static void Main(string[] args) { ReportError("Yay!" ...
- requests(爬虫常用)库的使用
Requests库的使用 基于urllib改写的库 示例: import requests response=requests.get('http://www.baidu.com')#get请求 pr ...
- 百科知识 华为手机P7如何更换电池
参考下面 教程 https://item.jd.com/3265516.html
- 文本聚类——Kmeans
上两篇文章分别用朴素贝叶斯算法和KNN算法对newgroup文本进行了分类測试.本文使用Kmeans算法对文本进行聚类. 1.文本预处理 文本预处理在前面两本文章中已经介绍,此处(略). 2.文本向量 ...
- binary-tree-maximum-path-sum——二叉树任意一条路径上的最大值
Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. ...
- Redux作用
作用:Redux是为了解决React中组件与组件之间数据传递的问题. React组件之间的传递有三种情况:1.父组件传递数据给子组件:由于redux是一个单向数据流的框架,所以它的数据就只能由父组件传 ...