北京清北 综合强化班 Day5
2024-09-05 06:08:01
T1
思路:
输入数据,sort一下,
如果a[i]>sum+1(前缀和)
那么sum+1就一定不会被拼出来,
然后输出即可.
上代码:
#include <iostream>
#include <cstdio>
#define LL long long
using namespace std; const int Maxn = ;
int n;
LL sum,a[Maxn]; int main() {
freopen("lost.in","r",stdin);
freopen("lost.out","w",stdout);
scanf("%d",&n);
for(int i=; i<=n; ++i) scanf("%lld",&a[i]);
sort(a+,a++n);
for(int i=; i<=n; ++i) {
if(sum+<a[i]) {
printf("%lld",sum+);
return ;
}
else sum+=a[i];
}
printf("%lld",sum+);
return ;
}
T1
T2
思路:
1.i<=sqrt(n)
2.i>sqrt(n)
30%
暴力枚举
100%
1.n/i-n/(i+1)<=1 <---> n<=i*(i+1)
//单调递减--->解不等式O(1)进行求解
2.二分答案
上代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cassert>
using namespace std; typedef long long LL;
LL n;
bool check(LL x) { // n <= x*(x+1)
if(x*.*(x+)>1e18) return true;
if(n <= x *(x+)) return true;
return false;
}
int main() {
freopen("div.in","r",stdin);
freopen("div.out","w",stdout);
scanf("%lld",&n);
if(n==) {
puts("");
} else if(n==) {
puts("");
} else {
LL L = ,R=n-;
while(R-L>) {
LL mid = (L+R)/;
if(check(mid)) R=mid;
else L=mid;
}
// assert(check(R));
printf("%lld\n",L+(n/R));
}
return ;
}
100
T3
思路:
1.60% 2^n 进行枚举
其实来个普通的dfs就行233
2.100%
qwq我我我...暂时不会
上代码:
#include<cstdio>
#include<iostream>
using namespace std; const int M = ;
int n,m,vi[M];
double ans[M],pi[M],arcpi[M]; void dfs(int now,int Count,int Money,double k) {
if(now>n) {
if(Money>=m) ans[Count]+=k;
return;
}
dfs(now+,Count,Money+vi[now],k*pi[now]);
dfs(now+,Count+,Money,k*arcpi[now]);
} int main() {
freopen("diamond.in","r",stdin);
freopen("diamond.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=,tmp; i<=n; i++) {
scanf("%d%d",&vi[i],&tmp);
pi[i]=1.0*tmp/,arcpi[i]=1.0-pi[i];
}
dfs(,,,);
for(int i=; i<=n; i++) printf("%.3lf\n",ans[i]);
return ;
}
最新文章
- spin.js
- FastJson转换自定义枚举类
- CentOS设置默认启动命令行(不启动图形界面)
- codeforces A. Flipping Game 解题报告
- CentOS 6 RPM安裝python 2.7
- Linux:crontab命令学习
- HDOJ(HDU) 2503 a/b + c/d(最大公约数问题)
- POJ 2002 点hash
- 微信小程序(兼容性问题)
- rest_framework之认证源码剖析
- 痞子衡嵌入式:第一本Git命令教程(7.1)- 清理之缓存(stash)
- Android JNI 学习(四):接口方法表 &; Base Api &; Exception Api
- gd_t , bd_t 结构分析
- Java高级开发必会的50个性能优化细节
- AngularJS封装UEditor
- Android 关于在ScrollView中加上一个ListView,ListView内容显示不完全(总是显示第一项)的问题的两种简单的解决方案
- PyCharm License Activation激活码失效问题的解决方法
- HDU4513:完美队形II(Manacher)
- mac下面安装redis
- Android与Unity交互研究