码迷,mamicode.com
首页 > 其他好文 > 详细

北京清北 综合强化班 Day5

时间:2017-10-06 17:27:29      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:log   day   isp   sed   gif   cas   turn   type   ges   

 

技术分享

   技术分享

             技术分享

思路:

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

上代码:

技术分享
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

const int M = 100011;
int n;
long long sum,a[M];

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+n+1);
    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

技术分享

思路:

  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

 技术分享

  技术分享

   技术分享

 思路:

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

上代码:

技术分享
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int maxn=1005;
int n,m,vi[maxn];
double ans[maxn],pi[maxn],arcpi[maxn];

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;
}
60

 

北京清北 综合强化班 Day5

标签:log   day   isp   sed   gif   cas   turn   type   ges   

原文地址:http://www.cnblogs.com/zxqxwnngztxx/p/7629925.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!