题外话:蒟蒻个人题解—(CF里面没人做啊),我也就做出了A/B/H。
A、Antiamuny wants to learn binary search
题意:就是给你一个二分的模板,自己带,求执行了多少次二分.直接拿来用就行
//
// Created by QYZ on 2023/4/17.
//
#include<bits/stdc++.h>
using namespace std;
double find(int a){
double l=0,r=110;
while (r-l>=1e-6){
double mid = (l+r)/2;
if (mid*mid*mid+a*mid<=a*a+a)l = mid;
else r = mid;
}
return l;
}
int fun_find(int l,int r ,int x){
int cnt =0;
while(l<=r){
cnt++;
int mid =l+r>>1;
if (mid==x) break;
if (mid<x) l=mid+1;
else r =mid-1;
}
return cnt;
}
int main(){
int l,r,x;
int n;
cin>>n;
while (n--){
cin>>l>>r>>x;
cout<<fun_find(l,r,x)<<endl;
}
}
B. Bespread with chequers
题外话:走来递归TLE,真可恶啊
题意:有1×2 大小和 2×2 大小的棋子,其中 1×2 大小的棋子可以横着占据 1 行 2 列的格子,也可以竖着占据 2行 1列的格子。求有2行n列,输出铺满当前棋盘的方案总数。
思路:找出递推式,进行递推就可以了
1.f1=1,f2=3;
2.f3=5=3+1*2
3.f4=11=5+3*2
f5=21=11+5*2
可得出递推式: n==1 , f1=1. n==2 f2=3
n>2 f(n) = f(n-1)+f(n-2)*2;
//
// Created by QYZ on 2023/4/20.
// B题,找出递推式
// 用递归爆TLE,所以要对其中数据进行预处理,然后进行遍历输出从而时间复杂度达到O(1);
//
#include<iostream>
using namespace std;
const long long mod = 1e9+7;
long long a[1000010];
void init(){
a[1] =1;
a[2] =3;
for (int i = 3; i <= 1000007 ; i++) {
a[i] = (a[i-1]+a[i-2]*2)%mod;
}
}
long long fun(int x){
if (x==1) return 1;
else if (x==2) return 3;
else return (fun(x-1)+ fun(x-2)*2)%mod;
}
void solve()
{
int n;
cin >> n;
cout << a[n] << '\n';
}
int main(){
int t=0,num=0;
cin>>t;
init();
while (t--){
cin>>num;
cout<<a[num]<<endl;
}
}
H、How to know the function
题意:给定了一个多项式函数,求最少询问多少次可以确定这个多项式函数
思路:根据题目2步可以确定,系数>0的时候的多项式函数
当系数=0,只需要一步
//
// Created by QYZ on 2023/4/20.
//
#include<iostream>
using namespace std;
int main(){
long long int t,num;
cin>>t;
while (t--){
cin>>num;
if (num==0) cout<<1<<"\n";
else cout<<2<<"\n";
}
}