2024牛客寒假算法基础集训营6
A
思路:暴力
查看代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=1e6+5,INF=0x3f3f3f3f,mod=1e9+7,Mod=998244353;
const int MAXN=1e8+5;
const double eps=1e-9;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
void solve() {
vector<int>pri(105);
vector<int>ans;
for(int i=2;i<=100;++i){
for(int j=2;j*j<=i;++j){
if(i%j==0){
pri[i]=1;
break;
}
}
}
for(int i=2;i<=100;++i){
for(int j=2;j<=100;++j){
for(int z=2;z<=100;++z){
if(i*j*z>100)continue;
if(i==j||i==z||j==z)continue;
if(!pri[i]&&!pri[j]&&!pri[z]){
ans.push_back(i*j*z);
}
}
}
}
sort(ans.begin(),ans.end());
int l,r;
cin>>l>>r;
auto it= std::lower_bound(ans.begin(), ans.end(),l);
if(it!=ans.end()&&*it<=r)cout<<*it;
else cout<<-1;
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t=1;
// cin>>t;
// init();
while(t--){
solve();
}
return 0;
}
B
思路:暴力
查看代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=1e6+5,INF=0x3f3f3f3f,mod=1e9+7,Mod=998244353;
const int MAXN=1e8+5;
const double eps=1e-9;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
void solve() {
int n;
cin>>n;
vector<int>a(n),b(n);
for(auto &v:a)cin>>v;
for(auto &v:b)cin>>v;
sort(a.begin(),a.end());
int mi=3e9,p,tb;
for(int i=0;i<n;++i){
auto it= std::lower_bound(a.begin(), a.end(),b[i]);
int mii=3e9,k;
if(it!=a.end()){
if(abs(*it-b[i])<mii)mii=abs(*it-b[i]),k=it-a.begin();
}
if(it!=a.begin()){
it--;
if(abs(*it-b[i])<mii)mii=abs(*it-b[i]),k=it-a.begin();
}
if(mii<mi){
mi=mii,p=k,tb=i;
}
}
vector<int>ans(n);
for(int i=0,j=0;i<n;++i){
if(j==p)j++;
if(i==tb)ans[i]=p;
else ans[i]=j++;
}
for(int i=0;i<n;++i)cout<<a[ans[i]]<<' ';
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t=1;
// cin>>t;
// init();
while(t--){
solve();
}
return 0;
}
C
思路:暴力
查看代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=1e6+5,INF=0x3f3f3f3f,mod=1e9+7,Mod=998244353;
const int MAXN=1e8+5;
const double eps=1e-9;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
void solve() {
vector<int>ve(200);
ve[1]=0,ve[2]=1;
int k=45;
for(int i=3;i<=k;++i){
ve[i]=ve[i-1]+ve[i-2];
}
map<int,vector<int>>mp;
for(int i=1;i<=k;++i){
for(int j=1;j<=k;++j){
for(int z=1;z<=k;++z){
vector<int>g(3);
g[0]=ve[i],g[1]=ve[j],g[2]=ve[z];
int c=g[0]+g[1]+g[2];
if(c>1e9)continue;
if(!mp.count(c))mp[c]=g;
}
}
}
int q,n;
cin>>q;
while(q--){
cin>>n;
if(mp.count(n)){
vector<int>g=mp[n];
for(auto v:g)cout<<v<<' ';
cout<<'\n';
}else cout<<-1<<'\n';
}
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t=1;
// cin>>t;
// init();
while(t--){
solve();
}
return 0;
}
D
思路:两种情况
查看代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=1e6+5,INF=0x3f3f3f3f,mod=1e9+7,Mod=998244353;
const int MAXN=1e8+5;
const double eps=1e-9;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
void solve() {
double p;
cin>>p;
double ans=pow(p,2)*pow(1-p,3);
p=1-p;
ans+=pow(p,2)*pow(1-p,3);
cout<<fixed<<setprecision(6)<<ans;
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t=1;
// cin>>t;
// init();
while(t--){
solve();
}
return 0;
}
E
思路:模拟,提BOx的x被坑了wa了一发
标签:typedef,const,winter,int,double,day5,long,week5,define From: https://www.cnblogs.com/bible-/p/18030280