• 【noip2014】day2


    T1

    [前缀和,差分]

    求二维前缀和然后大概差分一下就好了?

     【code】

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long 
    #define File "wireless"
    inline void file(){
        freopen(File".in","r",stdin);
        freopen(File".out","w",stdout);
    } 
    inline int read(){
        int x = 0,f = 1; char ch = getchar();
        while(ch < '0' || ch > '9'){if(ch=='-')f = -1; ch = getchar();}
        while(ch >= '0' && ch <= '9'){x = (x<<1) + (x<<3) + ch-'0'; ch = getchar();}
        return x*f;
    }
    const int mxn = 130;
    int d,n;
    int s[mxn][mxn];
    int a[mxn][mxn];
    
    inline int Q(int x_1,int y_1,int x_2,int y_2){
        return s[x_2][y_2] - s[x_1-1][y_2] - s[x_2][y_1-1] + s[x_1-1][y_1-1];
    }
    int cnt,ans;
    int main(){
        file();
        d = read(),n = read();
        for(int i = 1;i <= n; ++i){
            int x,y,k;
            x = read(),y = read(),k = read();
            a[x][y] = k;
        }
        
    //    s[0][0] = a[0][0];
        for(int i = 0;i <= 128; ++i)
            for(int j = 0;j <= 128; ++j)
                s[i][j] = (s[i][j-1] + s[i-1][j] - s[i-1][j-1] + a[i][j]);
    //            ,printf("%d
    ",s[i][j]);
    
    
    //    printf("%d
    ",ans);
        for(int i = 0;i <= 128; ++i){
            for(int j = 0;j <= 128; ++j){
                int x_1,y_1,x_2,y_2;
                x_1 = (i-d >= 0) ? (i-d) : 0;
                y_1 = (j-d >= 0) ? (j-d) : 0;
                x_2 = (i+d <= 128) ? (i+d) : 128;
                y_2 = (j+d <= 128) ? (j+d) : 128;
                int t = Q(x_1,y_1,x_2,y_2);
                if(t == ans) cnt++;
                else if(t > ans) ans = t,cnt = 1;
            }
        }
        printf("%d %d
    ",cnt,ans);        
        return 0;
    }
    View Code

    T2

    [Bfs]

    通过建反图判断每个点是否能到达终点。

    通过枚举每个能达到终点的点,判断与之相连的边连接的点是否能出现在路径中。

    最后bfs求出起点到终点的距离即可。                

    【code】

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long 
    #define File "road"
    inline void file(){
        freopen(File".in","r",stdin);
        freopen(File".out","w",stdout);
    } 
    inline int read(){
        int x = 0,f = 1; char ch = getchar();
        while(ch < '0' || ch > '9'){if(ch=='-')f = -1; ch = getchar();}
        while(ch >= '0' && ch <= '9'){x = (x<<1) + (x<<3) + ch-'0'; ch = getchar();}
        return x*f;
    }
    const int mxn = 1e4 + 10;
    int n,m;
    bool v1[mxn],v2[mxn];//是否能出现在路途中。是否能到达终点。 
    int dis[mxn];
    vector<int>E1[mxn];
    vector<int>E2[mxn];
    #define pb push_back
    int st,ed;
    queue<int> q;
    
    int main(){
    //    file();
        n = read(),m = read();
        for(int i = 1;i <= m; ++i){
            int x = read(),y = read();
            E1[x].pb(y),E2[y].pb(x);
        }    
        st = read(),ed = read();
        
        v2[ed] = 1; q.push(ed);
        while(q.size()){
            int x = q.front();
            q.pop();
            for(int i = E2[x].size()-1; i >= 0; --i){
                int y = E2[x][i];
                if(!v2[y]){
                    q.push(y);
                    v2[y] = 1;
                }
            }
        }
        if(!v2[st]){
            puts("-1");
            return 0;
        }
        for(int i = 1;i <= n; ++i){
            if(v2[i]){
                v1[i] = 1;
                for(int j = E1[i].size()-1; j >= 0; --j){
                    int y = E1[i][j];
                    if(!v2[y]){
                        v1[i] = 0;
                        break;
                    }                
                }
            }
        }
        
        dis[st] = 1; q.push(st);
        while(q.size()){
            int x = q.front();
            q.pop();
            if(x == ed){
                printf("%d
    ",dis[ed]-1);
                return 0;
            }
            for(int i = E1[x].size()-1; i >= 0; --i){
                int y = E1[x][i];
                if(v1[y] && !dis[y]){
                    dis[y] = dis[x] + 1;
                    q.push(y);
                }
            }
        }
        
        puts("-1");
        return 0;
    }
    View Code

    T3

    [数学]

    读入取模。秦九韶公式。

    【code】 

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long 
    #define File "equation"
    inline void file(){
        freopen(File".in","r",stdin);
        freopen(File".out","w",stdout);
    }
    const int mod = 998244353;
    const int mxn = 110;
    inline ll read(){
        ll x = 0,f = 1; char ch = getchar();
        while(ch < '0' || ch > '9'){if(ch=='-')f = -1; ch = getchar();}
        while(ch >= '0' && ch <= '9'){x = ((x<<1)%mod + (x<<3)%mod + ch-'0')%mod; ch = getchar();}
        return x*f; 
    }
    ll n,m;
    ll a[mxn],b[mxn];
    ll tot(0);
    inline bool J(ll x){
        ll s(0);
        for(ll i = n; i; --i)
            s = ((s + a[i])*x) % mod;
        s = (s+a[0]) % mod;
        return s==0;
    }//秦九韶公式的判断。返回得到的s是否等于0 
    
    int main(){
        file();
        n = read(),m = read();    
        for(ll i = 0;i <= n; ++i) a[i] = read();
        for(ll i = 1;i <= m; ++i){
            if(J(i)) 
                b[++tot] = i;//记录答案 
        }
        printf("%lld
    ",tot);
        for(ll i = 1;i <= tot; ++i) printf("%lld
    ",b[i]);
        return 0;
    }
    View Code

    我又预感因为交题交得慢我今天要ak掉rating。

  • 相关阅读:
    hihocoder #1333 : 平衡树·Splay2
    【bzoj1251】序列终结者 splay
    BZOJ 1588: [HNOI2002]营业额统计 双向链表 / splay / treap
    湖南省第十二届大学生计算机程序设计竞赛 F 地铁 多源多汇最短路
    湖南省第十二届大学生计算机程序设计竞赛 B 有向无环图 拓扑DP
    湖南省第十二届大学生计算机程序设计竞赛 G Parenthesis
    HDU 4251 The Famous ICPC Team Again 主席树
    Codeforces Round #369 (Div. 2) D. Directed Roads dfs求某个联通块的在环上的点的数量
    python main
    python显示灰度图
  • 原文地址:https://www.cnblogs.com/ve-2021/p/11364388.html
Copyright © 2020-2023  润新知