cf B. Fixed Points
http://codeforces.com/contest/347/problem/B
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; int n;
int a[];
int id[];
int main()
{
while(scanf("%d",&n)!=EOF)
{
int cnt=;
for(int i=; i<n; i++)
{
scanf("%d",&a[i]);
id[i]=a[i];
if(a[i]==i)
{
id[i]=-;
cnt++;
}
}
bool flag=false;
bool flag1=false;
for(int i=; i<n; i++)
{
if(id[id[i]]==i&&id[i]!=-)
{
flag=true;
cnt+=;
break;
}
else if(id[i]!=i&&id[i]!=-)
{
flag1=true;
}
}
if(!flag&&flag1) cnt+=;
printf("%d\n",cnt);
}
return ;
}
cf B. Fixed Points的更多相关文章
- B. Fixed Points
B. Fixed Points time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- CF 1405E Fixed Point Removal【线段树上二分】
CF 1405E Fixed Point Removal[线段树上二分] 题意: 给定长度为\(n\)的序列\(A\),每次操作可以把\(A_i = i\)(即值等于其下标)的数删掉,然后剩下的数组 ...
- codeforces B.Fixed Points
link:http://codeforces.com/contest/347/problem/B 很简单,最多只能交换一次,也就是说,最多会增加两个.可能会增加一个.也可能一个也不增加(此时都是fix ...
- codeforces B. Fixed Points 解题报告
题目链接:http://codeforces.com/problemset/problem/347/B 题目意思:给出一个包含n个数的排列a,在排列a中最多只能作一次交换,使得ai = i 这样的匹配 ...
- [Codeforces] 347B - Fixed Points
题意:给定一个序列,现有一种操作:两个数的位置互换.问最多操作一次.序列 [元素位置i] 与 [元素Ai] 相等的最多个数? 依据题意,最多个数为 : [操作之前[元素位置i] 与 [元素Ai] ...
- CodeForces 347B Fixed Points (水题)
题意:给定 n 数,让你交换最多1次,求满足 ai = i的元素个数. 析:很简单么,只要暴力一遍就OK了,先把符合的扫出来,然后再想,最多只能交换一次,也就是说最多也就是加两个,然后一个的判,注意数 ...
- (简单) CF 44D Hyperdrive,数学。
In a far away galaxy there are n inhabited planets, numbered with numbers from 1 to n. They are loca ...
- 不动点(Fixed Point)
本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/51735818 在数学中,函数的不动点( ...
- codefroces Round #201.B--Fixed Points
B. Fixed Points time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
随机推荐
- LeetCode_Text Justification
Given an array of words and a length L, format the text such that each line has exactly L characters ...
- Java Json开源解析包 google-gson download(下载)
官方下载地址:http://code.google.com/p/google-gson/ http://files.cnblogs.com/hnrainll/google-gson-2.1-relea ...
- ios论坛
http://developer.cocoachina.com/ 讨论区:http://www.cocoachina.com/bbs/ http://bbs.9ria.com/forum-58-1.h ...
- bzoj2325 [ZJOI2011]道馆之战
Description 口袋妖怪(又名神奇宝贝或宠物小精灵)红/蓝/绿宝石中的水系道馆需要经过三个冰地才能到达馆主的面前,冰地中的每一个冰块都只能经过一次.当一个冰地上的所有冰块都被经过之后,到下一个 ...
- 除了修改WEBCONFIG会导致WEB服务重启外,还有其他的什么操作会导致重启?
1.修改WEBCONFIG文件 2.BIN文件夹下,添加.删除.覆盖文件 3.IIS应用程序池回收 参考文章:http://blog.csdn.net/hb_gx/archive/2007/05/ ...
- usaco6.1-Cow XOR:trie树
Cow XOR Adrian Vladu -- 2005 Farmer John is stuck with another problem while feeding his cows. All o ...
- 一个session已经ACTIVE20多小时,等待事件SQL*Net more data from client
问题描述: 一个session已经ACTIVE20多小时,等待事件SQL*Net more data from client 有一人session,从昨天上午11点多登陆(v$session.logi ...
- MySQL数据库 常用操作
1:使用SHOW语句找出在服务器上当前存在什么数据库: mysql> SHOW DATABASES; 2:创建一个数据库MYSQLDATA mysql> CREATE DATABASE M ...
- Annotation(三)——Spring注解开发
Spring框架的核心功能IoC(Inversion of Control),也就是通过Spring容器进行对象的管理,以及对象之间组合关系的映射.通常情况下我们会在xml配置文件中进行action, ...
- shell脚本一条命令直接发送http请求(xjl456852原创)
我们知道nc命令是一个网络工具.可以连接tcp/udp.也能模拟发送http请求. 现在介绍通过shell脚本,一条命令直接发送http请求. 命令如下,可以对下面的地址等信息自行修改: #!/bin ...