开始填坑_(:з」∠)_
628A - Tennis Tournament 20171124
小学数学题,\((x,y)=((n-1)\cdot(2b+1),np)\)
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,b,p,x,y;
int main()
{
scanf("%d%d%d",&n,&b,&p);
x=(n-)*(*b+),y=n*p;
printf("%d %d\n",x,y);
return ;
}
628B - New Skateboard 20171124
由于能根据末尾的两个数字判断出是否为4的倍数,直接每相邻两位判断一下就好了
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
string s;
LL ans;
bool check(int k){return k%==;}
int main()
{
cin>>s;
ans=check(s[]-'');
for(LL i=;i<s.size();i++)
ans+=check(s[i]-''),ans+=i*check(s[i-]*+s[i]);
printf("%I64d\n",ans);
return ;
}
628C - New Skateboard 20171124
让每一位修改产生的距离尽可能大即可
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
string s;
int n,k,f[];
int main()
{
scanf("%d%d",&n,&k);
cin>>s;
for(int i=;i<=n;i++)
f[i]=max(s[i-]-'a','z'-s[i-])+f[i-];
if(f[n]<k)return printf("-1\n"),;
for(int i=;i<n;i++)
{
if(k>=f[i+]-f[i])
s[i]=(s[i]-'a'>'z'-s[i])?'a':'z';
else s[i]=(s[i]-k>='a')?s[i]-k:s[i]+k;
k-=f[i+]-f[i];if(k<=)break;
}
cout<<s<<endl;return ;
}
628D - Magic Numbers 20190301
比较恶心的DP,首先将区间\((l,r)\)的询问转化为两次对区间\((1,n)\)的询问
令\(f[i][j][k]\)表示当前进行到第\(i\)位,除以\(m\)的余数为\(j\)时,与\(n\)的大小关系为\(k\)的方案数
循环时\(i\)从\(1\)到\(n\),通过枚举第\(i\)位的数字来推出\(j\)进行转移
接下去就是各种细节处理了
#include<bits/stdc++.h>
using namespace std;
#define N 2005
#define LL long long
#define MOD 1000000007
LL m,d,f[N][N][],ans;
char s[N];
LL rua()
{
LL n=strlen(s+);
memset(f,,sizeof(f));
for(LL j=;j<=;j++)if(j!=d)
{
if(j<s[]-'')f[][j%m][]++;
if(j==s[]-'')f[][j%m][]++;
if(j>s[]-'')f[][j%m][]++;
}
for(LL i=;i<n;i++)
for(LL j=;j<m;j++)
for(LL k=;k<;k++)if(f[i][j][k])
{
//cout<<i<<" "<<j<<" "<<k<<" "<<f[i][j][k]<<endl;
if(i&)
{
if(k==)(f[i+][(j*10ll+d)%m][k]+=f[i][j][k])%=MOD;
if(k==)
{
if(d<s[i+]-'')(f[i+][(j*10ll+d)%m][]+=f[i][j][k])%=MOD;
else if(d==s[i+]-'')(f[i+][(j*10ll+d)%m][]+=f[i][j][k])%=MOD;
else if(d>s[i+]-'')(f[i+][(j*10ll+d)%m][]+=f[i][j][k])%=MOD;
}
if(k==)(f[i+][(j*10ll+d)%m][k]+=f[i][j][k])%=MOD;
continue;
}
for(LL l=;l<=;l++)if(l!=d)
{
if(k==)(f[i+][(j*10ll+l)%m][k]+=f[i][j][k])%=MOD;
if(k==)
{
if(l<s[i+]-'')(f[i+][(j*10ll+l)%m][]+=f[i][j][k])%=MOD;
else if(l==s[i+]-'')(f[i+][(j*10ll+l)%m][]+=f[i][j][k])%=MOD;
else if(l>s[i+]-'')(f[i+][(j*10ll+l)%m][]+=f[i][j][k])%=MOD;
}
if(k==)(f[i+][(j*10ll+l)%m][k]+=f[i][j][k])%=MOD;
}
}
LL res=;
//for(LL j=0;j<m;j++)for(LL k=0;k<2;k++)if(f[n][j][k])cout<<n<<" "<<j<<" "<<k<<" "<<f[n][j][k]<<endl;
for(LL i=;i<n;i++)
for(LL k=;k<;k++)
(res+=f[i][][k])%=MOD;
(res+=f[n][][]+f[n][][])%=MOD;
return res;
}
bool check()
{
LL n=strlen(s+);
for(LL i=;i<=n;i++)
{
if((i&) && s[i]==d+'')
return false;
if(i%== && s[i]!=d+'')
return false;
}
LL r=;
for(LL i=;i<=n;i++)
r=(r*+s[i]-'')%m;
return r==;
}
int main()
{
scanf("%I64d%I64d",&m,&d);
scanf("%s",s+);
ans=MOD-rua()+check();
//cout<<rua()<<endl;
scanf("%s",s+);
ans+=rua();
//cout<<rua()<<endl;
return printf("%I64d\n",ans%MOD),;
}
628E - Zbazi in Zeydabad 20190305
这题只能说。。。bitset大法好,莽就完事了
#include<bits/stdc++.h>
using namespace std;
#define N 3005
#define LL long long
LL n,m,ans;
bitset<N>a[N],b[N],c[N];
int get()
{
char ch=getchar();
while(ch!='.' && ch!='z')ch=getchar();
return ch=='z';
}
int main()
{
scanf("%I64d%I64d",&n,&m);
for(LL i=;i<n;i++)
for(LL j=;j<m;j++)
a[i][m-j-]=get(),b[i].set(),c[i].set();
for(LL i=;i<min(m,n);i++)
{
for(LL j=;j<n;j++)b[j]&=a[j]>>i;
for(LL j=;j<n-i;j++)c[j]&=a[j+i]>>i,ans+=(b[j]&b[j+i]&c[j]).count();
}
return printf("%I64d\n",ans),;
}
628F - Bear and Fair Set 20190306
标解是网络流,但是有种瞎搞的方法不知道为什么能过_(:з」∠)_
考虑\(\{0,1,2,3,4\}\)的所有子集\(A\),对每个区间,计算出满足\(i\%5\epsilon A\)的\(i\)的个数,并与该区间可取数字的个数取\(min\),加起来后若个数小于\(\frac{|A|\cdot n}{5}\),则一定无解
若考虑完所有子集后依旧没有出现不合法的情况,则一定有解(本弱不会证,求大佬证明)
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
int nn,n,b,q;
vector<pair<int,int> >d;
int main()
{
d.push_back(mp(,));
scanf("%d%d%d",&n,&b,&q),nn=n;
d.push_back(mp(b,n));
for(int i=;i<=q;i++)scanf("%d%d",&b,&n),d.push_back(mp(b,n));
sort(d.begin(),d.end());
for(int i=;i<=q;i++)
if(d[i].second>d[i+].second || d[i+].second-d[i].second>d[i+].first-d[i].first)
return printf("unfair\n"),;
for(int k=;k<;k++)
{
int res=;
for(int i=;i<=q+;i++)
{
int cnt=;
for(int j=d[i-].first+;j<=d[i].first;j++)
cnt+=bool((<<(j%))&k);
res+=min(cnt,d[i].second-d[i-].second);
}
if(res<nn/*__builtin_popcount(k))return printf("unfair\n"),;
}
printf("fair\n");
return ;
}