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;
    }
  • 相关阅读:
    目前服务器所需要的技能
    c++11 初始化列表 bind function 示例
    c++11 时间相关操作练习
    C++ Crypto++ RSA加密资料收集
    多线程查找大量数据加锁的速度降低
    c++沉思录 学习笔记 第六章 句柄(引用计数指针雏形?)
    c++沉思录 学习笔记 第五章 代理类
    boost asio 一个聊天的基本框架
    c++11 并发 条件变量 超时等待的代码练习
    centos 6.5 hadoop 2.3 初配置
  • 原文地址:https://www.cnblogs.com/shenben/p/6417407.html
Copyright © 2011-2022 走看看