zoukankan      html  css  js  c++  java
  • cfER79

    传送门


    A New Year Garland standard input/output 1 s, 256 MB Submit Add to favourites x6464

      插空法,三种颜色,假设红色最多, 先把红色球放一排, 为了两个红色球不想碰 所以要往红色球的间隔中放入另外两种颜色的球 而如果红色球数量为 n 那红色球之间的空隔为 n-1, 所以 若另外两种颜色球数量 大于 n-1 则 Yes, 否则 No

    B Verse For Santa standard input/output 1 s, 256 MB Submit Add to favourites x4213

      因为只能skip 1个礼物,所以如果所有礼物的时间加起来小于圣诞老人能听的最大时间 那就不必跳过 输出 0, 否则 找到会总时间会超过最大时间的串 并输出其中时间最大的礼物下标。题目和我理解的有些出入  我一开始理解的是跳过一个礼物 必须要 礼物数量更大 但题解就是跳过而已 不判断是否礼物数量更多
    C Stack of Presents standard input/output 1 s, 256 MB Submit Add to favourites x3464

      记录下每个礼物在a 数组中的位置, 然后每个礼品的发送时间 1s, 共 m s, 然后查找需要的时间为 remove  和 push  2*(pos[x]-i-1) (其中remove需要的时间为 pos[x]-i-1 i为已经去除的礼物数, 如果之后的位置小于pos[x] 则已经在栈顶 不需要寻找)   因为 i 从 0 开始, 所以  2*(pos[x]-i) 
    D Santa's Bot standard input/output 5 s, 256 MB Submit Add to favourites x1572

      题意,有n 个小朋友, 每人有 kx 个想要的礼物, 问从 里面挑一个小朋友 选一个他想要的礼物  再在n 个小朋友里面选一个送给他, 问这个礼物是他想要的概率, 求逆元, 然后就可以写下概率公式 先挑一个小朋友 1/n  再选一个礼物 1/kx   再挑一个小朋友送给他这个礼物且是他满意的礼物  cnt(presen)/n , 然后把这些概率相乘便是一个礼物的有效概率 (题目中No item is contained in the same list more than once.) 然后把所有礼物的有效概率加起来即可

    #include <bits/stdc++.h> 
    //cfER 79
    using namespace std;
    #define _for(i,a,b) for(int i = (a); i < (b); i++)
    #define _rep(i,a,b) for(int i = (a); i <= (b); i++)
    #define ll long long
    void taskA(){
        int t; 
        cin >> t;
        while(t--) {
            int a[3]; cin >> a[0] >> a[1] >> a[2];
            sort(a, a+3);
            cout << (a[2]-1 <= a[0]+a[1]?"Yes
    ":"No
    ");
        }
        return;
    }
    void taskB1(){
        int t; cin >> t;
        while(t--) {
            int n; ll s; cin >> n >> s;
            vector<int> a(n);
            int ans = 0;
            _for(i,0,n) cin>> a[i];
            _for(i,0,n) {
                if(a[i] > a[ans]) ans = i;
                s-=a[i];
                if(s < 0) break;
            }
            if(s >= 0) ans = -1;
            cout << ans+1 << "
    "; 
        }
        return;
    }
    
    void taskB(){
        int t; cin >> t;
        while(t--) {
            int n;ll s; cin >> n >> s;
            vector<int> a(n);
            _for(i,0,n) cin >> a[i];
    
            int ans = 0, k = 0;
            ll sum = 0;
            _for(i,0,n) sum += a[i], k = i;
            if(sum <= s) {cout << "0
    "; continue;}
            sum = 0;
            _for(i,0,n) {
                sum += a[i];
                if(a[i] > a[ans]) ans = i;
                if(sum > s)  break;
            }
            cout << ans+1 << "
    ";
        }
        return;
    }
    void taskC(){
        int t; cin >> t;
        while(t--) {
            int n,m;
            cin >> n >> m;
            vector<int> pos(n);
            _for(i,0,n) {
                int x; cin >> x; x--;
                pos[x] = i;
            }
    
            ll ans = m; int lst = -1;
            _for(i,0,m) {
                int x; cin >> x; x--;
                int y = pos[x];
                if(y > lst) ans += 2*(y-i), lst = y;
            }
            cout << ans << "
    ";
        }
        return;
    }
    const int mod = 998244353;
    ll fpow(ll a, ll b) {
        ll ret = 1;
        while(b) {
            if(b&1) ret = ret*a%mod;
            a = a*a%mod;
            b >>= 1; 
        }
        return ret;
    }
    ll inv(ll x) { return fpow(x, mod-2)%mod;}
     
    void taskD(){
        int t; //cin >> t;
        t = 1;
        while(t--) {
            int n; cin >> n;
            vector<int> a[n], cnt(1e6+2);
            _for(i,0,n) {
                int k; cin >> k;
                a[i].resize(k);
                _for(j,0,k) cin >> a[i][j], cnt[a[i][j]]++; 
            }
            ll ans = 0;
            _for(i,0,n) for(auto x:a[i]) {
                ans = (ans+inv(1LL*n)*inv(1LL*n)%mod*cnt[x]%mod*inv(1LL*a[i].size())) %mod;
            }
            cout << ans << "
    ";
        }
        return;
    }
    int main(){
        ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        //taskA();
        //taskB();
        //taskC();
        //taskD();
        return 0;
    }
  • 相关阅读:
    spring aop实现过程之三Spring AOP中Aspect编织的实现
    spring aop实现过程之一代理对象的生成
    数据库常用面试题(SQL Server) (转载)
    回溯法解八后问题
    masmplus增加调试工具
    c++ new关键字 详解
    EMU8086 编译器使用简介
    汇编操作显存
    回溯法简介
    汇编链接时 错误:unresolved external symbol _WinMainCRTStartup
  • 原文地址:https://www.cnblogs.com/163467wyj/p/12131076.html
Copyright © 2011-2022 走看看