洛谷 B3925 题解
零、前言
注意:本题解非正常思路,若要正解请移步到其他题解。
有 OIer 云:暴力出奇迹,打表出省一。这题感觉打表好题。
一、思路
1.1 写出暴力程序
这就很简单了,只要从 break。代码中
//云剪贴板维护,只能把代码贴在文中了qwq
#include <bits/stdc++.h>
using namespace std;
int n,m;
bool check(int x)
{
for(int rnd=1;rnd<=n;rnd++)
{
if(x==0)return false;//判断是否有鱼吃
int r=x%n;//计算本轮扔掉的鱼i
if(r!=m)return false;
//cout<<(x-r)/n<<' ';
x-=m;//坑点:要减去余数
x=x-x/n;
}
return true;
}
int main()
{
cin>>n>>m;
for(int i=1;;i++)
{
if(check(i))
{
cout<<i<<endl;
break;
}
}
return 0;
}
轻松
1.2 打表
我们一看数据范围:for 枚举所有的
二、代码
注意:代码中因为我没有用
//程序算法:枚举
#include <bits/stdc++.h>
using namespace std;
int n,m,ans[20][20]={
{1,0,0,0,0,0,0,0,0},
{4,7,0,0,0,0,0,0,0},
{27,25,23,0,0,0,0,0,0},
{256,253,250,247,0,0,0,0,0},
{3125,3121,3117,3113,3109,0,0,0,0},
{46656,46651,46646,46641,46636,46631,0,0,0},
{823543,823537,823531,823525,823519,823513,823507,0,0},
{16777216,16777209,16777202,16777195,16777188,16777181,16777174,16777167,0},
{387420489,387420481,387420473,387420465,387420457,387420449,387420441,387420433,387420425},
};
void fast_read()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
int main()
{
//freopen("input.in","r",stdin);
//freopen("output.out","w",stdout);
fast_read();
cin>>n>>m;
cout<<ans[n-1][m]<<endl;
return 0;
}
打表抢到最优解,与第二名相差