• zstuoj 4423: panda和卡片


    传送门:http://oj.acm.zstu.edu.cn/JudgeOnline/problem.php?id=4423

    题意:

       给定许多数字,这些数字都是2的倍数,问可以用这些数字组成多少个数字。

    思路:

      这道题可以先从小到大排序。可以发现,如果第i个x值不会被前面的值累加得到,说明这个数是和前面的数没有关系,可以把前面的计入答案,否则,需要把cnt +  这个数除以这个独立集中最小值。

       

    //#pragma GCC optimize(3)
    //#pragma comment(linker, "/STACK:102400000,102400000")  //c++
    // #pragma GCC diagnostic error "-std=c++11"
    // #pragma comment(linker, "/stack:200000000")
    // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    // #pragma GCC optimize("-fdelete-null-pointer-checks,inline-functions-called-once,-funsafe-loop-optimizations,-fexpensive-optimizations,-foptimize-sibling-calls,-ftree-switch-conversion,-finline-small-functions,inline-small-functions,-frerun-cse-after-loop,-fhoist-adjacent-loads,-findirect-inlining,-freorder-functions,no-stack-protector,-fpartial-inlining,-fsched-interblock,-fcse-follow-jumps,-fcse-skip-blocks,-falign-functions,-fstrict-overflow,-fstrict-aliasing,-fschedule-insns2,-ftree-tail-merge,inline-functions,-fschedule-insns,-freorder-blocks,-fwhole-program,-funroll-loops,-fthread-jumps,-fcrossjumping,-fcaller-saves,-fdevirtualize,-falign-labels,-falign-loops,-falign-jumps,unroll-loops,-fsched-spec,-ffast-math,Ofast,inline,-fgcse,-fgcse-lm,-fipa-sra,-ftree-pre,-ftree-vrp,-fpeephole2",3)
    
    #include <algorithm>
    #include  <iterator>
    #include  <iostream>
    #include   <cstring>
    #include   <cstdlib>
    #include   <iomanip>
    #include    <bitset>
    #include    <cctype>
    #include    <cstdio>
    #include    <string>
    #include    <vector>
    #include     <stack>
    #include     <cmath>
    #include     <queue>
    #include      <list>
    #include       <map>
    #include       <set>
    #include   <cassert>
    
    using namespace std;
    #define lson (l , mid , rt << 1)
    #define rson (mid + 1 , r , rt << 1 | 1)
    #define debug(x) cerr << #x << " = " << x << "
    ";
    #define pb push_back
    #define pq priority_queue
    
    
    
    typedef long long ll;
    typedef unsigned long long ull;
    //typedef __int128 bll;
    typedef pair<ll ,ll > pll;
    typedef pair<int ,int > pii;
    typedef pair<int,pii> p3;
    
    //priority_queue<int> q;//这是一个大根堆q
    //priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
    #define fi first
    #define se second
    //#define endl '
    '
    
    #define OKC ios::sync_with_stdio(false);cin.tie(0)
    #define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行
    #define REP(i , j , k)  for(int i = j ; i <  k ; ++i)
    #define max3(a,b,c) max(max(a,b), c);
    #define min3(a,b,c) min(min(a,b), c);
    //priority_queue<int ,vector<int>, greater<int> >que;
    
    const ll mos = 0x7FFFFFFF;  //2147483647
    const ll nmos = 0x80000000;  //-2147483648
    const int inf = 0x3f3f3f3f;
    const ll inff = 0x3f3f3f3f3f3f3f3f; //18
    const int mod = 1e9+7;
    const double esp = 1e-8;
    const double PI=acos(-1.0);
    const double PHI=0.61803399;    //黄金分割点
    const double tPHI=0.38196601;
    
    
    template<typename T>
    inline T read(T&x){
        x=0;int f=0;char ch=getchar();
        while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
        while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
        return x=f?-x:x;
    }
    
    
    /*-----------------------showtime----------------------*/
    
                const int maxn = 109;
                ll a[maxn];
                int n;
    int main(){
                while(~scanf("%d", &n)){
                        for(int i=1; i<=n; i++) scanf("%lld", &a[i]);
                        sort(a+1,a+1+n);
                        ll pre = 0,ans = 1,cnt = 0,bas = 1;
                        a[n+1] = inff;
                        for(int i=1; i<=n+1 ; i++) {
                            if(pre >= a[i]){
                                cnt += a[i] / bas;
                                pre += a[i];
                            }
                            else {
                                ans = 1ll*ans * (cnt+1);
                                pre = a[i];
                                cnt = 1;
                                bas = a[i];
                            }
                        }
                        printf("%lld
    ", ans);
                }
                return 0;
    }
    View Code

      

  • 相关阅读:
    git提交到了错误的分支,如何解决
    js使用 isNumber() 判断是否是数字,要注意NaN
    prettier 出现 Couldn't resolve parser "babylon" 错误的解决方法
    在AWS CloudWatch中使用Logs Insights查询错误日志
    腾讯智能对话平台TBP 返回的数据结构
    python 中在使用f string 格式化字符串时出现ValueError: Invalid format specifier 的一种原因
    冒泡排序
    第一次摸底考试总结
    用for循环打印99乘法表
    数据库编写 数据库常用约束
  • 原文地址:https://www.cnblogs.com/ckxkexing/p/10032744.html
Copyright © 2020-2023  润新知