zoukankan      html  css  js  c++  java
  • 2015 Multi-University Training Contest 3

    【比赛链接】:click here~~

    5326 :Work

    【题意】:

    It’s an interesting experience to move from ICPC to work, end my college life and start a brand new journey in company.
    As is known to all, every stuff in a company has a title, everyone except the boss has a direct leader, and all the relationship forms a tree. If A’s title is higher than B(A is the direct or indirect leader of B), we call it A manages B.
    Now, give you the relation of a company, can you calculate how many people manage k people. 

    代码:

    <span style="font-size:14px;">#pragma comment(linker,"/STACK:1024000000,1024000000")
    #ifndef _GLIBCXX_NO_ASSERT
    #include <cassert>
    #endif
    
    #include <cctype>
    #include <cerrno>
    #include <cfloat>
    #include <ciso646>
    #include <climits>
    #include <clocale>
    #include <cmath>
    #include <csetjmp>
    #include <csignal>
    #include <cstdarg>
    #include <cstddef>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <ctime>
    
    // C++
    #include <algorithm>
    #include <bitset>
    #include <complex>
    #include <deque>
    #include <exception>
    #include <fstream>
    #include <functional>
    #include <iomanip>
    #include <ios>
    #include <iosfwd>
    #include <iostream>
    #include <istream>
    #include <iterator>
    #include <limits>
    #include <list>
    #include <locale>
    #include <map>
    #include <memory>
    #include <new>
    #include <numeric>
    #include <ostream>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <stdexcept>
    #include <streambuf>
    #include <string>
    #include <typeinfo>
    #include <utility>
    #include <valarray>
    #include <vector>
    
    using namespace std;
    
    #define rep(i,j,k) for(int i=(int)j;i<(int)k;++i)
    #define per(i,j,k) for(int i=(int)j;i>(int)k;--i)
    #define lowbit(a) a&-a
    #define Max(a,b) a>b?

    a:b #define Min(a,b) a>b?b:a #define mem(a,b) memset(a,b,sizeof(a)) typedef long long LL; typedef __int64 LL64; typedef unsigned long long LLU; typedef double db; const int N=105; const int inf=0x3f3f3f3f; int dir4[4][2]= {{1,0},{0,1},{-1,0},{0,-1}}; int dir8[8][2]= {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}}; int movv[5][2]= {{1,0},{0,1},{0,0},{-1,0},{0,-1}}; inline LL read() { int c=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){ c=c*10+ch-'0'; ch=getchar();} return c*f; } int t,k,n,m,ck,res; int sum[N]; int x[N],y[N]; int link[N]; int fa[N]; void Union(int a,int b) { fa[b]=a; sum[a]+=sum[b]+1; ck=sum[b]+1; while(fa[a]!=a) { a=fa[a]; sum[a]+=ck; } } int main() { while(~scanf("%d%d",&t,&k)) { for(int i=1; i<=t; ++i){ fa[i]=i; sum[i]=0; } int a,b; for(int i=0; i<t-1; ++i){ scanf("%d%d",&a,&b); Union(a,b); } int res=0; for(int i=1; i<=t; ++i){ if(sum[i]==k) res++; } printf("%d ",res); } return 0; } </span>


    5317:RGCDQ

    【题目大意】:

    Mr. Hdu is interested in Greatest Common Divisor (GCD). He wants to find more and more interesting things about GCD. Today He comes up with Range Greatest Common Divisor Query (RGCDQ). What’s RGCDQ? Please let me explain it to you gradually. For a positive integer x, F(x) indicates the number of kind of prime factor of x. For example F(2)=1. F(10)=2, because 10=2*5. F(12)=2, because 12=2*2*3, there are two kinds of prime factor. For each query, we will get an interval [L, R], Hdu wants to know maxGCD(F(i),F(j)) (Li<jR)

    给你 n和m,定义F(x)为的素因子种类个数,求maxGCD(F(i),F(j)) (Li<jR)

    【思路】:我们发现事实上F(x)的范围非常小,最大:2*3*5*7*11*13*17*19>10^6,因此用sum[i][j]表示前i个数中素因子个数种类为j 的数有多少个

    代码:

    <span style="font-size:14px;">/--------------5317------------------/
    #include <bits/stdc++.h>
    using namespace std;
    const int N=1e6+10;
    typedef long long LL;
    inline LL read()
    {
        int c=0,f=1;
        char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){c=c*10+ch-'0';ch=getchar();}
        return c*f;
    }
    int sum[N][8];/// 用sum[i][j]记录前 i 个数字中的有 j 个不同素因子的数字的个数
    int num[8];
    int pos[N];
    bool vis[N];
    
    void init()   ///统计每一个数有多少个不同种类的素因子
    {
        for(int i=2; i<=N; ++i){
            if(!vis[i]){
                for(int j=i; j<=N; j+=i){
                    vis[j]=true,pos[j]++;
                }
            }
        }
    }
    
    void solve()
    {
        memset(sum,0,sizeof(sum));
        init();
        for(int i=2; i<=N; ++i){
            for(int j=1; j<=7; ++j){
                if(pos[i]%j==0){
                    sum[i][j]=1;
                }
            }
        }
        for(int i=2; i<=N; ++i){  ///前缀和累加
            for(int j=1; j<=7; ++j){
                sum[i][j]+=sum[i-1][j];
            }
        }
    }
    int t,l,r,res;
    int main()
    {
        solve();
        t=read();
        while(t--){
            l=read();
            r=read();
            for(int j=7; j>=1; --j){
                if(sum[r][j]-sum[l-1][j]>=2){
                    printf("%d
    ",j);
                    break;
                }
            }
        }
        return 0;
    }</span>

    5323: Solve this interesting problem

    【题目大意】:

    给定区间[l,r]。用线段树的递归建树方式build(1, n)。问最小的n是多少,使得build(1,n) 中能直接建出区间[l,r]
    【思路】:
    从底向上搜就好了
    用线段树方式建树 [ 0, n]
    已知[ l, r] 结点 求n
    若 建一个[0, 2*r] 的线段树 ,左子树!=右子树。[0, r]  在左子树里 则n最大为2*r
    若 建一个[0, 2*r+1] 的线段树 ,左子树==右子树,[0, r]  在左子树里 这时则 [0, r] 就能够建树
    搜的时候超出2*r 就直接return

    注意往上dfs顺序。否则会RE!

    ps:说究竟,还是英文是硬伤!

    han!

    代码:

    <span style="font-size:14px;">/***************hdu 5323******************************
    #pragma comment(linker, "/STACK:1024000000,1024000000")
    // C
    #include <cctype>
    #include <cerrno>
    #include <cfloat>
    #include <ciso646>
    #include <climits>
    #include <clocale>
    #include <cmath>
    #include <csetjmp>
    #include <csignal>
    #include <cstdarg>
    #include <cstddef>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <ctime>
    // C++
    #include <algorithm>
    #include <bitset>
    #include <complex>
    #include <deque>
    #include <exception>
    #include <fstream>
    #include <functional>
    #include <iomanip>
    #include <ios>
    #include <iosfwd>
    #include <iostream>
    #include <istream>
    #include <iterator>
    #include <limits>
    #include <list>
    #include <locale>
    #include <map>
    #include <memory>
    #include <new>
    #include <numeric>
    #include <ostream>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <stdexcept>
    #include <streambuf>
    #include <string>
    #include <typeinfo>
    #include <utility>
    #include <valarray>
    #include <vector>
    
    using namespace std;
    
    #define rep(i,j,k) for(int i=(int)j;i<(int)k;++i)
    #define per(i,j,k) for(int i=(int)j;i>(int)k;--i)
    #define lowbit(a) a&-a
    #define Max(a,b) a>b?a:b
    #define Min(a,b) a>b?b:a
    #define mem(a,b) memset(a,b,sizeof(a))
    
    typedef long long LL;
    typedef unsigned long long LLU;
    typedef double db;
    const int N=1e6+10;
    const int inf=0x3f3f3f3f;
    
    char str[N];
    bool vis[N];
    int mat[N][10];///状态之前
    
    int dir4[4][2]= {{1,0},{0,1},{-1,0},{0,-1}};
    int dir8[8][2]= {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
    int movv[5][2]= {{1,0},{0,1},{0,0},{-1,0},{0,-1}};
    
    __int64 l,r,t,res;
    void dfs(__int64 l,__int64 r)
    {
        if(r>=res) return;
        if(l<0) return ;
        if(l==0){
            res=r;
            return;
        }
        if(r-l+1>l) return;
        dfs(2*l-r-1,r);
        dfs(2*l-r-2,r);
        dfs(l,2*r-l+1);
        dfs(l,2*r-l);
    }
    
    int main()
    {
        while(scanf("%I64d%I64d",&l,&r)!=EOF){
            res = inf;
            dfs(l,r);
            printf("%I64d
    ",(res==inf)?-1:res);
        }
        return 0;
    }</span>




  • 相关阅读:
    Flink--Table和DataStream和DataSet的集成
    flink-SQL
    Flink的容错
    Flink--基于mysql的sink和source
    Flink--sink到kafka
    Flink在流处理上常见的Source和sink操作
    【计算机网络】-传输层-传输服务的要素
    【计算机网络】-传输层-传输服务
    文件系统-文件的逻辑结构与存取方法
    文件系统-概念
  • 原文地址:https://www.cnblogs.com/clnchanpin/p/6821266.html
Copyright © 2011-2022 走看看