传送门
A
从 1到 n 遍历
若i 为7的倍数, 则加上m中7的倍数的个数
若不是7的倍数, 加上 m除以7的个数
#include
#include
using namespace std;
int main(){
long long n,m;
scanf("%lld %lld",&n,&m);
long long sum = 0;
for(long long i = 1;i<=n;i++){
int temp = i%7;
if(i==0)
sum+=(m/7);
else
sum+=(m+temp)/7;
}
printf("%lld",sum);
return 0;
}
B 状压DP
#include
using namespace std;
#define ll long long
int N, M;
ll dp[1035][1035];
void dfs(int i,int j,int state,int nex) {
if (j==N) {
dp[i+1][nex]+=dp[i][state];
return;
}
if (((1<0)
dfs(i,j+1,state,nex);
if (((1<
C 签到题
#include
using namespace std;
#define ll long long
int a[1005];
int main()
{
int n,s;
ll sum=0;
scanf("%d %d",&n,&s);
for(int i=0;i
D 签到题
E 动态规划
#include
using namespace std;
#define ll long long
char a[1005],b[1005];
int dp[1005][1005];
int main()
{
scanf("%s",a);
scanf("%s",b);
int n1 = strlen(a);
int n2 = strlen(b);
memset(dp,0,sizeof(dp));
for(int i=0;i
F
模拟 深搜
#include
using namespace std;
const int mod = 1e9+7;
int dp[205][205][205];
int dir[][2] = { 1,2,2,1,-1,2,-2,1,1,-2,2,-1,-1,-2,-2,-1 };
struct node{
int x;
int y;
int step;
};
int main()
{
int n,m,k;
while(scanf("%d %d %d",&n,&m,&k)!=EOF)
{
queue q;
while(!q.empty())q.pop();
memset(dp,0,sizeof(dp));
dp[0][0][0] = 1;
q.push( node{0,0,0} );
while(!q.empty())
{
node t = q.front();
q.pop();
if(t.step == k)
break;
for(int i=0;i<8;i++)
{
int tx = t.x + dir[i][0];
int ty = t.y + dir[i][1];
if(tx<0||tx>=n||ty<0||ty>=m)continue;
if(dp[tx][ty][t.step+1]==0)
q.push(node{tx,ty,t.step+1});
dp[tx][ty][t.step+1]+=dp[t.x][t.y][t.step];
dp[tx][ty][t.step+1]%=mod;
}
}
printf("%d\n",dp[n-1][m-1][k]);
}
return 0;
}
G
队列+bfs
#include
using namespace std;
#define ll long long
char ma[1010][1010];
int n,m,rx,ry,fx,fy;
int dir[][2]={0,1, 0,-1, 1,0, -1,0};
struct node{
int x,y,step;
}now,qian,ff;
int step[1010][1010];
int bfs()
{
queue que;
memset(step,0,sizeof(step));
for (int i=0;i
H
I 博弈 水题
#include
using namespace std;
#define ll long long
int main(){
ll n,m,k;
while(~scanf("%lld %lld %lld",&n,&m,&k)){
n = n+m;
if(n%2==0&&k%2!=0){
printf("LAOZI CHUI SI NI!\n");
}
else{
printf("HAI YOU SEI!\n");
}
}
return 0;
}
J
列举所有情况 00, 25 , 50, 75结尾
写出第一种其他改一下字符就行
#include
using namespace std;
char s[105],a[105];
int main()
{
int s0,s5,s7,s2,ans,t,flag;
while(scanf("%s",s)>0)
{
ans = 10000;
flag = 0;
strcpy(a,s);
s0 = 0; s5 = 0; s7 = 0; s2 = 0;
for(int i=0;i=2)
{
t = 0;
flag = 1;
for(int i = strlen(a)-1;i>=0;i--)
{
if(a[i]=='0')
{
for(int j = i;j=0;i--)
{
if(a[i]=='0')
{
for(int j = i;j=0;i--)
{
if(a[i]=='5')
{
for(int j = i;j=0;i--)
{
if(a[i]=='2')
{
for(int j = i;j=0;i--)
{
if(a[i]=='5')
{
for(int j = i;j=0;i--)
{
if(a[i]=='7')
{
for(int j = i;j= 0; i--)
{
if (a[i] == '0')
{
for (int j = i; j < strlen(s) - 1; j++)
{
t++;
swap(a[j], a[j + 1]);
}
break;
}
}
for (int i = strlen(s) - 2; i >= 0; i--)
{
if (a[i] == '5')
{
for (int j = i; j < strlen(s) - 2; j++)
{
t++;
swap(a[j], a[j + 1]);
}
break;
}
}
ans = min(ans, t);
}
if(!flag)
ans = -1;
printf("%d\n",ans);
}
return 0;
}