HihoCoder 1873 Frog and Portal ###K //K
题目链接:https://hihocoder.com/problemset/problem/1873
题意:给定一个数 从0走到200 每次可以走一位或者两位, 可以在任意地方设计传送门, 问如何使最终的方案数为n
思路:构造等于一个具体的数,考虑用二进制来构造 即每次乘2来得到一个数
考虑传送门的时候每次 都构造2两种可能 如果此时有1 让其跳到终点 每次的构造需要5个位置 1 2 3 4 5 1为起点, 2传送到3 4传送到终点或死路,5传送到下一个起点,
注意第一个要构造1的时候特别处理一下即可
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 #define pb push_back 5 const int maxn =3e5+10; 6 const int mod=998244353; 7 int f[65]; 8 9 10 int main() 11 { 12 ios::sync_with_stdio(false); 13 cin.tie(0); 14 ll n; 15 while(cin>>n) 16 { 17 //int index=0; 18 memset(f,0,sizeof(f)); 19 for(int i=0;i<35;i++) 20 { 21 if((n>>i)&1) 22 f[i]=1; 23 } 24 int l=4; 25 int cnt=4; 26 cout<<106<<'\n'; 27 if(f[0]) 28 cout<<1<<" "<<199<<'\n'; 29 else 30 cout<<1<<" "<<1<<'\n'; 31 cout<<2<<" "<<4<<'\n'; 32 for(int i=1;i<35;i++) 33 { 34 cout<<l+1<<" "<<l+2<<'\n'; 35 cout<<l+3<<" "<<l+5<<'\n'; 36 if(f[i]) 37 cout<<l+4<<" "<<199<<'\n'; 38 else 39 cout<<l+4<<" "<<190<<'\n'; 40 l+=5; 41 cnt+=3; 42 43 } 44 //cout<<cnt<<" debug"<<'\n'; 45 cout<<191<<" "<<191<<'\n'; 46 cout<<192<<" "<<192<<'\n'; 47 } 48 49 50 51 52 53 54 55 56 57 58 59 60 }

浙公网安备 33010602011771号