浙江省赛C What Kind of Friends Are You?(MAP)

题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3960

题意:对01矩阵中第i行j个数 1表示第j个问题中的名字和c个已知名字取交集

    0表示已知名字去除第j个问题中的名字

    问对于矩阵中i行 是否存在q个问题中的名字和c个已知名字的元素个数为1的交集

    若有输出该名字 否则输出Let‘s go to the library!!

思路:将第i个问题中的Yes数值化为1<<i(压位 相当于转化为二进制数后左移i位) 这样可以保证c中名字有唯一对应值

    要让名字和值对应需要用到 STL中的map<string,int>

代码:

#include<bits/stdc++.h>
using namespace std;

int main(){
    string s,s0;
    int t,n,q,c,m,a;
    map<string,int> mp;
    map<string,int>::iterator it;

    cin>>t;
    while(t--){
        mp.clear();
        cin>>n>>q;
        cin>>c;
        for(int i=0;i<c;i++){
            cin>>s0;
            mp[s0]=0;//需初始化 否则会WA
        }
        for(int i=0;i<q;i++){
            cin>>m;
            for(int j=0;j<m;j++){
                cin>>s;
                mp[s]+=1<<i;
            }
        }
        for(int i=0;i<n;i++){
            int sum=0;
            for(int j=0;j<q;j++){
                cin>>a;
                if(a==1)
                    sum+=1<<j;
            }
            int cnt=0;
            string name;

            for(it=mp.begin();it!=mp.end();it++){//遍历图 是否存在唯一对应值
                if(it->second==sum){
                    name=it->first;
                    cnt++;
                }
            }
            if(cnt==1)
                cout<<name<<endl;
            else
                cout<<"Let‘s go to the library!!"<<endl;
        }
    }
    return 0;
}

    

    

时间: 2024-08-25 18:26:26

浙江省赛C What Kind of Friends Are You?(MAP)的相关文章

2017浙江省赛 D - Let&#39;s Chat ZOJ - 3961

地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3961 题目: ACM (ACMers' Chatting Messenger) is a famous instant messaging software developed by Marjar Technology Company. To attract more users, Edward, the boss of Marjar Company, has re

第14届浙江省赛--Let&#39;s Chat

Let's Chat Time Limit: 1 Second      Memory Limit: 65536 KB ACM (ACMers' Chatting Messenger) is a famous instant messaging software developed by Marjar Technology Company. To attract more users, Edward, the boss of Marjar Company, has recently added

2017年浙江省赛总结

最终是5题银.其实感觉再给点时间能7题的,主要是最后机子不够用了,没时间调试了,当然代码能力弱也是很大的一个问题. E题,队友当时卡了很久,最终是A了.赛后发现就是一个很水的数位DP..代码如下: 1 #include <stdio.h> 2 #include <algorithm> 3 #include <string.h> 4 using namespace std; 5 typedef long long ll; 6 7 int T,n; 8 char s[15]

ZOJ 3879 Capture the Flag 15年浙江省赛K题

每年省赛必有的一道模拟题,描述都是非常的长,题目都是蛮好写的... sigh... 比赛的时候没有写出这道题目 :( 题意:首先输入4个数,n,q,p,c代表有n个队伍,q个服务器,每支队伍的初始分数p, 还有c次操作对于每次操作,首先输入一个k,代表k次攻击每次攻击有三个数,a,b,c, 代表a通过c服务器成功的攻击了b对于每次成功的攻击,b会失去n-1分, 这n-1分会平分给通过同一服务器攻击b的几支队伍然后是q行,每行n个数, 分别代表1~n是否成功维护了,1为成功,0为不成功不成功的队伍

2019省赛训练组队赛4.9周二 2017浙江省赛

A - Cooking Competition "Miss Kobayashi's Dragon Maid" is a Japanese manga series written and illustrated by Coolkyoushinja. An anime television series produced by Kyoto Animation aired in Japan between January and April 2017. In episode 8, two

2017浙江省赛 E - Seven Segment Display ZOJ - 3962

地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3962 题目: A seven segment display, or seven segment indicator, is a form of electronic display device for displaying decimal numerals that is an alternative to the more complex dot matrix

2017浙江省赛 H - Binary Tree Restoring ZOJ - 3965

地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3965 题目: iven two depth-first-search (DFS) sequences of a binary tree, can you find a binary tree which satisfies both of the DFS sequences? Recall that a binary tree is a tree in which

2017浙江省赛 C - What Kind of Friends Are You? ZOJ - 3960

地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3960 题目: Japari Park is a large zoo home to extant species, endangered species, extinct species, cryptids and some legendary creatures. Due to a mysterious substance known as Sandstar, a

2014浙江省赛

ZOJ 3777 Problem Arrangement 状态压缩DP,种数DP,dp[s][m]代表当前被占位置的集合分数为m的方案数,父母是总数n!,记忆化搜索好写 by fd ZOJ 3785 What day is that day? 等比数列,逆元,快速幂,当然可以暴力找循环节,有mod肯定有循环节,因为x^y%7 等价于(x%7)^y,所以可以分成6个第比数列,如下 1^1,2^2,3^3,4^4,5^5,6^6,0^7 1^8,2^9,3^10,4^11,5^12,6^13,0,^