zoukankan      html  css  js  c++  java
  • 哈尔滨理工大学第六届程序设计团队 E-Mod

    /*
    成功水过,哈哈哈,可能数据水吧
    */
    #include <stdio.h>
    #include <algorithm>
    #include <string.h>
    #include <queue>
    #include <set>
    #define t_mid (l+r >> 1)
    #define ls (o<<1)
    #define rs (o<<1 | 1)
    #define lson ls,l,t_mid
    #define rson rs,t_mid+1,r
    using namespace std;
    typedef long long ll;
    const int N = 100000 + 5;
    int a[N],c[N<<2],n;
    void build(int o,int l,int r)
    {
        if(l==r) {c[o] = a[l];return;}
        build(lson);
        build(rson);
        c[o] = min(c[ls],c[rs]);
    }
    
    int query(int ql,int qr,int o,int l,int r,int x)
    {
        if(l==r)
        {
            if(c[o] <= x) return l;//找到比他小的了
            else return -1;
        }
        int ans = -1;
        if(t_mid >= ql && c[ls] <= x)
        {
            ans = query(ql,qr,lson,x);
            if(ans == -1)
            {
                if(t_mid < qr && c[rs] <= x) ans = query(ql,qr,rson,x);
            }
            return ans;
        }
        else if(t_mid < qr && c[rs] <= x) return query(ql,qr,rson,x);
        return -1;
    }
    
    int main()
    {
        //freopen("C:\Users\acer\Desktop\in.txt","r",stdin);
        int T;scanf("%d",&T);
        while(T--)
        {
            scanf("%d",&n);
            for(int i=1;i<=n;i++)
                scanf("%d",a+i);
            build(1,1,n);
    
            int q;
            scanf("%d",&q);
            while(q--)
            {
                int op;
                scanf("%d",&op);
                int now =op;
                int l=1;
                while(l <=n)
                {
                    l=query(l,n,1,1,n,now);
                    if(l == -1) break;
                    now %= a[l];
                }
                printf("%d
    ",now);
            }
        }
    }
  • 相关阅读:
    AC_9. 分组背包问题
    AC_8. 二维费用的背包问题
    AC_7混合背包问题
    AC_5. 多重背包问题 II
    AC_4. 多重背包问题 I
    AC_3. 完全背包问题
    小郡肝火锅点餐系统——测试部署发布
    Vue脚手架搭建
    归并排序-总结
    小郡肝火锅点餐系统——项目文档
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/6158350.html
Copyright © 2011-2022 走看看