ZOJ 3960 What Kind of Friends Are You? 题解
来源:互联网 发布:win7系统摄像头软件 编辑:程序博客网 时间:2024/06/06 10:41
题意
一个人有n个朋友,但她现在只知道这n个朋友在一群人中却无法分辨出谁是谁,她通过问一些只有是或否的问题收集每个人的答案与她朋友应答的答案做对比,如果一样那这个人就是她的这个朋友
思路
首先把每个人的名字通过map hash成int,然后根据每个问题回答是的人去更新map的值,由于问题最多只有20个,我们就可以使用二进制表示这个人对每个问题的答案,进行对比时只需比较两个int就可以了
代码
#include <iostream>#include <cstdio>#include <string>#include <map>using namespace std;string name[201];map<string,int> mp;int ans[201];int main(){ int T,n,q,c,m,f,tt; string s; int temp,x; cin>>T; while(T--) { cin>>n>>q; cin>>c; for(int i=1;i<=c;i++) { cin>>name[i]; mp[name[i]]=i; } for(int i=0;i<q;i++) { for(int j=1;j<=c;j++) ans[j]<<=1; cin>>m; for(int j=0;j<m;j++) { cin>>s; ans[mp[s]]++; } } for(int i=0;i<n;i++) { temp=0; f=0; for(int i=0;i<q;i++) { temp<<=1; cin>>x; temp+=x; } for(int i=1;i<=c;i++) if(ans[i]==temp) { tt=i; f++; } if(f!=1) printf("Let's go to the library!!\n"); else cout<<name[tt]<<"\n"; } for(int i=1;i<=c;i++) ans[i]=0; mp.clear(); } return 0;}
0 0
- ZOJ 3960 What Kind of Friends Are You? 题解
- zoj 3960 What Kind of Friends Are You?
- ZOJ 3960 What Kind of Friends Are You?(哈希)
- zoj 3960 What Kind of Friends Are You?
- ZOJ 3960 What Kind of Friends Are You?【】
- ZOJ 3960What Kind of Friends Are You?
- What Kind of Friends Are You?
- What Kind of Friends Are You?
- What Kind of Friends Are You?
- ZOJ3960-What Kind of Friends Are You?
- What Kind of Friends Are You?
- zoj 3960 What Kind of Friends Are You?(map+哈希)
- ZOJ 3960 What Kind of Friends Are You?(STL map,状态压缩)
- 浙江省赛 C What Kind of Friends Are You?
- 浙江省赛C题 What Kind of Friends Are You?
- What Kind of Friends Are You?(字符串匹配)
- 2017 浙江省赛 C What Kind of Friends Are You + D Let's Chat
- 17年浙江省省赛C-What Kind of Friends Are You?
- Apriltag源码C版本编译以及运行
- python画词云图
- 二级指针作为函数输入的三种实现方式:
- JFileChooser实现对选定文件夹内图片自动播放
- IOS开发中制作属于自己的静态库.a、资源库.bundle、.framework
- ZOJ 3960 What Kind of Friends Are You? 题解
- 堆和栈的概念和区别
- RxAndroid使用解析以及使用场景分析
- IO流
- Leetcode——134 Gas Station
- Error configuring application listener of class com.sun.faces.config.ConfigureListener
- python学习笔记
- 论文学习笔记:《Rich feature hierarchies foe accurate object detection and semantic segmentation》
- Universal Links踩坑