CodeForces - 1234B1 Social Network (easy version)

题目:

The only difference between easy and hard versions are constraints on n and k .
You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most k most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations equals 0).

Each conversation is between you and some of your friends. There is at most one conversation with any of your friends. So each conversation is uniquely defined by your friend.

You (suddenly!) have the ability to see the future. You know that during the day you will receive nn messages, the i-th message will be received from the friend with ID idi (1≤idi≤109).

If you receive a message from idi in the conversation which is currently displayed on the smartphone then nothing happens: the conversations of the screen do not change and do not change their order, you read the message and continue waiting for new messages.

Otherwise (i.e. if there is no conversation with idi on the screen):

Firstly, if the number of conversations displayed on the screen is k, the last conversation (which has the position k) is removed from the screen.
Now the number of conversations on the screen is guaranteed to be less than k and the conversation with the friend idiidi is not displayed on the screen.
The conversation with the friend idiidi appears on the first (the topmost) position on the screen and all the other displayed conversations are shifted one position down.

Your task is to find the list of conversations (in the order they are displayed on the screen) after processing all n messages.


Input

The first line of the input contains two integers n and k (1≤n,k≤200) — the number of messages and the number of conversations your smartphone can show.

The second line of the input contains nn integers id1 ,id2 ,…,idn (1≤idi ≤109), where idi is the ID of the friend which sends you the i-th message.


Output

In the first line of the output print one integer m (1≤m≤min(n,k)) — the number of conversations shown after receiving all n messages

In the second line print mm integers ids1,ids2,…,idsm, where idsi should be equal to the ID of the friend corresponding to the conversation displayed on the position i after receiving all n messages.


Sample Input

7 2
1 2 3 2 1 3 2

Sample Output

2
2 1

Sample Input

10 4
2 3 3 1 1 2 1 2 3 3

Sample Output

3
1 3 2

题目大意:
一共有n条信息,屏幕上只能显示k个好友的信息,如果该好友的信息已经在屏幕上则不发生任何变化,否则将最早的一条好友信息顶掉,新的好友信息进入屏幕。

题目分析:

对于简单版的 ,我们还是比较容易过的 , 我们只需要 设置两个数组分别 存放 屏幕上的 朋友的ID ,和 朋友来信的ID的顺序
用两个循环嵌套,暴力扫 存放屏幕上朋友 ID的数组 ,如果有 就不执行操作,如果没有 就每个向后移动,然后放在最前面,
对于简单版 是不会超时的,但是复杂版就 不可以暴力扫了,
复杂版请移步 : CodeForces - 1234B2 Social Network (hard version)

AC代码:

 #include <stdio.h>
