zoukankan      html  css  js  c++  java
  • hdu 多校第一场

    1001

    思路:打表可以发现只有3|n 和 4|n 的情况有解,判一下就好啦。

    #include<bits/stdc++.h>
    #define LL long long
    #define fi first
    #define se second
    #define mk make_pair
    #define pii pair<int, int>
    #define y1 skldjfskldjg
    #define y2 skldfjsklejg
    
    using namespace std;
    
    const int N = 1e5 + 7;
    const int M = 1e5 + 7;
    const int inf = 0x3f3f3f3f;
    const LL INF = 0x3f3f3f3f3f3f3f3f;
    const int mod = 1e9 +7;
    
    LL n;
    int main() {
    
        int T; scanf("%d", &T);
        while(T--) {
            scanf("%lld", &n);
            if(n % 3 == 0) {
                LL ans = n / 3;
                printf("%lld
    ", ans * ans * ans);
            } else if(n % 4 == 0) {
                LL ans = n / 4;
                printf("%lld
    ", ans * ans * (ans + ans));
            } else {
                puts("-1");
            }
        }
    
        return 0;
    }
    
    
    /*
    */
    View Code

    1003

    思路:按x轴排序,按三个三个的顺序输出即可。

    #include<bits/stdc++.h>
    #define LL long long
    #define fi first
    #define se second
    #define mk make_pair
    #define pii pair<int, int>
    #define y1 skldjfskldjg
    #define y2 skldfjsklejg
    
    using namespace std;
    
    const int N = 1e5 + 7;
    const int M = 1e5 + 7;
    const int inf = 0x3f3f3f3f;
    const LL INF = 0x3f3f3f3f3f3f3f3f;
    const int mod = 1e9 +7;
    
    struct Point {
        int x, y, id;
        bool operator < (const Point &rhs) const {
            if(x == rhs.x) return y < rhs.y;
            return x < rhs.x;
        }
    } p[N];
    
    int n;
    int main() {
    
        int T; scanf("%d", &T);
        while(T--) {
            scanf("%d", &n);
            n *= 3;
            for(int i = 1; i <= n; i++) {
                scanf("%d%d", &p[i].x, &p[i].y);
                p[i].id = i;
            }
    
            sort(p + 1, p + 1 + n);
    
            for(int i = 1; i <= n; i += 3) {
                printf("%d %d %d
    ", p[i].id, p[i + 1].id, p[i + 2].id);
            }
        }
        return 0;
    }
    
    
    /*
    */
    View Code

    1011

    思路:直接模拟,队友写的。

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n;
        scanf("%d",&n);
        while(n--)
        {
            int h,m;
            scanf("%d%d",&h,&m);
    
    
            char t[100];
            int lateh=0,latem=0;
            scanf("%s",t);
            int len=strlen(t);
    
            bool point=false;
    
            int pos;
    
            for(int i=4;i<len;i++)
            {
                if(t[i]=='.'){
                    point=true;
                    pos=i;
                }
            }
            if(point){
                for(int i=4;i<pos;i++)
                {
                    lateh*=10;
                    lateh+=t[i]-'0';
                }
                for(int i=pos+1;i<len;i++)
                {
                    latem*=10;
                    latem+=t[i]-'0';
                }
            }
            else{
                for(int i=4;i<len;i++)
                {
                    lateh*=10;
                    lateh+=t[i]-'0';
                }
            }
    
    
            h+=16;
            h%=24;
    
    
            if(t[3]=='+')
            {
                h+=lateh;
                h%=24;
                m+=6*latem;
                h+=m/60;
                h%=24;
                m%=60;
            }
            else{
                h+=24;
                h-=lateh;
    
                if(m<latem*6)
                {
                    h--;
                    m+=60;
                    m-=latem*6;
                }
                else{
                    m-=latem*6;
                }
    
                h%=24;
    
            }
            printf("%02d:%02d
    ",h,m);
        }
    }
    /*
    3
    11 11 UTC+8
    11 12 UTC+9
    11 23 UTC+0
    */
    View Code

    1004

    思路:贪心取,把包含于别的线段的线段去掉,用set维护一个可用集, 每条线段结束恢复可以再用的数字。

    #include<bits/stdc++.h>
    #define LL long long
    #define fi first
    #define se second
    #define mk make_pair
    #define pii pair<int, int>
    #define y1 skldjfskldjg
    #define y2 skldfjsklejg
    
    using namespace std;
    
    const int N = 1e5 + 7;
    const int M = 1e5 + 7;
    const int inf = 0x3f3f3f3f;
    const LL INF = 0x3f3f3f3f3f3f3f3f;
    const int mod = 1e9 +7;
    
    int n, m, tot, ans[N], num[N];
    struct Line {
        int l, r;
        bool operator < (const Line &rhs) const {
            if(l == rhs.l) return r > rhs.r;
            return l < rhs.l;
        }
    } a[N], b[N];
    set<int> st;
    
    int main() {
    
        int T; scanf("%d", &T);
        while(T--) {
            tot = 0; st.clear();
            scanf("%d%d", &n, &m);
    
            for(int i = 1; i <= n; i++) st.insert(i), num[i] = ans[i] = 0;
    
    
            for(int i = 1; i <= m; i++) {
                scanf("%d%d", &a[i].l, &a[i].r);
            }
    
            sort(a + 1, a + 1 + m);
            b[tot++] = a[1];
    
    
            for(int i = 2; i <= m; i++) {
                if(a[i].r <= b[tot - 1].r) continue;
                b[tot++] = a[i];
            }
    
            for(int i = 0; i < tot; i++) {
                num[b[i].r + 1] -= 1;
                num[b[i].l] += 1;
            }
    
    
    
            for(int i = 1; i <= n; i++) num[i] += num[i - 1];
    
    //        puts("");
    //        for(int i = 1; i <= n; i++) printf("%d ", num[i]);
    //        puts("");
    
            int ptr = 0, cnt = 0;
            b[tot].l = inf, b[tot].r = inf + 1;
    
            for(int i = 1; i <= n; i++) {
    
                while(ptr < tot && i > b[ptr].r) {
                    for(int j = b[ptr].l; j < b[ptr + 1].l && j <= b[ptr].r; j++) {
    //                    if(ans[j] == 2) cout << i << endl;
                        st.insert(ans[j]);
                    }
                    ptr++;
                }
    
                ans[i] = *st.begin();
    
                if(num[i]) {
                    st.erase(st.begin());
                }
    
            }
    
            printf("%d", ans[1]);
            for(int i = 2; i <= n; i++) printf(" %d", ans[i]);
            puts("");
        }
        return 0;
    }
    
    
    /*
    10
    10 3
    1 5
    2 7
    4 8
    */
    View Code

    1002

    队友后面一直在写的题目,瞎贪心就过了,正解好像是先按前边段长还是后半段长分成两类,然后类以内再排序。

    //#pragma comment(linker, "/stack:200000000")
    //#pragma GCC optimize("Ofast,no-stack-protector")
    //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    //#pragma GCC optimize("unroll-loops")
    #include<bits/stdc++.h>
    #define fi first
    #define se second
    #define mp make_pair
    #define pb push_back
    #define pi acos(-1.0)
    #define ll long long
    #define vi vector<int>
    #define mod 1000000007
    #define ld long double
    #define C 0.5772156649
    #define ls l,m,rt<<1
    #define rs m+1,r,rt<<1|1
    #define pll pair<ll,ll>
    #define pil pair<int,ll>
    #define pli pair<ll,int>
    #define pii pair<int,int>
    #define cd complex<double>
    #define ull unsigned long long
    #define base 1000000000000000000
    #define Max(a,  b) ((a)>(b)?(a):(b))
    #define Min(a,  b) ((a)<(b)?(a):(b))
    #define fio ios::sync_with_stdio(false);cin.tie(0)
    inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
    inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
    inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
    inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
    
    using namespace std;
    
    const double eps=1e-8;
    const ll INF=0x3f3f3f3f3f3f3f3f;
    const int N=100000+10,maxn=100000+10,inf=0x3f3f3f3f;
    
    char s[N];
    pii p[N],pp[N];
    bool cmp1(pii a,pii b){return a.fi>b.fi||a.fi==b.fi&&a.se>b.se;}
    bool cmp2(pii a,pii b){return a.fi>b.fi||a.fi==b.fi&&a.se<b.se;}
    bool cmp3(pii a,pii b){return a.fi<b.fi||a.fi==b.fi&&a.se>b.se;}
    bool cmp4(pii a,pii b){return a.fi<b.fi||a.fi==b.fi&&a.se<b.se;}
    int main()
    {
        int T;
        while(~scanf("%d",&T))
        {
            while(T--)
            {
                int n;scanf("%d",&n);
                int ans=0,ans1=0,ans2=0;
    
                for(int i=0;i<n;i++)
                {
                    scanf("%s",s);
                    int len=strlen(s),l=0,r=0;
                    for(int j=0;j<len;j++)
                    {
                        if(s[j]==')')
                        {
                            if(l!=0)l--,ans+=2;
                            else r++;
                        }
                        else l++;
                    }
                    p[i]=mp(l,r);
                }
                for(int i=0;i<n;i++)pp[i]=p[i];
                int res=0,ma=0;
                sort(p,p+n,cmp1);
                for(int i=1;i<n;i++)
                {
                    if(min(p[i].fi,p[i-1].se)>min(p[i].se,p[i-1].fi))
                    {
                        res+=2*min(p[i].fi,p[i-1].se);
                        if(p[i].fi>p[i-1].se)
                            p[i]=mp(p[i].fi-p[i-1].se+p[i-1].fi,p[i].se);
                        else p[i]=mp(p[i-1].fi,p[i-1].se-p[i].fi+p[i].se);
                    }
                    else
                    {
                        res+=2*min(p[i].se,p[i-1].fi);
                        if(p[i].se>p[i-1].fi)
                            p[i]=mp(p[i].fi,p[i].se-p[i-1].fi+p[i-1].se);
                        else p[i]=mp(p[i-1].fi-p[i].se+p[i].fi,p[i-1].se);
                    }
                }
                ma=max(ma,res);
                for(int i=0;i<n;i++)p[i]=pp[i];
                res=0;
                sort(p,p+n,cmp2);
                for(int i=1;i<n;i++)
                {
                    if(min(p[i].fi,p[i-1].se)>min(p[i].se,p[i-1].fi))
                    {
                        res+=2*min(p[i].fi,p[i-1].se);
                        if(p[i].fi>p[i-1].se)
                            p[i]=mp(p[i].fi-p[i-1].se+p[i-1].fi,p[i].se);
                        else p[i]=mp(p[i-1].fi,p[i-1].se-p[i].fi+p[i].se);
                    }
                    else
                    {
                        res+=2*min(p[i].se,p[i-1].fi);
                        if(p[i].se>p[i-1].fi)
                            p[i]=mp(p[i].fi,p[i].se-p[i-1].fi+p[i-1].se);
                        else p[i]=mp(p[i-1].fi-p[i].se+p[i].fi,p[i-1].se);
                    }
                }
                for(int i=0;i<n;i++)p[i]=pp[i];
                ma=max(ma,res);
                res=0;
                sort(p,p+n,cmp3);
                for(int i=1;i<n;i++)
                {
                    if(min(p[i].fi,p[i-1].se)>min(p[i].se,p[i-1].fi))
                    {
                        res+=2*min(p[i].fi,p[i-1].se);
                        if(p[i].fi>p[i-1].se)
                            p[i]=mp(p[i].fi-p[i-1].se+p[i-1].fi,p[i].se);
                        else p[i]=mp(p[i-1].fi,p[i-1].se-p[i].fi+p[i].se);
                    }
                    else
                    {
                        res+=2*min(p[i].se,p[i-1].fi);
                        if(p[i].se>p[i-1].fi)
                            p[i]=mp(p[i].fi,p[i].se-p[i-1].fi+p[i-1].se);
                        else p[i]=mp(p[i-1].fi-p[i].se+p[i].fi,p[i-1].se);
                    }
                }
                for(int i=0;i<n;i++)p[i]=pp[i];
                ma=max(ma,res);
                res=0;
                sort(p,p+n,cmp4);
                for(int i=1;i<n;i++)
                {
                    if(min(p[i].fi,p[i-1].se)>min(p[i].se,p[i-1].fi))
                    {
                        res+=2*min(p[i].fi,p[i-1].se);
                        if(p[i].fi>p[i-1].se)
                            p[i]=mp(p[i].fi-p[i-1].se+p[i-1].fi,p[i].se);
                        else p[i]=mp(p[i-1].fi,p[i-1].se-p[i].fi+p[i].se);
                    }
                    else
                    {
                        res+=2*min(p[i].se,p[i-1].fi);
                        if(p[i].se>p[i-1].fi)
                            p[i]=mp(p[i].fi,p[i].se-p[i-1].fi+p[i-1].se);
                        else p[i]=mp(p[i-1].fi-p[i].se+p[i].fi,p[i-1].se);
                    }
                }
                for(int i=0;i<n;i++)p[i]=pp[i];
                printf("%d
    ",ans+ma);
            }
        }
        return 0;
    }
    /***********************
    100000
    4
    )))
    )))
    )(
    (((
    ***********************/
    View Code

    补题:

    1006

    我后面一个半小时都在写这道题。。 我先打了个表,发现找不到规律,然后拉过来我的找规律队友,分分钟

    找出来了,每个数字出现自身有的2这个因子的个数次。 然后我就开始码,二分找出最后一个数对应值,然后

    算答案,复杂度(logn) ^ 2, 然后被卡T了。。(别人居然没有T。。),然后开始扣log,发现最后一个数值在

    n/2附近,缩小二分的范围,交上去发现,hdu炸掉了。。 然后多改了几次范围交了很多次。最后死于有一个

    地方没有取模。。  想了想好像确实是我的锅,难受。

    #include<bits/stdc++.h>
    #define LL long long
    #define fi first
    #define se second
    #define mk make_pair
    #define pii pair<int, int>
    
    using namespace std;
    
    const int N = 1e5 + 7;
    const int M = 1e5 + 7;
    const int inf = 0x3f3f3f3f;
    const LL INF = 0x3f3f3f3f3f3f3f3f;
    const int mod = 1e9 +7;
    
    LL n, ivn2, bin[63];
    //LL a[N], sum[N];
    void add(LL &a, LL b) {
        a += b; if(a >= mod) a -= mod;
    }
    
    LL fastPow(LL a, LL b) {
        LL ans = 1;
        while(b) {
            if(b & 1) ans = ans * a % mod;
            a = a * a % mod; b >>= 1;
        }
        return ans;
    }
    
    LL check(LL x) {
        LL ans = 0;
        for(int i = 0; i <= 62; i++) {
            ans += x / bin[i];
            if(ans >= n - 1) return true;
        }
        return ans >= n - 1;
    }
    
    LL cal(LL x) {
        LL ans = 0;
        for(int i = 0; i <= 62; i++) {
            ans += x / bin[i];
        }
        return ans;
    }
    
    int main() {
    
        ivn2 = fastPow(2, mod - 2);
        bin[0] = 1;
        for(int i = 1; i <= 62; i++) bin[i] = bin[i - 1] * 2;
    
        LL q = 500000000000000014;
    
    
        int T; scanf("%d", &T);
        while(T--) {
            scanf("%lld", &n);
            if(n == 1) {
                puts("1");
                continue;
            }
    
            LL l = max(1ll, n / 2 - 30), r = min(n, n / 2 + 30), mid, ret = -1;
    
            while(l <= r) {
                mid = l + r >> 1;
                if(check(mid)) ret = mid, r = mid - 1;
                else l = mid + 1;
            }
    
            LL num = ret - 1, now = 0;
            for(int i = 0; i <= 62; i++) {
                if(bin[i] > num) break;
                LL cnt = num / bin[i];
                cnt %= mod;
                add(now, bin[i] % mod * (cnt + 1) % mod * (cnt) % mod * ivn2 % mod);
            }
    
            add(now, (n - 1 - cal(num)) % mod * ret % mod);
    
            printf("%lld
    ", (1 + now) % mod);
        }
        return 0;
    }
    
    
    /*
    100000
    1000000000000000000
    */
    View Code

    1008

    构造笛卡尔树,算贡献。。。 学习了一波笛卡尔树。

    #include<bits/stdc++.h>
    #define LL long long
    #define fi first
    #define se second
    #define mk make_pair
    #define pii pair<int, int>
    #define y1 skldjfskldjg
    #define y2 skldfjsklejg
    
    using namespace std;
    
    const int N = 1e6 + 7;
    const int M = 1e5 + 7;
    const int inf = 0x3f3f3f3f;
    const LL INF = 0x3f3f3f3f3f3f3f3f;
    const int mod = 1e9 +7;
    
    int l[N], r[N], vis[N], stk[N], sum[N], inv[N], n;
    pii a[N];
    
    LL ans;
    void dfs(int u) {
        sum[u] = 1;
        if(l[u]) dfs(l[u]), sum[u] += sum[l[u]];
        if(r[u]) dfs(r[u]), sum[u] += sum[r[u]];
        ans = ans * inv[sum[u]] % mod;
    }
    
    void build() {
        int top = 0;
        for(int i = 1; i <= n; i++)
            l[i] = 0, r[i] = 0, vis[i] = 0;
        for(int i = 1; i <= n; i++)
        {
            int k = top;
            while(k > 0 && a[stk[k - 1]] > a[i]) k--;
            if(k) r[stk[k - 1]]=i;
            if(k < top) l[i] = stk[k];
            stk[k++]=i;
            top = k;
        }
        for(int i=1; i<=n; i++)
            vis[l[i]] = vis[r[i]] = 1;
        int rt=0;
        for(int i=1; i<=n; i++)
            if(vis[i]==0) rt=i;
        dfs(rt);
    }
    
    void init() {
        inv[1] = 1;
        for(int i = 2; i < N; i++) {
            inv[i] = (mod - mod / i) * 1ll * inv[mod % i] % mod;
        }
    }
    int main() {
    
        init();
        int T; scanf("%d", &T);
        while(T--) {
            ans = 1;
            scanf("%d", &n);
            for(int i = 1; i <= n; i++) {
                int x; scanf("%d", &x);
                a[i].fi = -x;
                a[i].se = i;
                sum[i] = 0;
            }
    
            build();
    
            printf("%lld
    ", ans * n % mod * inv[2] % mod);
        }
        return 0;
    }
    
    
    /*
    */
    View Code
  • 相关阅读:
    将SVD应用于推荐系统
    matrix.A
    机架感知配置
    PCA主成分分析进行数据降维
    Rabbitmq的高级特性
    Topics(主题模式)
    Routing(exchange--direct)
    fanout(Publish/Subscribe)发布/订阅
    Work Queues(工作队列)
    simple queue(简单队列)
  • 原文地址:https://www.cnblogs.com/CJLHY/p/9359431.html
Copyright © 2011-2022 走看看