//https://img2018.cnblogs.com/blog/1646268/201908/1646268-20190806114008215-138720377.jpg

部分分做题记录(暴力+玄学)

以下的玄学做法除非考试的时候暴力也不会打否则千万不要轻易尝试,如果爆零本博主一概不负责!

P5977 [CEOI2008] Fence

这题我是肯定不会做的,所以我如果是在考场上的话就会像这样一样瞎几把乱搞(谁叫我不会模拟退火)
首先看到题目就可以发现数据范围特别小,只有不到100,但是我还是不会,爆搜也不会,所以我就只能看这个题目的题面,然后我就想,你说会不会有一种情况那就是你用了三个木桩子就全围起来了,我觉得这个是可以骗分得分的好方式,所以我就直接cout 60,然后喜提40分。
这道题数据太水了所以不算部分分了。
蔡徐坤录

P6817 [PA2013]Filary

这道题目一看我就做不出来,然后我就直接一个暴力,当然可以看到你要枚举除以的数,以及余数和每一个数,四舍五入就是N三方的复杂度,要是取里面的最大值这不就T飞了吗,于是我就取了一个中间一点的数:100,假设他数据小,那他100的话也差不多够了,如果他数据大,我们还可以在不T的前提下A掉当除数小于等于100的情况,美哉!
下面是我改成120后的代码,100是32,120是33.

#include<bits/stdc++.h>//暴力枚举不T的情况下33 
#define re register
using namespace std;
int n,a[100010],ans,cnt;
int main()
{
	cin>>n;
	for(re int i=1;i<=n;i++)
	  scanf("%d",&a[i]);
	for(re int i=2;i<=120;i++)//优化防止TLE,因为可能有的枚举到120之前就已经是最优解了 
	{
		int sum=0,num=i;
		for(re int j=0;j<i;j++)//枚举余数 
		{
			sum=0;
			for(re int k=1;k<=n;k++)//枚举每一个数 
			  if(a[k]%i==j)sum++;
			if(sum>ans||(sum==ans&&num>cnt))
			  ans=sum,cnt=num;
		}
	}
	cout<<ans<<" "<<cnt<<endl;
	return 0;
}
//40min暴力拿到33分 

P1036 [NOIP2002 普及组] 选数

本题就是一个单纯的搜索题目,所以直接A了
看一下题面,给你n个数,让你选k个,问你有多少种方案拼出来个质数
那这不就很好搜索了吗,我们dfs里面传三个变量(x,cnt,sum),分别代表当前是第几个数在考虑选不选,已经选了几个数,以及当前选了的数的总和,那这就好处理了,当cnt等于k的时候判断一下是不是素数就ans++,剪枝什么的不需要,普及-考什么剪枝。

#include<bits/stdc++.h>
using namespace std;
int ans,n,m,a[1010];
int pd(int x)
{
	int flag=1;
	for(int i=2;i<=sqrt(x);i++)
	{
		if(x%i==0)
		  flag=0;
	}
	return flag;
}
void dfs(int x,int cnt,int sum)
{
	if(cnt==m)
	{
		if(pd(sum))
		  ans++;
		return ;
	}
	if(x>n)return ;
	dfs(x+1,cnt,sum);
	dfs(x+1,cnt+1,sum+a[x]);
	return ;
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	  cin>>a[i];
	dfs(1,0,0);
	cout<<ans<<endl;
	return 0;
}
//20分钟打出来的搜索 正解就是搜索的橙题 

AT2165 [AGC006D] Median Pyramid Hard

这题目一看就不可做,考虑乱搞暴力
可以直接开一个二维数组模拟,然后输出答案,AC是不可能的,但拿20分是很轻松的,接下来考虑乱搞
发现题目中给的两个样例都是一开始输入的数据的中位数在最上面,那么我们就可以写一个sort来水一下,由于出题人想不到我们会这么勇敢,而且他也不会去造数据的时候考虑这么多,毕竟难造,在10个点的情况下对一两个点还是很有可能的。

