zoukankan      html  css  js  c++  java
  • SDOI2012 Round1 day2 集合(set)解题报告

     

    //=====================以上为官方题解==============//

    数据略水,暴力枚举50.

    把边按照升序排一遍,在询问,水过。

    #include<cstdio>
    #include<algorithm>
    #define setfire(name) freopen(#name".in","r",stdin);freopen(#name".out","w",stdout);
    using namespace std;
    const int N=100000+5;
    struct M{
        int u,v,w;
    }e[N*5];
    int n,m,ans,cas,belong[N];
    bool cmp(const M &a,const M &b){
        return a.w<b.w;
    }
    int main(){
        setfire(set);
        scanf("%d%d",&n,&m);
        for(int i=1;i<=m;i++) scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].w);
        sort(e+1,e+m+1,cmp);
        for(int i=1;i<=n;i++) belong[i]=1;
        scanf("%d",&cas);char s[10];
        for(int i=1,x;i<=cas;i++){
            scanf("%s",s);
            if(s[0]=='M'){
                scanf("%d",&x);
                if(s[4]=='A'){
                    belong[x]=1;
                }
                else if(s[4]=='B'){
                    belong[x]=2;
                }
                else if(s[4]=='C'){
                    belong[x]=3;
                }
            }
            else{
                ans=0x3f3f3f3f;
                if(s[3]=='A'&&s[4]=='A'){
                    for(int i=1;i<=m;i++){
                        if(belong[e[i].u]==1&&belong[e[i].v]==1){
                            ans=e[i].w;
                            break;
                        }
                    }
                }
                else if(s[3]=='A'&&s[4]=='B'){
                    for(int i=1;i<=m;i++){
                        if(belong[e[i].u]==1&&belong[e[i].v]==2
                          ||belong[e[i].u]==2&&belong[e[i].v]==1){
                            ans=e[i].w;
                            break;
                        }
                    }
                }
                else if(s[3]=='A'&&s[4]=='C'){
                    for(int i=1;i<=m;i++){
                        if(belong[e[i].u]==1&&belong[e[i].v]==3
                          ||belong[e[i].u]==3&&belong[e[i].v]==1){
                            ans=e[i].w;
                            break;
                        }
                    }
                }
                else if(s[3]=='B'&&s[4]=='B'){
                    for(int i=1;i<=m;i++){
                        if(belong[e[i].u]==2&&belong[e[i].v]==2){
                            ans=e[i].w;
                            break;
                        }
                    }
                }
                else if(s[3]=='B'&&s[4]=='C'){
                    for(int i=1;i<=m;i++){
                        if(belong[e[i].u]==2&&belong[e[i].v]==3
                          ||belong[e[i].u]==3&&belong[e[i].v]==2){
                            ans=e[i].w;
                            break;
                        }
                    }
                }
                else if(s[3]=='C'&&s[4]=='C'){
                    for(int i=1;i<=m;i++){
                        if(belong[e[i].u]==3&&belong[e[i].v]==3){
                            ans=e[i].w;
                            break;
                        }
                    }
                }
                if(ans==0x3f3f3f3f) puts("No Found!");
                else printf("%d
    ",ans);
            }
        }
        return 0;
    }
  • 相关阅读:
    perl 安装Net::ZooKeeper
    严重: WSSERVLET11: failed to parse runtime descriptor: The serviceName cannot be retrieved from an int
    最新版FusionCharts2D面积图
    select自定义属性值
    thinkphp 常用的查询
    ThinkPHP 3.1.2 模板中的基本语法
    perl post 带上请求头
    商业智能让营销更精确
    su: cannot set user id: Resource temporarily unavailable
    java.security.KeyException
  • 原文地址:https://www.cnblogs.com/shenben/p/6417407.html
Copyright © 2011-2022 走看看