codeforces B.Fixed Points
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的更多相关文章
- 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了,先把符合的扫出来,然后再想,最多只能交换一次,也就是说最多也就是加两个,然后一个的判,注意数 ...
- B. Fixed Points
B. Fixed Points time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- codeforces 19D D. Points 树套树
D. Points Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/19/problem/D De ...
- codeforces 577E E. Points on Plane(构造+分块)
题目链接: E. Points on Plane time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- cf B. Fixed Points
http://codeforces.com/contest/347/problem/B #include <cstdio> #include <cstring> #includ ...
- codeforces 19 D. Points(线段树+set二分)
题目链接:http://codeforces.com/contest/19/problem/D 题意:给出3种操作:1)添加点(x,y),2)删除点(x,y),3)查询离(x,y)最近的右上方的点. ...
- Codeforces C Match Points(二分贪心)
题目描述: Match Points time limit per test 2 seconds memory limit per test 256 mega bytes input standard ...
随机推荐
- 面试复习(C++)之直接选择排序
#include <iostream> using namespace std; void Selection(int *a,int len) { ;i<len;i++) { int ...
- R语言入门系列1--数学狗还是做数据好了
nanana,作为一个不合格的数学专业学生,脑袋不好使,又穷逼,只好学点儿实用的东西,希望能养活自己~~~ 不瞎哔哔,想做数据方面工作的时候在犹豫是学R还是学python,一点儿python基础都没有 ...
- qt 单文档程序关闭时在delete ui处出现segmentation fault
做了个显示图片的单文档程序. qt 单文档程序关闭时在delete ui处出现segmentation fault. 调试发现调用两次mainwindow析构函数. http://blog.csdn. ...
- CentOS 6.6编译安装Nginx1.6.2+MySQL5.6.21+PHP5.6.3
http://www.osyunwei.com/archives/8867.html 一.配置防火墙,开启80端口.3306端口 vi /etc/sysconfig/iptables #编辑防火墙配置 ...
- 64位计算机安装setuptool
Python Version 2.7 required, which was not found in the registry 新建注册表信息:HKEY_LOCAL_MACHINE\SOFTWARE ...
- hibernate 连接oracle数据库的配置 (参考)
<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE hibernate-configuration PUBLIC &qu ...
- 近期编程问题——epoll failed:bad file descriptor
出现问题:epoll_wait:Bad file descriptor 原因:IO时间的socket描述符在epoll_ctl处理前就关闭了. 解决方法:不要在epoll_ctl之前关闭socket描 ...
- shopex 小知识
产品链接: http://www.--/product-172.html 中间的数字代表 sdb_goods 表中 的 goods_id ... 表示数据库里的产品 id. 分类链接: http: ...
- GreenDao数据库框架的配置与增删改查
并非原创,原创地址http://blog.csdn.net/njweiyukun/article/details/51893092 配置-------------------------------- ...
- Spark MLlib 之 Basic Statistics
Spark MLlib提供了一些基本的统计学的算法,下面主要说明一下: 1.Summary statistics 对于RDD[Vector]类型,Spark MLlib提供了colStats的统计方法 ...