int main()
{int n,k,i=0,j=0,x=0,c=0;scanf("%d%d",&n,&k);int id[n],l[k]={0};for(i=0;i<n;i++)scanf("%d",&id[i]);for (i=0;i<n;i++){for (;j<k;)if (l[j]!=id[i]){j++;x++;}elsej++;j=0;if(x==k)//x与k比较 是判断 屏幕上有没有 的条件,{for(j=k-1;j>0;j--)l[j]=l[j-1];l[0]=id[i];}x=0;             }for (j=0;j<k;j++)if(l[j]>0)c++;printf("%d\n",c);for (j=0;j<k;j++)if(l[j]>0)printf("%d ",l[j]);return 0;       }

我来要赞了,如果觉得解释还算详细,可以学到点什么的话,点个赞再走吧
欢迎各位路过的dalao 指点,提出问题。

CodeForces - 1234B1 Social Network (easy version)相关推荐

  1. Social Network (easy version)

    Social Network (easy version) CodeForces 1234B1 这是一道我曾经训练时做过的一道题,为了应对上面的要求指标我不得不把它掏了出来(doge),这道题还是有点 ...

  2. CodeForces - 1234B2 Social Network (hard version)

    CodeForces - 1234B2 Social Network (hard version) 题目: The only difference between easy and hard vers ...

  3. Codeforces Round #590 (Div. 3) B2. Social Network (hard version)

    题目链接 The only difference between easy and hard versions are constraints on n and k. You are messagin ...

  4. B2. Social Network (hard version)(STL)Codeforces Round #590 (Div. 3)

    原题链接:https://codeforces.com/contest/1234/problem/B2 你正在一个流行的社交网络中通过智能手机发送信息.你的智能手机最多可以显示k个最近与朋友的对话.最 ...

  5. CodeForces - 1118F1 Tree Cutting (Easy Version)(树形dp)

    题目链接:点击查看 题目大意:给定n个点,每个点的权值分别对应颜色:0:无颜色,1:红色,2:蓝色,现在需要切割边,使切割后的两个部分不能出现红色和蓝色掺杂的部分,也就是说两个部分必须只能各自含有一个 ...

  6. Codeforces C1. Prefix Flip (Easy Version) (二进制串 / 模拟 / 构造) (Roun #658 Div.2)

    传送门 题意: 给出两个长度为n的二进制串a和b,你每次可选取一段前缀子串取反并翻转(即:10010 -> 01101 -> 10110).已知在3 * n次操作内一定能将a变成b.先让你 ...

  7. Social Network(运用map容器)

    题目链接: Social Network (hard version) 题目: 你正在一个流行的社交网络中通过智能手机发送信息.你的智能手机最多可以显示k个最近与朋友的对话.最初,屏幕是空的(即显示的 ...

  8. CodeForces - 1543D1 RPD and Rap Sheet (Easy Version)(异或+交互)

    题目链接:点击查看 题目大意:交互题猜密码,设原密码为 xxx,猜的密码为 yyy,如果没猜到,密码会自适应变成 zzz,满足 x⊕z=yx \oplus z=yx⊕z=y ,最多猜 nnn 次 题目 ...

  9. Codeforces Round #579 (Div. 3) F1. Complete the Projects (easy version) 排序 + 贪心

    传送门 文章目录 题意: 思路: 题意: 思路: 比较直观的想法就是对于bi≥0b_i\ge0bi​≥0的项目,我们将aia_iai​从小到大排序,让后依次加bib_ibi​,如果有取不到的,显然就无 ...

最新文章

  1. 算法:详解布隆过滤器的原理、使用场景和注意事项@知乎.Young Chen
  2. P1996 约瑟夫问题
  3. 使用AspNetpagerGridView添加连续的序号
  4. Hadoop实战 -- IO
  5. windows server 中,Tomcat9 配置
  6. Fiori Elements - OData metadata response and annotation merge
  7. mysql简单分表_mysql分区分表哪个好
  8. [转]如何处理机器学习中的不平衡类别
  9. 吴恩达深度学习CNN作业:Convolutional Neural Networks: Application
  10. HTTP 1 1与HTTP 1 0的比较
  11. 软件开发基本流程概述
  12. Genius‘s Gambit(构造)
  13. 【Unity3D插件】Alembic插件分享《abc动画文件导入Unity》
  14. Android练手——分贝计
  15. 大白菜Ghost备份还原系统-人人都会重装系统
  16. Java 实现双向链表
  17. Java实现word导出与pdf导出
  18. 自动定时发送邮件的方法 —— 定时执行专家V6.8
  19. 第十一天 乐在其中-Android与远端之JDBC
  20. 剑指offer2.1

热门文章

  1. 在WPSOFFICE中一次性消除硬回车(转)
  2. 同一局域网中ping 通 Ubuntu 与 win10
  3. Dooker镜像详解,文件系统分层,本地镜像的发布 (阿里云和私有库)commit (安装vim ),详细演示
  4. 中央空调组空、风柜变频pid控制实例 含西门子1200plc程序(PID调节)
  5. 浅谈棋盘覆盖问题(算法思想及伪代码)
  6. matlab 制动仿真,基于MATLAB/Simulink的电动汽车再生制动仿真
  7. 如何获取招聘源?在投简历前获取更多招聘信息...
  8. 奔梦向前-代码实现桌球游戏网页版-2020-04-26
  9. Umbrella Project 2012安全工具合集—Hacktools Ultra
  10. 200G光模块有哪些?详解易飞扬200G QSFP-DD SR8光模块