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的更多相关文章

  1. B. Fixed Points

    B. Fixed Points time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  2. CF 1405E Fixed Point Removal【线段树上二分】

    CF 1405E Fixed Point Removal[线段树上二分]  题意: 给定长度为\(n\)的序列\(A\),每次操作可以把\(A_i = i\)(即值等于其下标)的数删掉,然后剩下的数组 ...

  3. codeforces B.Fixed Points

    link:http://codeforces.com/contest/347/problem/B 很简单,最多只能交换一次,也就是说,最多会增加两个.可能会增加一个.也可能一个也不增加(此时都是fix ...

  4. codeforces B. Fixed Points 解题报告

    题目链接:http://codeforces.com/problemset/problem/347/B 题目意思:给出一个包含n个数的排列a,在排列a中最多只能作一次交换,使得ai = i 这样的匹配 ...

  5. [Codeforces] 347B - Fixed Points

    题意:给定一个序列,现有一种操作:两个数的位置互换.问最多操作一次.序列 [元素位置i]  与 [元素Ai] 相等的最多个数? 依据题意,最多个数为 : [操作之前[元素位置i]  与 [元素Ai] ...

  6. CodeForces 347B Fixed Points (水题)

    题意:给定 n 数,让你交换最多1次,求满足 ai = i的元素个数. 析:很简单么,只要暴力一遍就OK了,先把符合的扫出来,然后再想,最多只能交换一次,也就是说最多也就是加两个,然后一个的判,注意数 ...

  7. (简单) CF 44D Hyperdrive,数学。

    In a far away galaxy there are n inhabited planets, numbered with numbers from 1 to n. They are loca ...

  8. 不动点(Fixed Point)

    本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/51735818 在数学中,函数的不动点( ...

  9. codefroces Round #201.B--Fixed Points

    B. Fixed Points time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

随机推荐

  1. poj 3792 Area of Polycubes

    http://poj.org/problem?id=3792 #include <cstdio> #include <cstring> #include <cmath&g ...

  2. hdu Fibonacci

    #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> u ...

  3. 使用Keil软件编写汇编源程序应注意事项

    1)一定要使用微软的txt文本编辑器,否则键入逗号时编译通不过.应该是这个样('),不该是这个样(,). 2) 用数字做标号时,前面一定要加一个英文字母,否则编译通不过. 3) 有时编译通过的.asm ...

  4. (1) 一个字符串,根据输入参数m,找出字符串的m个字符的所有字符串

    /** * 有一个字符串,根据输入参数m,找出字符串的m个字符的所有字符串 例如: String str ="abc", m=2 得到结果是 "ab" &quo ...

  5. syslog_test.c 简单的syslog函数

    #cat syslog_test.c #include<stdio.h> #include<stdlib.h> #include<syslog.h> int mai ...

  6. MySql 查询表字段数

    MySql 查询表字段数 SELECT COUNT(*) FROM information_schema.columns WHERE table_schema='test_cases' AND tab ...

  7. BootStrap学习之先导篇——响应式网页

    Bootstrap学习之前,要知道响应式网页的原理. 1.什么是响应式网页? 一个页面,可以根据浏览设备的不同,以及特性的不同,而自动改变布局.大小等.使得在不同的设备上上都可以呈现优秀的界面. 优点 ...

  8. C++类訪问控制及继承

    一.C++类的訪问控制有三类:public,protected和private. 类訪问控制符 类成员可被哪些对象訪问 public 1.类的成员函数.2.类对象.3.友元.4.子类成员函数 prot ...

  9. VCS仿真生成vpd文件(verilog)

    VCS仿真生成vpd文件(verilog) 一.环境与文件 Linux平台  csh环境 VCS 64bit 代码文件请参考<一个简单的Verilog计数器模型> 二.开始仿真 1.com ...

  10. CSS transform(变形)和transform-origin(变形原点)

    transform(变形)和transform-origin(变形原点)的说明: 目前这两个属性得到了除去ie以外各个主流浏览器webkit,firefox,opera的支持,属性名分别为 -webk ...