# 7.6补题

2020/7/7 3:31:49 人评论 次浏览 分类：学习教程

CodeForces - 1272B

``````#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#define INF 0x3f3f3f3f
#define m 2008
using namespace std;
char s[100010];
int main(){
int q;
cin>>q;
while(q--)
{
cin>>s;
int n=strlen(s);
int l=0,r=0,d=0,u=0;
for(int i=0;i<n;i++)
{
if(s[i]=='U') u++;
if(s[i]=='D') d++;
if(s[i]=='L') l++;
if(s[i]=='R') r++;
}
int x=min(l,r),y=min(u,d);
if(x==0&&y==0) cout<<'0'<<endl;
else if(x==0&&y) cout<<'2'<<endl<<"UD"<<endl;
else if(x&&y==0) cout<<'2'<<endl<<"LR"<<endl;
else
{
cout<<2*(x+y)<<endl;
for(int i=1;i<=y;i++) cout<<'U';
for(int i=1;i<=x;i++) cout<<'R';
for(int i=1;i<=y;i++) cout<<'D';
for(int i=1;i<=x;i++) cout<<'L';
cout<<endl;
}
}
return 0;
}
``````

CodeForces - 1272C

``````#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#define INF 0x3f3f3f3f
#define m 2008
using namespace std;
char x;
int a[27]={0};
string s;
int main(){
long long n,k,lent=0;
long long ans=0;
cin>>n>>k;
cin>>s;
for(int i=1;i<=k;i++)
{
cin>>x;
a[x-'a'+1]=1;
}
for(int i=0;i<n;i++)
{
if(a[s[i]-'a'+1]) lent++;
else
{
ans+=(lent+1)*lent/2;
lent=0;
}
}
ans+=(lent+1)*lent/2;
cout<<ans<<endl;
return 0;
}``````

CodeForces - 1272D

``````#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#define INF 0x3f3f3f3f
#define m 2008
using namespace std;
int l[200010],r[200010],a[200010];
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
l[1]=1;
for(int i=2;i<n;i++)
{
if(a[i]>a[i-1]) l[i]=l[i-1]+1;
else
l[i]=1;
}
r[n]=1;
for(int i=n-1;i>1;i--)
{
if(a[i+1]>a[i]) r[i]=r[i+1]+1;
else
r[i]=1;
}
int maxn=1;
if(a[1]<a[2]) maxn=l[1]+r[2];
for(int i=3;i<=n;i++)
{
if(a[i]>a[i-1]) maxn=max(maxn,l[i-1]+r[i]);
if(a[i]>a[i-2]) maxn=max(maxn,l[i-2]+r[i]);
}
cout<<maxn<<endl;
return 0;
}``````

CodeForces - 1272E *

CodeForces - 1272F *

dp[i][j][k]表示匹配到的s的第I个,t的第j个,s的第I个

暂无相关的资讯...

-->