• 今日SGU 5.12


    SGU 149

    题意:求每一个点的距离最远距离的点的长度

    收获:次大值和最大值,dfs

    #include<bits/stdc++.h>
    #define de(x) cout<<#x<<"="<<x<<endl;
    #define dd(x) cout<<#x<<"="<<x<<" ";
    #define rep(i,a,b) for(int i=a;i<(b);++i)
    #define repd(i,a,b) for(int i=a;i>=(b);--i)
    #define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
    #define ll long long
    #define mt(a,b) memset(a,b,sizeof(a))
    #define fi first
    #define se second
    #define inf 0x3f3f3f3f
    #define INF 0x3f3f3f3f3f3f3f3f
    #define pii pair<int,int>
    #define pdd pair<double,double>
    #define pdi pair<double,int>
    #define mp(u,v) make_pair(u,v)
    #define sz(a) (int)a.size()
    #define ull unsigned long long
    #define ll long long
    #define pb push_back
    #define PI acos(-1.0)
    #define qc std::ios::sync_with_stdio(false)
    #define db double
    #define all(a) a.begin(),a.end()
    const int mod = 1e9+7;
    const int maxn = 1e4+6;
    const double eps = 1e-6;
    using namespace std;
    bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
    bool ls(const db &a, const db &b) { return a + eps < b; }
    bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
    ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
    ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
    ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
    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*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //inv[1]=1;
    //for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
    int mx[maxn][2] = {0};
    vector<pii> G[maxn];
    int dfs(int u,int p){
        rep(i,0,sz(G[u])){
            int v=G[u][i].se,w=G[u][i].fi;
            if(v==p) continue;
            int tmp = dfs(v,u) + w;
            rep(i,0,2) if(mx[u][i]<tmp) swap(mx[u][i],tmp);
        }
        return mx[u][0];
    }
    void dp(int u,int p){
        rep(i,0,sz(G[u])){
            int v=G[u][i].se,w=G[u][i].fi;
            if(v==p) continue;
            int tmp;
            if(mx[v][0] + w == mx[u][0]) tmp = mx[u][1] + w;
            else tmp = mx[u][0] + w;
            rep(i,0,2) if(mx[v][i]<tmp) swap(mx[v][i],tmp);
            dp(v,u);
        }
    }
    int main(){
        int n;
        scanf("%d",&n);
        rep(i,2,n+1){
            int u,c;
            scanf("%d%d",&u,&c);
            G[u].pb(mp(c,i));
            G[i].pb(mp(c,u));
        }
        dfs(1,-1);dp(1,-1);
        rep(i,1,n+1) printf("%d
    ",mx[i][0]);
        return 0;
    }
    View Code

     SGU 196

    题意:求AT*A,Aij表示i这个顶点是否是j这个边的端点(是1,不是0)

    收获:度是个好东西

    #include<bits/stdc++.h>
    #define de(x) cout<<#x<<"="<<x<<endl;
    #define dd(x) cout<<#x<<"="<<x<<" ";
    #define rep(i,a,b) for(int i=a;i<(b);++i)
    #define repd(i,a,b) for(int i=a;i>=(b);--i)
    #define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
    #define ll long long
    #define mt(a,b) memset(a,b,sizeof(a))
    #define fi first
    #define se second
    #define inf 0x3f3f3f3f
    #define INF 0x3f3f3f3f3f3f3f3f
    #define pii pair<int,int>
    #define pdd pair<double,double>
    #define pdi pair<double,int>
    #define mp(u,v) make_pair(u,v)
    #define sz(a) (int)a.size()
    #define ull unsigned long long
    #define ll long long
    #define pb push_back
    #define PI acos(-1.0)
    #define qc std::ios::sync_with_stdio(false)
    #define db double
    #define all(a) a.begin(),a.end()
    const int mod = 1e9+7;
    const int maxn = 1e4+6;
    const double eps = 1e-6;
    using namespace std;
    bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
    bool ls(const db &a, const db &b) { return a + eps < b; }
    bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
    ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
    ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
    ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
    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*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //inv[1]=1;
    //for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
    int in[maxn];
    int main(){
        int n,m;
        int u,v;
        cin>>n>>m;
        rep(i,0,m){
            scanf("%d%d",&u,&v);
            in[u]++,in[v]++;
        }
        int ans = 0;
        rep(i,1,n+1) ans += in[i] * in[i];
        printf("%d
    ",ans);
        return 0;
    }
    View Code

     SGU 302

    题意:给你up和down就是up区间里变大写,down变小写

    收获:栈

    #include<bits/stdc++.h>
    #define de(x) cout<<#x<<"="<<x<<endl;
    #define dd(x) cout<<#x<<"="<<x<<" ";
    #define rep(i,a,b) for(int i=a;i<(b);++i)
    #define repd(i,a,b) for(int i=a;i>=(b);--i)
    #define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
    #define ll long long
    #define mt(a,b) memset(a,b,sizeof(a))
    #define fi first
    #define se second
    #define inf 0x3f3f3f3f
    #define INF 0x3f3f3f3f3f3f3f3f
    #define pii pair<int,int>
    #define pdd pair<double,double>
    #define pdi pair<double,int>
    #define mp(u,v) make_pair(u,v)
    #define sz(a) (int)a.size()
    #define ull unsigned long long
    #define ll long long
    #define pb push_back
    #define PI acos(-1.0)
    #define qc std::ios::sync_with_stdio(false)
    #define db double
    #define all(a) a.begin(),a.end()
    const int mod = 1e9+7;
    const int maxn = 1e3+6;
    const double eps = 1e-6;
    using namespace std;
    bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
    bool ls(const db &a, const db &b) { return a + eps < b; }
    bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
    ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
    ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
    ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
    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*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //inv[1]=1;
    //for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
    char s[maxn];
    int st[maxn],r=0;
    char up(char c){
        if(c>='A'&&c<='Z') return c;
        return c - 'a' + 'A';
    }
    char down(char c){
        if(c>='a'&&c<='z') return c;
        return c - 'A' + 'a';
    }
    int main(){
        scanf("%s",s+1);
        int len = strlen(s+1);
        rep(i,1,len+1){
            if(s[i]=='<'){
                if(s[i+1]=='/') {
                    r--;
                    if(s[i+2]=='D') i += 5;
                    else i += 3;
                }else if(s[i+1]=='D'){
                    i += 4;
                    st[++r] = 2;
                }else {
                    i += 2;
                    st[++r] = 1;
                }
                i++;
                continue;
            }
            if(!r){
                printf("%c",s[i]);
            }else if(st[r]==2){
                printf("%c",down(s[i]));
            }else {
                printf("%c",up(s[i]));
            }
        }
        return 0;
    }
    View Code
  • 相关阅读:
    [Oracle]跨越 DBLINK 访问表时,数据缓存在何处的Data Buffer 中?
    [Oracle]查看数据是否被移入 DataBuffer 的方法
    [Oracle]如何为数据库设置Event(eg: ORA-00235)
    [Oracle][Corruption]究竟哪些检查影响到 V$DATABASE_BLOCK_CORRUPTION
    [Oracle]OpenVMS 运行 Oracle 时的推荐值
    [Oracle]System 表空间的文件丢失
    [Oracle]如果误删了某个数据文件,又没有被备份,能否恢复?
    OFS环境,删除Resource 时出现错误失败,应该如何继续
    基于酷Q的工作秘书机器人
    C++编写简单的俄罗斯方块游戏
  • 原文地址:https://www.cnblogs.com/chinacwj/p/9030061.html
Copyright © 2020-2023  润新知