效果出乎意料的好呢~
当然后来这题我用二分A了。

P1432 倒水问题

搜索绿题值得一水
本题的主要意思就是给你两个已知容积为a,b没有刻度的瓶子,问你倒出k升水的操作数量和操作类型
乍一看很简单,我当时就用30min打了一个dfs,结果他挂了。。
老老实实来写bfs。
这种需要最少操作的不是dp就是bfs,当然我会选择后者
先来考虑一下队列里面放些什么东西,首先要有ab容器当前的水量,然后就是当前操作的类型,最后也是最重要的就是记录当前情况的前一个操作编号,这样我们才可以输出操作的路径。
然后就是朴(sang)实(xin)无(bing)华(kuang)的bfs,前四种操作很好写,后面两个操作要分类讨论,一种是倒空了,另一种是倒满另一个了,自己还有剩余。
然后他TLE了。
所以还要开一个数组来表示当前情况有没有出现过,这样就保证每一个情况都只遍历过一次,然后就可以A了(
代码:

#include<bits/stdc++.h>//dfs打挂了改的bfs,基本上重写了一遍 
using namespace std;
int n,t[1001][1001];//t数组用来判重
struct que{int a,b,w,l;}q[100000];//a,b为两容器现在水量,w是操作编号,l是上一次操作在队列中的坐标
void print(int x)//输出函数,因为在那个地方写看起来太麻烦了 
{
	int ans=0;//ans存放操作的数量 
	stack<int>st;//开一个栈 
	while(1)//只要没到底就一直循环 
	{
		if(q[x].l==0)break;//一开始的操作也入栈了,退出 
		st.push(q[x].w);//把当前点压入栈中 
		ans++;//操作数加1 
		x=q[x].l;//替换成当前操作的前一个操作 
	}
	cout<<ans;//先输出操作数量 
	while(!st.empty())//然后输出 
		cout<<" "<<st.top(),st.pop();//输一个操作类型输一个空格 
	cout<<endl;//输出换行符 
}
void bfs(int a,int b,int c)//开始广搜 
{
	memset(t,0,sizeof t);//每一次都要清空一下 
	int f=1,r=1;//fr是当前队列的左右下标 
	while(f<=r)//只要队列不空 
	{
		if(q[f].b==c)//如果当前的点的b值达到了题目要求的值 
		{
			print(f);//输出当前答案 
			break;//完美结束 
		}
		if(q[f].a!=a&&t[a][q[f].b]==0)//如果当前a没满并且当前这种情况没有出现过 
		{
			r++;//入列 
			q[r].a=a;//a装满 
			q[r].b=q[f].b;//b还是原来的值 
			q[r].w=1;//操作类型是1 
			q[r].l=f;//当前点的前一个操作 
			t[q[r].a][q[r].b]=1;//当前点的情况标记为出现过 
		}
		if(q[f].b!=b&&t[q[f].a][b]==0)//如果当前b没满并且当前这种情况没有出现过 
		{
			r++;//入列 
			q[r].a=q[f].a;//a还是原来的值 
			q[r].b=b;//b装满 
			q[r].w=2;//操作类型是2 
			q[r].l=f;//标记当前点的前一个操作 
			t[q[r].a][q[r].b]=1;//标记此类情况已经出现过 
		}
		if(q[f].a!=0&&t[0][q[f].b]==0)//如果当前a不是空的并且当前情况没有出现过 
		{
			r++;//入列 
			q[r].a=0;//a清空 
			q[r].b=q[f].b;//b还是原来的值 
			q[r].w=3;//当前点的操作类型是3 
			q[r].l=f;//标记当前点的前驱 
			t[q[r].a][q[r].b]=1;//标记出现过 
		}
		if(q[f].b!=0&&t[q[f].a][0]==0)//如果b不空并且没出现过 
		{
			r++;//入列 
			q[r].a=q[f].a;//a值不变 
			q[r].b=0;//b值清空 
			q[r].w=4;//操作类型是4 
			q[r].l=f;//标记前驱 
			t[q[r].a][q[r].b]=1;//标记出现过 
		}
		if(q[f].a!=a&&q[f].b!=0)//如果当前点的a不满并且b有值 
		{
			if(q[f].a+q[f].b<=a&&t[q[f].a+q[f].b][0]==0)//b到进a里面不够,b空了 
			{
				r++;//入列 
				q[r].a=q[f].a+q[f].b;//把b倒进a里面 
				q[r].b=0;//b值清空 
				q[r].w=5;//操作类型是5 
				q[r].l=f;//标记前驱 
				t[q[r].a][q[r].b]=1;//标记当前情况出现过 
			}
			if(q[f].a+q[f].b>a&&t[a][q[f].a+q[f].b-a]==0)//如果当前b倒进a里面会有剩余 
			{
				r++;//入列 
				q[r].a=a;//a满了 
				q[r].b=q[f].a+q[f].b-a;//b剩下的值 
				q[r].w=5;//标记操作类型为5 
				q[r].l=f;//标记前驱 
				t[q[r].a][q[r].b]=1;//标记当前情况 
			}
		}
		if(q[f].a!=0&&q[f].b!=b)//如果当前a不空,b不满 
		{
			if(q[f].a+q[f].b<=b&&t[0][q[f].a+q[f].b]==0)//当前a倒进b里不会满 
			{
				r++;//入列 
				q[r].a=0;//a值清空 
				q[r].b=q[f].a+q[f].b;//计算当前b的值 
				q[r].w=6;//标记操作类型是6 
				q[r].l=f;//标记前驱 
				t[q[r].a][q[r].b]=1;//标记当前清空出现过 
			}
			if(q[f].a+q[f].b>b&&t[q[f].a+q[f].b-b][b]==0)//如果把a倒进b里面会有剩余 
			{
				r++;//入列 
				q[r].a=q[f].a+q[f].b-b;//计算a剩余的值 
				q[r].b=b;//b满了 
				q[r].w=6;//操作类型为6 
				q[r].l=f;//标记前驱 
				t[q[r].a][q[r].b]=1;//标记当前情况出现过 
			}
		}
		f++;//左下标右移 
	}
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int a,b,c;
		cin>>a>>b>>c;//输入信息 
		bfs(a,b,c);//开始bfs 
	}
	return 0;//好习惯 
}

