【LGR-288-Div.2】洛谷 7 月月赛 I & lnOI Round 1 T1 轻舟已过 题解
前言
- msjing根本不会写于是直接暴力打表
可能是在打比赛之前一直在听《杀死那个石家庄人》
solve
暴搜挂着机,打表出省一。
- 我们发现一共 \(20\) 个数,考虑打表。
- 先写朴素,然后直接跑,前 \(25\) 个跑挺快但是到 \(30\) 就跑不动,算一下需要的时间,貌似从 \(34\) 到 \(35\) 要两个小时,考虑加速打表。
- 观察一下之前的答案,我们发现在 \(n\) 大于 \(30\) 后的答案与 \(2^n\) 非常接近,从这里下手,由于我们只需要求偶数解,所以我们直接对上一次结果乘上 \(4\),然后把后面的 \(9\) 位全抹掉,以这个数位起点,以 \(2^n\) 为终点,直接暴力枚举,时间明显缩短,从 \(38\) 到 \(40\) 好像就跑了 \(40\) 秒。
code
- 代码有点怪因为是分着打的
- 请忽视那个
#define int long long
答案code
#include<bits/stdc++.h>
using namespace std;
long long biao[45]={0,
2,
2,
2,
12,
20,
56,
104,
240,
464,
992,
1952,
4032,
8000,
16256,
32384,
65280,
130304,
261632,
522752,
1047552,
2094080,
4192256,
8382464,
16773120,
33542144,
67100672,
134193152,
268419072,
536821760,
1073709056,
2147385344,
4294901760,
0,
17179738112,
0,
68719214592,
0,
274877382656,
0,
1099510579200};
int main()
{
int n;
cin >> n;
cout << biao[n] << endl;
return 0;
}
打表code1
#include<bits/stdc++.h>
#define int long long
using namespace std;
long long read() {long long x=0,f=1;char ch=getchar();while (ch<'0' || ch>'9'){if (ch == '-') f=-1;ch=getchar();}while (ch>='0' && ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}return x*f;}
long long n;
long long lowbit(long long x) {return x&(-x);}
long long Count(long long x)
{
long long cnt=0;
while (x) x-=lowbit(x),cnt++;
return cnt;
}
long long ans;
long long ksm(long long x,long long y)
{
long long res=1;
while (y)
{
if (y&1) res*=x;
x*=x;
y>>=1;
}
return res;
}
signed main()
{
freopen("biao.out","w",stdout);
long long last=0;
for (int n=1;n<=40;n++)
{
// n=read();
for (long long i=last;i<=ksm(2,n);i+=2)
{
if (ksm(2,Count(i)) == lowbit(i)) ans=i;
}
cerr << n << endl;
// 这个是看打到哪个用的
printf("%lld\n",ans);
last=ans;
}
return 0;
}
打表code2
- 只给出一个示例,其他的都差不多
#include<bits/stdc++.h>
#define int long long
using namespace std;
long long read() {long long x=0,f=1;char ch=getchar();while (ch<'0' || ch>'9'){if (ch == '-') f=-1;ch=getchar();}while (ch>='0' && ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}return x*f;}
long long n;
long long lowbit(long long x) {return x&(-x);}
long long Count(long long x)
{
long long cnt=0;
while (x) x-=lowbit(x),cnt++;
return cnt;
}
long long ans;
long long ksm(long long x,long long y)
{
long long res=1;
while (y)
{
if (y&1) res*=x;
x*=x;
y>>=1;
}
return res;
}
signed main()
{
freopen("biao34.out","w",stdout);
n=read();
for (long long i=17000000000;i<=ksm(2,n);i+=2)
{
if (ksm(2,Count(i)) == lowbit(i)) ans=i;
}
printf("%lld\n",ans);
return 0;
}
// 32ans:294901760
// (294901760<<1)<<1 = 17179607040
后话
- sbmqwm:如此生活三十年
- msjing:你别唱了

浙公网安备 33010602011771号