今天的比赛是我们队第一次AK,取得了巨大的胜利O(∩_∩)O哈哈~,一直在水全国女生赛的题,不敢做dp,感觉心慌慌,先划划水再攻dp
https://cn.vjudge.net/contest/228631#problem/D
题意:
查找字符串中某个区间某个字符出现的次数,这里的字符串是把字符无限循环的,我用的sum[i][j]从0到i,j字符出现的次数,水,就是输入必须是scanf否则就超时。。
代码:
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
#define ll long long
int a[10005][30];
int main()
{
int t,i,j,n,q,aa,bb,ant,maxn,minn;
char cc[10];
string s;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&q);
cin>>s;
int m;
m=s.size()+1;
memset(a,0,sizeof(a));
for(i=1;i<m;i++)
{
memcpy(a[i],a[i-1],sizeof(a[i]));
a[i][s[i-1]-'a']++;
}
//cout<<"ok"<<endl;
for(i=0;i<q;i++)
{
scanf("%d%d%s",&aa,&bb,&cc);
//cin>>cc;
maxn=(aa+n-1)/n;
minn=(bb-1)/n;
ant=(minn-maxn+1)*a[n][cc[0]-'a'];
aa=aa%n;
bb=bb%n;
if(aa==0)
aa=n;
if(bb==0)bb=n;
ant+=a[bb][cc[0]-'a']-a[aa-1][cc[0]-'a'];
printf("%d\n",ant);
}
}
}
https://cn.vjudge.net/contest/228631#problem/C
题意:
在数组里找和除本身外,和取模最大的值
分析:
就是sort+二分
代码:
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
#define ll long long
int a[100005];
struct node
{
int num,id;
bool operator<(const node &aa)const
{
if(num!=aa.num)
return num<aa.num;
return id<aa.id;
}
}b[100005];
int mod;
int main()
{
int i,j,t,n,ant;
scanf("%d",&t);
mod=1000000007;
while(t--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
b[i].num=a[i]%mod;
b[i].id=i;
}
sort(b,b+n);
for(i=0;i<n;i++)
{
if(i!=0)printf(" ");
int ans;
ans=(mod-1-a[i]+mod)%mod;
int l,r,mid;
l=0;
r=n-1;
ant=n-1;
while(l<=r)
{
mid=(l+r)>>1;
if(b[mid].num>ans)
{
r=mid-1;
}
else
{
l=mid+1;
ant=mid;
}
}
//printf("%d %d \n",ant,ans);
if(b[ant].id==i)
{
if(ant==0)
ant=n-1;
else
ant--;
}
printf("%d",(a[i]+b[ant].num)%mod);
}
printf("\n");
}
}
https://cn.vjudge.net/contest/228631#problem/J
题意:
用该字符串打乱顺序可以构成的回文串有几种?
分析:
数学的排列组合
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include <sstream>
#define inf 8000000000000
#define ll long long
#define mod 1000000007
using namespace std;
ll go(int aa,int bb)
{
ll t;
int i,j;
t=1;
for(i=aa,j=0;j<bb;j++,i--)
{
t*=i;
}
for(i=1;i<=bb;i++)
t/=i;
return t;
}
int a[30];
int main()
{
int t,i,j,n,pos;
ll sum;
string s;
scanf("%d",&t);
while(t--)
{
sum=1;
scanf("%d",&n);
memset(a,0,sizeof(a));
cin>>s;
int m;
m=s.size();
for(i=0;i<m;i++)
{
a[s[i]-'a']++;
}
bool flag,ok;
flag=0;
ok=0;
for(i=0;i<26;i++)
{
if(a[i]%2&&!flag)
{
flag=1;
pos=i;
}
else
if(flag&&a[i]%2)
{
ok=1;
break;
}
}
if(ok)
printf("0\n");
else
{
if(flag)
{
n>>=1;
for(i=0;i<26;i++)
{
if(i!=pos)
{
sum*=go(n,a[i]>>1);
n=n-(a[i]>>1);
}
else
{
sum*=go(n,(a[i]-1)>>1);
n=n-((a[i]-1)>>1);
}
}
printf("%lld\n",sum);
}
else
{
n>>=1;
for(i=0;i<26;i++)
{
sum*=go(n,a[i]>>1);
n=n-(a[i]>>1);
}
printf("%lld\n",sum);
}
}
}
}
其他的不是我做的,看了下就是有几个dp还有找规律,最难的是E就是2个dfs+map,每个dfs是6^7