- C. Cut the Deck
- D. Dislike the Raisins
- G. Grid of Letters
- I. Integer Multiplicative Persistence
链接:link.
思路:找出max(R的数量-B的数量),从此处开始便利,n/2-d1[ i ] (B的数量)>=max,i即为所求。
int t;
char s[1000010];
int d1[1000010],d2[1000010];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>t;
while(t--)
{
cin>>s;
int n=strlen(s);
int k1=0,k2=0;
int flag=0;
int maxn=-INF,maxf=-1;
for(int i=0;imaxn)maxf=i,maxn=k2-k1;
}
if(flag==0){cout<<"0n";continue;}
for(int i=maxf;i=maxn)
{
cout<
D. Dislike the Raisins
链接:link.
注意:只要(c+r)%s!=0&&c%s>=(c+r)%s,结果一就为(c/s)++;
int t;
int c,r,s;
int main()
{
ios::sync_with_stdio(0);
//cin.tie(0);cout.tie(0);
cin>>t;
while(t--)
{
cin>>c>>r>>s;
int x=(c+r)/s;
int y=(c+r)%s;
int s1=c/s,s2;
if(y!=0&&c%s>=y)s1++;
if(y!=0)x++;
if(x<=r)s2=0;
else s2=x-r;
cout<
G. Grid of Letters
链接:link.
思路:找到入度为0的点开始dfs,注意特判终止dfs。
int n,m;
char s[1010][1010];
typedef pairPII;
vectorv;
int dx[]={1,1,1,-1,-1,-1,0,0};
int dy[]={1,0,-1,1,0,-1,1,-1};
void dfs(int x,int y,int ss,int &maxn)
{
for(int i=0;i<8;i++)
{
int cx=x+dx[i];
int cy=y+dy[i];
if(cx>=0&&cx=0&&cy>n>>m;
for(int i=0;i>s[i];
//for(int i=0;i=0&&x=0&&ymaxn)dfs(x,y,ss,maxn);
}
cout<
I. Integer Multiplicative Persistence
链接:link.
int t,n;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>t;
while(t--)
{
cin>>n;
int k=0;
while(n>9)
{
k++;
int x=1;
while(n>0)
{
x=x*(n%10);
n=n/10;
}
n=x;
}
cout<



