九进制转十进制
#include<bits/stdc++.h>
using namespace std;
int main()
{
cout<<1478<<endl;
return 0;
}
顺子日期
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int months[]={0,31,28,31,30,31,30,
31,31,30,31,30,31};
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int year=2022,month=1,day=1;
int ans=0;
for(int i=1;i<=365;i++)
{
char ch[9]={0};
sprintf(ch,"%04d%02d%02d",year,month,day);
bool flag=false;
for(int j=0;j<6;j++)
{
if(ch[j+1]==ch[j]+1&&ch[j+2]==ch[j]+2)
{
flag=true;
break;
}
}
if(flag==true)
ans++;
day++;
if(day>months[month])
{
day=1;
month++;
}
}
cout<<ans;
}
刷题统计
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
LL n;
LL a,b;
cin>>a>>b>>n;
LL w =5*a+2*b;
LL week_count=n/w;
LL yu_n = n%w;
LL day_c=0;
if(yu_n==0)
{
cout<<week_count*7<<endl;
return 0;
}
for(int i=1;i<=7;i++)
{
if(i==6||i==7)
yu_n-=b;
else
yu_n-=a;
day_c++;
if(yu_n<=0)
break;
}
cout<<day_c+week_count*7<<endl;
return 0;
}
修剪灌木
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
if(i<=n/2)
{
cout<<2*(n-i)<<endl;
}
else
{
cout<<2*(i-1)<<endl;
}
}
return 0;
}
X进制减法
#include<bits/stdc++.h>
using namespace std;
int jin_zhi[100000],A[100000],B[100000];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin>>N;
int Ma,Mb;
cin>>Ma;
for(int i=Ma-1;i>=0;i--)
cin>>A[i];
cin>>Mb;
for(int i=Mb-1;i>=0;i--)
cin>>B[i];
int W=max(Ma,Mb);
bool exist_N=false;
for(int i=0;i<W;i++)
{
jin_zhi[i]=max(A[i],B[i])+1;
if(jin_zhi[i]<2)
jin_zhi[i]=2;
if(jin_zhi[i]==N)
exist_N=true;
}
if(exist_N==false)
jin_zhi[W-1]=N;
long long s=1,result=0;
for(int i=0;i<W;i++)
{
result=(result+(A[i]-B[i])*s)%1000000007;
s=(s*jin_zhi[i])%1000000007;
}
cout<<result;
}
统计子矩阵
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=510;
int n,m,k;
int s[N][N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m>>k;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
cin>>s[i][j];
s[i][j]+=s[i-1][j];
}
ll res=0;
for(int i=1;i<=n;i++)
for(int j=i;j<=n;j++)
for(int l=1,r=1,sum=0;r<=m;r++)
{
sum+=s[j][r]-s[i-1][r];
while(sum>k)
{
sum-=s[j][l]-s[i-1][l];
l=l+1;
}
res +=r-l+1;
}
cout<<res;
return 0;
}
积木画
#include<bits/stdc++.h>
using namespace std;
const int N=1e7+10,MOD=1e9+7;
int n;
int g[4][4]={
{1,1,1,1},
{0,0,1,1},
{0,1,0,1},
{1,0,0,0},
};
int f[2][4];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
f[1][0]=1;
for(int i=1;i<=n;i++)
{
memset(f[i+1&1],0,sizeof(f[0]));
for(int j=0;j<4;j++)
for(int k=0;k<4;k++)
if(g[j][k])
f[i+1 & 1][k]=(f[i+1 & 1][k]+f[i & 1][j])%MOD;
}
cout<<f[n+1 & 1][0];
return 0;
}
扫雷
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=50010,M = 999997;
int n,m;
struct Circle
{
int x,y,r;
}cir[N];
LL h[M];
int id[M];
bool st[M];
LL get_key(int x,int y)
{
return x*1000000001ll+y;
}
int find(int x,int y)
{
LL key=get_key(x,y);
int t = (key % M+M)%M;
while(h[t]!=-1&&h[t]!=key)
if(++t==M)
t=0;
return t;
}
int sqr(int x)
{
return x*x;
}
void dfs(int x,int y,int r)
{
st[find(x,y)]=true;
for(int i=x-r;i<=x+r;i++)
for(int j=y-r;j<=y+r;j++)
if(sqr(i-x)+sqr(j-y)<=sqr(r))
{
int t=find(i,j);
if(id[t]&&!st[t])
{
dfs(i,j,cir[id[t]].r);
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
memset(h,-1,sizeof(h));
cin>>n>>m;
for(int i=1;i<=n;i++)
{
int x,y,r;
cin>>x>>y>>r;
cir[i]={x,y,r};
int t=find(x,y);
if(h[t]==-1)
h[t]=get_key(x,y);
if(!id[t]||cir[id[t]].r<r)
id[t]=i;
}
while(m--)
{
int x,y,r;
cin>>x>>y>>r;
for(int i=x-r;i<=x+r;i++)
for(int j=y-r;j<=y+r;j++)
{
if(sqr(i-x)+sqr(j-y)<=sqr(r))
{
int t=find(i,j);
if(id[t]&&!st[t])
dfs(i,j,cir[id[t]].r);
}
}
}
int res=0;
for(int i=1;i<=n;i++)
if(st[find(cir[i].x,cir[i].y)])
res++;
cout<<res;
return 0;
}
李白打酒加强版
#include<bits/stdc++.h>
using namespace std;
const int N=103,M=103,MOD=1000000007;
int f[N][M][M];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
pair<int ,int> p[t];
for(int i=0;i<t;i++)
{
int x,y;
cin>>x>>y;
p[i]={x,y};
}
for(int tt=0;tt<t;tt++)
{
int n,m;
n=p[tt].first;
m=p[tt].second;
memset(f,0,sizeof(f));
f[0][0][2]=1;
for(int i=0;i<=n;i++)
for(int j=0;j<=m;j++)
for(int k=0;k<=m;k++)
{
if(k%2==0&&i>=1)
f[i][j][k]=(f[i][j][k]+f[i-1][j][k/2])%MOD;
if(j>=1)
f[i][j][k]=(f[i][j][k]+f[i][j-1][k+1])%MOD;
}
cout<<f[n][m-1][1]<<endl;
}
return 0;
}
砍竹子
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=200009,M=7;
int n,layer;
LL f[N][M];
int main()
{
cin>>n;
int ans=0;
for(int i=0;i<n;i++)
{
LL temp[7];
int top=0;
LL h;
cin>>h;
while(h>1) temp[top++]=h,h=sqrt(h/2+1);
layer=max(top,layer);
ans+=top;
for(int j=0;top>0;top--,j++)
{
f[i][j]=temp[top-1];
}
}
for(int i=0;i<layer;i++)
for(int j=1;j<n;j++)
{
if((f[j][i]==f[j-1][i])&&f[j][i])
ans--;
}
cout<<ans<<endl;
return 0;
}