P1657 选书

水题让我快乐

//大约花了15min?
#include<bits/stdc++.h>
using namespace std;
int n,a[110],b[110],vis[110],ans;
void dfs(int x)
{
	if(x==n+1)
	  return ans++,void();
	if(!vis[a[x]])
	{
		vis[a[x]]=1;
		dfs(x+1);
		vis[a[x]]=0; 
	}
	if(!vis[b[x]])
	{
		vis[b[x]]=1;
		dfs(x+1);
		vis[b[x]]=0;
	}
	return ;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	  cin>>a[i]>>b[i];
	dfs(1);
	cout<<ans<<endl;
	return 0;
}

P1679 神奇的四次方数

这个题的正解是背包dp,但考试我不敢写,谁知道他给你的样例有多水,样例过了交上全WA也不是没有的事。
所以我们来考虑乱搞爆搜,我们可以很轻易的得出一个最简单的搜索,但是他叫上只能A一个,其他全都TLE了,所以我们要考虑加一点小剪枝,毕竟这题是普及-背包dp而不是普及-的搜索,所以我们考虑如何让他健步如飞,首先我们要知道他的最后结果要最小值,所以如果我们当前选的数的个数已经大于存放的最优解了的话,我们就没有必要再继续搜了,而这一情况需要我们倒着搜,其次就是如果当前的累计的和已经大于他给出的值了的话,我们就可以直接退出了,这样他已经能A了,但是我们为了防止出题人用一些奇奇怪怪的方法来干掉我们的搜索,所以我们就可以用究极剪枝:1+4=4+1,所以我们只要保证他是从小到大或者从大到小搜的就可以了。
代码:

