CodeForces 658B Bear and Displayed Friends(好友在线查询)
来源:互联网 发布:视频点播软件哪个好 编辑:程序博客网 时间:2024/05/25 21:34
http://codeforces.com/problemset/problem/658/B
题意:
给定一些数据,查询朋友当前是否能够联系的上,并且输出结果。
操作有:
操作1 好友Id: 好友上线;
操作 2 好友Id :查询能否联系的上。
键入数据提示:
朋友数量 n ,可以显示的朋友数量(亲密度优先显示)k,操作的次数 q;
第一个朋友的亲密度............第 n 个朋友的亲密度。
思路:
引入一个 onl[ ] 数组,用来记录已经在线好友的亲密度(没有两个好友是一样的),用于查询 k 范围内在线好友的亲密度即可。
具体看下代码吧。
AC Code:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int MYDD = 1103+1.5e5;int fri[MYDD];//friendsint onl[16];//online 注意:1≤k≤min(6,n)bool cmp(int x,int y) {return x>y;}int main() {int n,k,q;while(scanf("%d%d%d",&n,&k,&q)!=EOF) {for(int j=1; j<=n; j++) {scanf("%d",&fri[j]);}memset(onl,0,sizeof(onl));while(q--) {int oper,id;//opertation scanf("%d%d",&oper,&id);if(oper==1) {onl[k]=fri[id];//当前在线的赋值给 onl[]数组sort(onl,onl+1+k,cmp);//注意排序空间 *wa_bug sort(onl+1,onl+1+k,cmp);}if(oper==2) {bool flag=false;//遍历在线的好友for(int j=0; j<k; j++) {//存在该亲密度的好友if(onl[j]==fri[id]) flag=true;}if(flag)puts("YES");elseputs("NO");}}}return 0;}
***********************
0 0
- CodeForces 658B Bear and Displayed Friends(好友在线查询)
- codeforces 658B-Bear and Displayed Friends
- CodeForces 658B Bear and Displayed Friends(树状数组)
- Codeforces 658B Bear and Displayed Friends【set】
- Codeforces 639A Bear and Displayed Friends (优先队列)
- CodeForces 639 A.Bear and Displayed Friends(水~)
- A. Bear and Displayed Friends
- Codeforces 639A Bear and Displayed Friends 【STL】
- VK Cup 2016 - Round 1 (Div. 2 Edition)-B - Bear and Displayed Friends-STL(维护前k大)
- VK Cup 2016 - Round 1 (Div. 2 Edition) B B. Bear and Displayed Friends 优先队列
- 【VK Cup 2016 - Round 1 (Div 2 Edition)B】【水题】Bear and Displayed Friends 即时维护最大6个数
- 【CODEFORCES】 B. Friends and Presents
- Codeforces 385B Bear and Strings(字符串)
- CodeForces 639B Bear and Forgotten Tree 3(水题)
- [CodeForces 573B] Bear and Blocks (脑洞题)
- CodeForces 680B Bear and Finding Criminals(捉小偷)
- CodeForces 639 B.Bear and Forgotten Tree 3(构造)
- CodeForces 643 B.Bear and Two Paths(构造)
- hibernate的一个分页的写法
- Swift-->UIAlertController(对话框)的使用
- 搞不清FastCgi与PHP-fpm之间是个什么样的关系
- UML学习(二)-----类图
- Iterator详解
- CodeForces 658B Bear and Displayed Friends(好友在线查询)
- UGUI中使用位图艺术字(使用BMfont的两种方式)
- 搭建自己专属的vpn——选择一个vps
- 【杭电oj2015】偶数求和
- PHP代码打包---phar
- js模仿 Map集合
- UML学习(三)-----序列图
- 【杭电oj2019】数列有序!
- 关于记忆的10个惊人事实