北京清北 综合强化班 Day5

 T1

   

             

思路:

  输入数据,sort一下,
  如果a[i]>sum+1(前缀和)
  那么sum+1就一定不会被拼出来,
  然后输出即可.

上代码:

#include <iostream>
#include <cstdio>
#define LL long long
using namespace std;

const int Maxn = 100011;
int n;
LL sum,a[Maxn];

int main() {
    freopen("lost.in","r",stdin);
    freopen("lost.out","w",stdout);
    scanf("%d",&n);
    for(int i=1; i<=n; ++i) scanf("%lld",&a[i]);
    sort(a+1,a+1+n);
    for(int i=1; i<=n; ++i) {
        if(sum+1<a[i]) {
            printf("%lld",sum+1);
            return 0;
        }
        else sum+=a[i];
    }
    printf("%lld",sum+1);
    return 0;
}
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*1.*(x+1)>1e18) return true;
    if(n <= x *(x+1)) return true;
    return false;
}
int main() {
    freopen("div.in","r",stdin);
    freopen("div.out","w",stdout);
    scanf("%lld",&n);
    if(n==1) {
        puts("1");
    } else if(n==2) {
        puts("2");
    } else {
        LL L = 1,R=n-1;
        while(R-L>1) {
            LL mid = (L+R)/2;
            if(check(mid)) R=mid;
            else L=mid;
        }
        // assert(check(R));
        printf("%lld\n",L+(n/R));
    }
    return 0;
}
100

 T3

  

   

 思路:

  1.60% 2^n 进行枚举
    其实来个普通的dfs就行233
  2.100%
    qwq我我我...暂时不会

上代码:

#include<cstdio>
#include<iostream>
using namespace std;

const int M = 1005;
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+1,Count,Money+vi[now],k*pi[now]);
    dfs(now+1,Count+1,Money,k*arcpi[now]);
}

int main() {
    freopen("diamond.in","r",stdin);
    freopen("diamond.out","w",stdout);
    scanf("%d%d",&n,&m);
    for(int i=1,tmp; i<=n; i++) {
        scanf("%d%d",&vi[i],&tmp);
        pi[i]=1.0*tmp/100,arcpi[i]=1.0-pi[i];
    }
    dfs(1,0,0,1);
    for(int i=0; i<=n; i++) printf("%.3lf\n",ans[i]);
    return 0;
}
View Code

 

posted @ 2017-10-06 16:43  夜雨声不烦  阅读(222)  评论(0编辑  收藏  举报