#include<bits/stdc++.h>
#define int long long
#define bug cout<<"WTF?"<<'\n'
using namespace std;
int ans=500,n,oo;
void dfs(int last,int cnt,int sum)//上一次选的数的值,cnt是已经选了的数的数量,sum存放当前的总和 
{
//	oo++;
//	bug;
    if(cnt>ans)return ;//如果大于当前节点的话就直接退出 
    if(sum>n)return ;//如果当前总和已经大于n的话就直接退出 
	if(sum==n)//当前刚好够n 
	  return ans=min(ans,cnt),void();//ans取最小值 
	int i=0;//i是当前一轮要选的数 
	for(i=0;i*i*i*i<=n;)i++;//要保证不能超过n 
	for( ;i>=last;i--)//到着枚举不然第一个小优化没有用了 
	  dfs(i,cnt+1,sum+i*i*i*i);//继续往下深搜 
	return ;//退出 
}
signed main()
{
	cin>>n;
	dfs(1,0,0);//开始搜索 
	cout<<ans<<endl;//输出答案 
//	cout<<oo<<endl;
	return 0;
}

P2657 [SCOI2009] windy 数

数位dp狗都不打.
首先我们要打一个暴力。然后只得了30分。
既然这道题要用数位dp,那肯定不用数位dp就能A,所以考虑yys教的打表大法。
首先我们需要一个打表程序,然后直接分段打表

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int P=1e6;//p是每一段的段长 
int l,r,ans;//lr是左右区间,ans存放答案,下面是打的表 
int db[5500]={0,202174,136131,138503,138214,138252,138252,138214,138503,136131,155315,0,0,0,138214,138252,138252,138214,138503,136131,155315,155315,0,0,0,138252,138252,138214,138503,136131,155315,155315,136131,0,0,0,138252,138214,138503,136131,155315,155315,136131,138503,0,0,0,138214,138503,136131,155315,155315,136131,138503,138214,0,0,0,138503,136131,155315,155315,136131,138503,138214,138252,0,0,0,136131,155315,155315,136131,138503,138214,138252,138252,0,0,0,155315,155315,136131,138503,138214,138252,138252,138214,0,0,0,155315,136131,138503,138214,138252,138252,138214,138503,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155315,136131,0,0,0,138252,138214,138503,136131,155315,155315,136131,138503,0,0,0,138214,138503,136131,155315,155315,136131,138503,138214,0,0,0,138503,136131,155315,155315,136131,138503,138214,138252,0,0,0,136131,155315,155315,136131,138503,138214,138252,138252,0,0,0,155315,155315,136131,138503,138214,138252,138252,138214,0,0,0,155315,136131,138503,138214,138252,138252,138214,138503,0,0,0,0,138503,138214,138252,138252,138214,138503,136131,155315,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155315,136131,138503,0,0,0,138214,138503,136131,155315,155315,136131,138503,138214,0,0,0,138503,136131,155315,155315,136131,138503,138214,138252,0,0,0,136131,155315,155315,136131,138503,138214,138252,138252,0,0,0,155315,155315,136131,138503,138214,138252,138252,138214,0,0,0,155315,136131,138503,138214,138252,138252,138214,138503,0,0,0,0,138503,138214,138252,138252,138214,138503,136131,155315,0,0,0,138214,138252,138252,138214,138503,136131,155315,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155315,136131,138503,138214,0,0,0,138503,136131,155315,155315,136131,138503,138214,138252,0,0,0,136131,155315,155315,136131,138503,138214,138252,138252,0,0,0,155315,155315,136131,138503,138214,138252,138252,138214,0,0,0,155315,136131,138503,138214,138252,138252,138214,138503,0,0,0,0,138503,138214,138252,138252,138214,138503,136131,155315,0,0,0,138214,138252,138252,138214,138503,136131,155315,155315,0,0,0,138252,138252,138214,138503,136131,155315,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155315,136131,138503,138214,138252,0,0,0,136131,155315,155315,136131,138503,138214,138252,138252,0,0,0,155315,155315,136131,138503,138214,138252,138252,138214,0,0,0,155315,136131,138503,138214,138252,138252,138214,138503,0,0,0,0,138503,138214,138252,138252,138214,138503,136131,155315,0,0,0,138214,138252,138252,138214,138503,136131,155315,155315,0,0,0,138252,138252,138214,138503,136131,155315,155315,136131,0,0,0,138252,138214,138503,136131,155315,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155315,136131,138503,138214,138252,138252,0,0,0,155315,155315,136131,138503,138214,138252,138252,138214,0,0,0,155315,136131,138503,138214,138252,138252,138214,138503,0,0,0,0,138503,138214,138252,138252,138214,138503,136131,155315,0,0,0,138214,138252,138252,138214,138503,136131,155315,155315,0,0,0,138252,138252,138214,138503,136131,155315,155315,136131,0,0,0,138252,138214,138503,136131,155315,155315,136131,138503,0,0,0,138214,138503,136131,155315,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155315,136131,138503,138214,138252,138252,138214,0,0,0,155315,136131,138503,138214,138252,138252,138214,138503,0,0,0,0,138503,138214,138252,138252,138214,138503,136131,155315,0,0,0,138214,138252,138252,138214,138503,136131,155315,155315,0,0,0,138252,138252,138214,138503,136131,155315,155315,136131,0,0,0,138252,138214,138503,136131,155315,155315,136131,138503,0,0,0,138214,138503,136131,155315,155315,136131,138503,138214,0,0,0,138503,136131,155315,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155315,136131,138503,138214,138252,138252,138214,138503,0,0,0,0,138503,138214,138252,138252,138214,138503,136131,155315,0,0,0,138214,138252,138252,138214,138503,136131,155315,155315,0,0,0,138252,138252,138214,138503,136131,155315,155315,136131,0,0,0,138252,138214,138503,136131,155315,155315,136131,138503,0,0,0,138214,138503,136131,155315,155315,136131,138503,138214,0,0,0,138503,136131,155315,155315,136131,138503,138214,138252,0,0,0,136131,155315,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,138503,138214,138252,138252,138214,138503,136131,155315,0,0,0,138214,138252,138252,138214,138503,136131,155315,155315,0,0,0,138252,138252,138214,138503,136131,155315,155315,136131,0,0,0,138252,138214,138503,136131,155315,155315,136131,138503,0,0,0,138214,138503,136131,155315,155315,136131,138503,138214,0,0,0,138503,136131,155315,155315,136131,138503,138214,138252,0,0,0,136131,155315,155315,136131,138503,138214,138252,138252,0,0,0,155315,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,138503,138214,138252,138252,138214,138503,136131,155315,0,0,0,138214,138252,138252,138214,138503,136131,155315,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155315,136131,138503,138214,0,0,0,138503,136131,155315,155315,136131,138503,138214,138252,0,0,0,136131,155315,155315,136131,138503,138214,138252,138252,0,0,0,155315,155315,136131,138503,138214,138252,138252,138214,0,0,0,155315,136131,138503,138214,138252,138252,138214,138503,0,0,0,0,138503,138214,138252,138252,138214,138503,136131,155315,0,0,0,138214,138252,138252,138214,138503,136131,155315,155315,0,0,0,138252,138252,138214,138503,136131,155315,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155315,136131,138503,138214,138252,0,0,0,136131,155315,155315,136131,138503,138214,138252,138252,0,0,0,155315,155315,136131,138503,138214,138252,138252,138214,0,0,0,155315,136131,138503,138214,138252,138252,138214,138503,0,0,0,0,138503,138214,138252,138252,138214,138503,136131,155315,0,0,0,138214,138252,138252,138214,138503,136131,155315,155315,0,0,0,138252,138252,138214,138503,136131,155315,155315,136131,0,0,0,138252,138214,138503,136131,155315,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155315,136131,138503,138214,138252,138252,0,0,0,155315,155315,136131,138503,138214,138252,138252,138214,0,0,0,155315,136131,138503,138214,138252,138252,138214,138503,0,0,0,0,138503,138214,138252,138252,138214,138503,136131,155315,0,0,0,138214,138252,138252,138214,138503,136131,155315,155315,0,0,0,138252,138252,138214,138503,136131,155315,155315,136131,0,0,0,138252,138214,138503,136131,155315,155315,136131,138503,0,0,0,138214,138503,136131,155315,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155315,136131,138503,138214,138252,138252,138214,0,0,0,155315,136131,138503,138214,138252,138252,138214,138503,0,0,0,0,138503,138214,138252,138252,138214,138503,136131,155315,0,0,0,138214,138252,138252,138214,138503,136131,155315,155315,0,0,0,138252,138252,138214,138503,136131,155315,155315,136131,0,0,0,138252,138214,138503,136131,155315,155315,136131,138503,0,0,0,138214,138503,136131,155315,155315,136131,138503,138214,0,0,0,138503,136131,155315,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155315,136131,138503,138214,138252,138252,138214,138503,0,0,0,0,138503,138214,138252,138252,138214,138503,136131,155315,0,0,0,138214,138252,138252,138214,138503,136131,155315,155315,0,0,0,138252,138252,138214,138503,136131,155315,155315,136131,0,0,0,138252,138214,138503,136131,155315,155315,136131,138503,0,0,0,138214,138503,136131,155315,155315,136131,138503,138214,0,0,0,138503,136131,155315,155315,136131,138503,138214,138252,0,0,0,136131,155315,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,138503,138214,138252,138252,138214,138503,136131,155315,0,0,0,138214,138252,138252,138214,138503,136131,155315,155315,0,0,0,138252,138252,138214,138503,136131,155315,155315,136131,0,0,0,138252,138214,138503,136131,155315,155315,136131,138503,0,0,0,138214,138503,136131,155315,155315,136131,138503,138214,0,0,0,138503,136131,155315,155315,136131,138503,138214,138252,0,0,0,136131,155315,155315,136131,138503,138214,138252,138252,0,0,0,155315,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int pd(int x)//判断是否为windy数 
{
	int xx=x,flag=1;//flag标记 
	int last=xx%10;//last是上一个数 
	xx/=10;//因为末尾的数已经存放在last里面了,所以除以10; 
	while(xx)//只要没算完 
	{
		int y=xx%10;//取出模数 
		if(abs(last-y)<2)//判断是否相差大于等于2 
		{
			flag=0;//不等于就标记直接break 
			break;
		}
		last=y;//存放上一个的数 
		xx/=10;//继续算 
	}
	return flag;//返回标记 
}
int Ans(int x)//计算1到x的里面有多少符合的数 
{
	int sum=0;
	int xx=x/P;
	for(int i=1;i<=xx;i++)
	  sum+=db[i];//累加前面几段 
	for(int i=xx*P+1;i<=x;i++)//最后的部分段计算 
	  if(pd(i))sum++;
	return sum;//返回答案 
}
//signed main()//打表程序 
//{
//	freopen("55.out","w",stdout);
//	for(int i=0;i<2000;i++)//把2e9分成2000段打出来 
//	{
//		ans=0;
//		for(int j=i*P+1;j<=P*(i+1);j++)
//			if(pd(j))ans++;
//		cout<<","<<ans;
//	}
//	return 0;
//}//暴力枚举判断30分,接下来考虑分段打表 
signed main()
{
	cin>>l>>r;
	ans=(Ans(r)-Ans(l-1));//前缀和一样的思想 
	cout<<ans<<endl;//输出 
	return 0;//好习惯 
}

然后就可以A掉这道水题了。

posted @ 2022-10-08 17:17  北烛青澜  阅读(37)  评论(2编辑  收藏  举报