link:http://codeforces.com/contest/347/problem/B

很简单,最多只能交换一次,也就是说,最多会增加两个。可能会增加一个。也可能一个也不增加(此时都是fixed point)

 #include <cstdio>
 using namespace std;
 ];
 int main(void)
 {
 #ifndef ONLINE_JUDGE
     freopen("in.txt", "r", stdin);
 #endif
     int n;
     while (~scanf("%d", &n))
     {
         ;
         ; i < n; scanf("%d", a+i++));
         bool flag = false;
         ; i < n; ++i)
         {
             if (a[i] == i) cnt++;
             else if (!flag && a[a[i] ] == i)
             {
                 cnt += ;
                 flag = true;
             }
         }
         if (!flag && cnt != n)
             cnt++;
         printf("%d\n", cnt);
     }
     ;
 }

还是WA了一次。逻辑关系没搞清楚。尤其是if和else if

codeforces B.Fixed Points的更多相关文章

  1. codeforces B. Fixed Points 解题报告

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

  2. [Codeforces] 347B - Fixed Points

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

  3. CodeForces 347B Fixed Points (水题)

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

  4. B. Fixed Points

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

  5. codeforces 19D D. Points 树套树

    D. Points Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/19/problem/D De ...

  6. codeforces 577E E. Points on Plane(构造+分块)

    题目链接: E. Points on Plane time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  7. cf B. Fixed Points

    http://codeforces.com/contest/347/problem/B #include <cstdio> #include <cstring> #includ ...

  8. codeforces 19 D. Points(线段树+set二分)

    题目链接:http://codeforces.com/contest/19/problem/D 题意:给出3种操作:1)添加点(x,y),2)删除点(x,y),3)查询离(x,y)最近的右上方的点. ...

  9. Codeforces C Match Points(二分贪心)

    题目描述: Match Points time limit per test 2 seconds memory limit per test 256 mega bytes input standard ...

随机推荐

  1. windows8.1下常用编辑器安装配置(emacs/vim/sublime text3)

    一.下载:在emacs:http://mirrors.ustc.edu.cn/gnu/emacs/windows/里下载emacs-24.3-bin-i386.zip.解压到自定目录,双击bin文件夹 ...

  2. Oracle数据库如何创建DATABASE LINK?

    Oracle数据库如何创建DATABASE LINK? 2011-08-09 14:54 taowei20061122 CSDN博客  http://blog.csdn.net/taowei20061 ...

  3. [转]Java反射之如何判断类或变量、方法的修饰符(Modifier解析)

    Java针对类.成员变量.方法,有很多修饰符,例如public.private.static.final.synchronized.abstract等,这些修饰符用来控制访问权限或其他特性. 本文就用 ...

  4. io端口与io内存详解

    (一)地址的概念 1)物理地址:CPU地址总线传来的地址,由硬件电路控制其具体含义.物理地址中很大一部分是留给内存条中的内存的,但也常被映射到其他存储器上(如显存.BIOS等).在程序指令中的虚拟地址 ...

  5. java.lang.Boolean->介绍

    介绍: public class Boolean extends Object implements Serializable, Comparable<Boolean> Boolean类是 ...

  6. 例子:Database - Linq to sql

    DataContext类型(数据上下文)是System.Data.Linq命名空间下的重要类型,用于把查询句法翻译成SQL语句,以及把数据从数据库返回给调用方和把实体的修改写入数据库. DataCon ...

  7. Devexpress DateEdit控件的值不反馈到数据源的处理方式。

    如果在GridControl中要把编辑的值反馈到数据源,可以用Gridview1.PostEdit()方法. 可是在datalayout中使用就会遇到一些问题:比如说DateEdit控件,在保存数据的 ...

  8. 2.4G/5G频段WLAN各国使用信道表

    List of WLAN channels (维基百科):https://en.wikipedia.org/wiki/List_of_WLAN_channels 2.4G 5G 另附美国5G允许使用的 ...

  9. WC项目要求

    #include "stdio.h" #include "string.h" #include "stdlib.h" int charcal ...

  10. 基于Jenkins + Git的PHP项目编译脚本

    本文针对的是了解或已经在使用Jenkins和Git的开发者或团队. 本团队使用了Jenkins作为持续集成平台,Git作为版本管理工具,而本人负责的项目是PHP项目,所谓发布项目就是复制文件. 通常有 ...