1742. Team building

博客围绕团队组建展开,若有未分配到开发团队的程序员,选其一标记为当前程序员,创建新团队并分配给他。若当前程序员认为某同事优秀且该同事未分配,将其加入同一团队并重复操作,否则团队组建完成,继续处理其他未分配程序员。

1742. Team building

Time limit: 1.0 second Memory limit: 64 MB
There are n programmers in the software development company. Each of them thinks that he is the greatest or the second greatest programmer in the company. In the latter case he can name the greatest programmer in his opinion.
The administration decided to divide all programmers into development teams using the following algorithm:
  1. If there are programmers, who are not assigned to a development team, choose any of them and mark him as current one.
  2. Create a new development team and assign it to the current programmer.
  3. If the current programmer thinks that one of his colleagues is the greatest programmer and this colleague is not assigned to a development team, then this colleague is assigned to the same development team and is marked as current programmer. Then the step 3 is repeated. Otherwise, the team is formed, and the administration returns to the step 1.
What is the minimal and maximal number of teams which can be formed in this company according to the algorithm?

Input

The first line contains an integer n (1 ≤ n ≤ 105). The i-th of the following n lines contains the number of the programmer, who is the greatest, according to thei-th programmer's opinion.

Output

Output the minimal and maximal number of development teams, separated with space.

Sample

inputoutput
4
2
3
4
2
1 2
Problem Author: Artyom Ripatti Problem Source: Ufa SATU Contest. Petrozavodsk Summer Session, August 2009
***************************************************************************************
手动找环(因为每个节点的出度都唯一),先找出入度为0的点搜索,如果发现pre==vis[next[pre0]],则找出了一个强连通分量,ans++;
***************************************************************************************
 1 #include<iostream>
 2 #include<cstring>
 3 #include<string>
 4 #include<cstdio>
 5 #include<cmath>
 6 using namespace std;
 7 int in[100010];
 8 int next[100010];
 9 int n,i,j,k;
10 int vis[100010];
11 int cnt[100010];
12 int a[100010];
13 int getnum(int pre)
14  {
15      int gs=pre;
16      int tot=0;
17      while(vis[pre]<=0)
18       {
19           vis[pre]=gs;
20            cnt[pre]=tot++;
21           if(vis[next[pre]]>0)
22            {
23                if(vis[next[pre]]==gs)//找环返回
24                 return  cnt[next[pre]];
25                else
26                  return tot-1;
27            }
28           pre=next[pre];
29       }
30  }
31 int main()
32 {
33     cin>>n;
34     memset(in,0,sizeof(in));
35     for(i=1;i<=n;i++)
36      {
37          cin>>next[i];
38          in[next[i]]++;
39      }
40      int  len=0;
41      for(i=1;i<=n;i++)
42       {
43           if(in[i]==0)
44             a[++len]=i;
45       }
46      int ans1=0;
47      int ans2=0;
48     memset(vis,0,sizeof(vis));
49     for(i=1;i<=len;i++)
50      {
51          ans1++;
52          ans2+=getnum(a[i])+1;
53      }
54     for(i=1;i<=n;i++)//再扫一遍,防止漏掉
55      {
56          if(vis[i]<=0)
57           {
58               ans1++;
59               ans2+=getnum(i)+1;
60           }
61      }
62      cout<<ans1<<' '<<ans2<<endl;
63      return 0;
64 
65 }
View Code

 

转载于:https://www.cnblogs.com/sdau--codeants/p/3252303.html

乐播投屏是一款简单好用、功能强大的专业投屏软件,支持手机投屏电视、手机投电脑、电脑投电视等多种投屏方式。 多端兼容与跨网投屏:支持手机、平板、电脑等多种设备之间的自由组合投屏,且无需连接 WiFi,通过跨屏技术打破网络限制,扫一扫即可投屏。 广泛的应用支持:支持 10000+APP 投屏,包括综合视频、网盘与浏览器、美韩剧、斗鱼、虎牙等直播平台,还能将央视、湖南卫视等各大卫视的直播内容一键投屏。 高清流畅投屏体验:腾讯独家智能音画调校技术,支持 4K 高清画质、240Hz 超高帧率,低延迟不卡顿,能为用户提供更高清、流畅的视觉享受。 会议办公功能强大:拥有全球唯一的 “超级投屏空间”,扫码即投,无需安装。支持多人共享投屏、远程协作批注,PPT、Excel、视频等文件都能流畅展示,还具备企业级安全加密,保障会议资料不泄露。 多人互动功能:支持多人投屏,邀请好友加入投屏互动,远程也可加入。同时具备一屏多显、语音互动功能,支持多人连麦,实时语音交流。 文件支持全面:支持 PPT、PDF、Word、Excel 等办公文件,以及视频、图片等多种类型文件的投屏,还支持网盘直投,无需下载和转格式。 特色功能丰富:投屏时可同步录制投屏画面,部分版本还支持通过触控屏或电视端外接鼠标反控电脑,以及在投屏过程中用画笔实时标注等功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值