Codeforces Round #201 (Div. 2) 347B Fixed Points(脑洞)

删除结点 对给定的单链表 L ,设计一个算法,删除 L 中值为 x 的结点的直接前驱结点。 1 由键盘输入值,换行表示输入结束,根据输入建立单链表。 2 输入链表中的一个元素值,从链表中删除这个元素的前驱结点。 3 对删除元素后的链表元素在屏幕上显示。 测试用例1 11 22 33 44 55 66 77↵ 44↵ 期待输出1 11 22 44 55 66 77↵ #include <iostre... 阅读详情

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

A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not.

A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points.

You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation.

Input

The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n integers a0, a1, ..., an - 1 — the given permutation.

Output

Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation.

Sample test(s)
input
5
0 1 3 4 2
output
3



问你交换两个数字后a[i] == i个数最多能有多少个。


读入数字时统计满足条件有多少个,然后判断,对应输出即可。


AC代码:


#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
using namespace std;
const int maxn = 100000 + 5;
int n;
int main(int argc, char const *argv[])
{
	while(scanf("%d", &n) != EOF) {
		int a[maxn], ans = 0;
		for(int i = 0; i < n; ++i) {
			scanf("%d", &a[i]);
			if(a[i] == i) ans++;
		}
		if(ans == n) {
			printf("%d\n", ans);
			continue;
		}
		if(ans == n - 2) {
			printf("%d\n", ans + 2);
			continue;
		}
		bool flag = false;
		for(int i = 0; i < n; ++i)
			if(a[i] != i && i == a[a[i]]) {
				flag = true;
				break;
			}
		if(flag) printf("%d\n", ans + 2);
		else printf("%d\n", ans + 1);
	}
	return 0;
}


RTKLIB中RTK定位原理(一) 1 模型 1.1 非差观测值 非差观测值与RTKLIB中PPP定位原理——观测模型部分中一致。 1.2 单间单差观测值 若两个接收机距离较近,经过站间单差,电离层对流层延迟可消除,卫星s的钟差以及初始相位被消除,中依然包含接收机初始相位。 1.3 站间星间双差观测值 经过站间星间双差,接收机钟差及初始相位被消除。 2 EKF参数估计 2.1 EKF法则 EKF法则与RTKLIB中PPP定位原理——观测模型部分中一致。 2.2 状态变量与时间更新 (1)状态变量 在RTK... 阅读详情

相关推荐

LM358实战:手把手教你搭建电流检测电路(附电阻选型计算)

本文详细解析了使用LM358运算放大器搭建电流检测电路的全过程,包括基础原理、采样电阻选型、放大电路设计及PCB布局技巧。通过实战案例和精确计算,帮助工程师快速掌握低成本、高精度的电流检测方案,适用于电源管理、电机控制等多种应用场景。

weixin_30872157的博客 448

CF818B-Permutation Game

B. Permutation Gametime limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output n children are standing in a circle and playing a game. Children’s number

algzjh的博客 1464

相控阵雷达仿真入门:TWS与TAS模式实战解析(附代码示例)

本文深入解析相控阵雷达仿真中的TWS(边搜索边跟踪)与TAS(搜索加跟踪)模式,提供实战代码示例和优化策略。通过简化模型设计和对象化建模,帮助开发者快速构建高效仿真系统,适用于军事推演和装备评估。文章涵盖核心逻辑、数据结构设计及性能优化技巧,提升仿真效率与准确性。

weixin_30687051的博客 453

小心使得万年船,特别数据别样烦

首先我想说,很多题目真的是就差这么一点点 ,感觉自己哪里都没错,其实就是想不到一些特别的数据 B. Fixed Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard outputA permutation of len

beckyUp的博客 399

使用 git一个仓库管理多个项目

我们需要在 git 里面创建一个空分支,该分支不继承任何提交,没有父节点,完全是一个干净的分支,这时候就需要使用 orphan。该命令会创建一个新的分支,并且该分支有前一个分支下的所有文件,我们不想提交任何内容,所以我们需要把当前内容全部删除。此时 master 分支已经有一个项目了,下面我们创建新的分支管理另一个项目。此时可以在该分支目录上初始化你的项目,在执行 git 命令提交代码。此时我们就完成了在同一个仓库管理不同项目的需求了。下载仓库到本地之后,进入项目目录,查看分支信息。

xrs151的博客 2027

学习笔记7--激光雷达标定

本系列博客包括6个专栏,分别为:《自动驾驶技术概览》、《自动驾驶汽车平台技术基础》、《自动驾驶汽车定位技术》、《自动驾驶汽车环境感知》、《自动驾驶汽车决策与控制》、《自动驾驶系统设计及应用》,笔者不是自动驾驶领域的专家,只是一个在探索自动驾驶路上的小白,此系列丛书尚未阅读完,也是边阅读边总结边思考,欢迎各位小伙伴,各位大牛们在评论区给出建议,帮笔者这个小白挑出错误,谢谢! 此专栏是关于《自动驾驶汽车环境感知》书籍的笔记。 2.激光雷达标定 2.1 概述 激光雷达内参标定:内部激光发射器坐标系与雷达本

FUXI_Willard 8026

Codeforces 303A 构造+数论

Lucky Permutation Triple time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Bike is interested in permutations

black_miracle的博客 506

【Allegro学习笔记】常规标贴封装创建-0402封装创建实例

摘要&#13; &#13; 本文主要介绍如何使用Allegro制作表面贴装封装。&#13; 所使用的软件&#13; &#13; 使用Allegro制作常规贴片封装主要使用的软件有Pad Designer和Allegro&#13; 1 0402类封装制作&#13; 1.1 0402类封装焊盘分析&#13; 0402封装尺寸图如图1...

Honglong 1万+

Permutation Game

B. Permutation Game time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output n children are standing in a circle and

爱梦者的心之旅 977

R数据分析:潜在剖面分析LPA的做法与解释

Latent Profile Analysis (LPA) tries to identify clusters of individuals (i.e., latent profiles) based on responses to a series of continuous variables (i.e., indicators). LPA assumes that there are unobserved latent profiles that generate patterns of resp.

Codewar的博客 1万+

1篇2章1节:在 Mac 上安装 Python,从环境检查到工具配置的完整指南

Python 是当今最流行的高级编程语言之一,广泛应用于数据分析、人工智能、自动化脚本和 Web 开发。虽然 macOS 曾自带 Python,但从 macOS 12.3 开始,系统不再默认提供可直接使用的版本,因此需要手动安装。本文将详细讲解如何在 Mac 上安装最新版本的 Python,如何验证安装是否成功,以及如何配置 IDLE 和 Python Launcher 等工具,为日常开发和学习打下坚实基础。即便你是完全的新手,也能按步骤完成环境搭建。

MD Code 848

Lucky Permutation Triple 构造

Bike is interested in permutations. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, [0, 2, 1] is a permutation...

anp53732的博客 308

异常数据(outlier data)处理基于分位数法(箱图法、箱型法)替换及删除方案

异常数据(outlier data)处理基于分位数法(箱图法、箱型法)替换及删除方案 简单统计法: 这个原则有个条件:数据需要服从正态分布。 在3倍标准差原则下,异常值如超过3倍标准差,那么可以将其视为异常值。正负3的概率是99.7%,那么距离平均值3之外的值出现的概率为P(|x-u| > 3) <= 0.003,属于极个别的小概率事件。如果数据不服从正态分布,也可以用远离平均值的多少倍标准差来描述。 分位数法(箱图法、箱型法): 并不是说从高斯分布中抽出的所有数据都符..

data+scenario+science+insight 1795

Fixed Points (Codeforces Round #201 (Div. 2))

题目链接:http://codeforces.com/contest/347/problem/B 题意:给定n个各不相同的数,若i = a[i]即第i个位置a[i]的数值为i则称该点为fixed point,对于给定的n个数,最多交换两个数的位置,求该数列可能有的最多的fixed points的值。 思路:两个for循环扫会超时,所以只能扫一次。另开一个vis数组,以和下标不一样的数字为下标储...

weixin_43870697的博客 234

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Round #201 (Div. 2)B、Fixed Points

1、题目链接:http://codeforces.com/contest/347/problem/B 2、我怎么又做了画蛇添足的事。。。在flag1=true之后直接break了,只是为了提高一点点效率。。。可是这样做的话,后面那些“正常”的fixed的点都被忽略了。。。奇怪的是系统数据居然过了。。。结果到最后果断被hack数据干掉了。。。 #include using namespace

475

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

Codeforces Round #201 (Div. 2) B. Fixed Points

B. Fixed Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A permutation of length n is an integer seq

习惯与规则决定命运 1430

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

B-fixed points

Description A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while bo

sdau20163940的博客 421

B. Fixed Points

time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A permutation of length n is an integer sequence such that each

无知的我 1880

CF 303A(Lucky Permutation Triple-打表-数列全排列)

A. Lucky Permutation Triple time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Bike is interested in permutati

nike0good |Oier&ACMer | 熟能生巧 2083

Lucky Permutation Triple CodeForces - 303A

Bike is interested in permutations. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, [0, 2, 1] is a permutation of l

白黑菜的博客 628

Codeforces Round #321 (Div. 2) 580C Kefa and Park(dfs)

题目链接: 第一行给你n、m,接下来的一行有n个数,如果为1则代表这个点有cat,接下来的n-1行每行给出x、y,表示x、y相连。问你从1出发 能到达的叶子结点有几个,要求到达叶子结点的路上连续有cat的点不超过m。 a数组保存结点是否含有cat,从1这个点开始dfs,每次dfs对cat数组操作,记录连续的含有cat的点数,回溯时再判断当前结点是否满足 条件,要求结点为叶子

GKHack's Blog 2041

Codeforces Round #200 (Div. 2)344E Read Time(二分)

E. Read Time time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mad scientist Mike does not use slow hard disks

GKHack's Blog 1749

Codeforces Round #325 (Div. 2) 586ABC题解

题目链接:点击打开链接 A: 给出Alena的课表, 1代表有课, 0代表没课, 2个连续0以上可以回家休息, 问你一天在学校待多久. 直接模拟即可, 可以直接计算1, 101的数目. 我记录了开头的1和结尾的1, 然后减去2个连续0以上的个数就是答案. AC代码: #include "iostream" #include "cstdio" #include "cstring" #

GKHack's Blog 1711

Codeforces Round #308 (Div. 2)题解

第二天补的 并不都是自己写的 参考了别人的题解 感觉这次cf题意好懂 就是做起来嘛。。 毕竟我还太弱。。 只为落实 A. Vanya and Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input

GKHack's Blog 1674

Codeforces Round #322 (Div. 2) 581A 581B 581C

581A链接:点击打开链接 给你a只红袜子,b只蓝袜子,问你可以组成多少对颜色不同的袜子以及剩下多少对单色袜子。 小小的脑洞,答案分别为a, b最小值以及a - b绝对值的一半。 AC代码: #include "iostream" #include "cstdio" #include "cstring" #include "algorithm" using na

GKHack's Blog 1665

Codeforces Round #250 (Div. 2) 437C The Child and Toy(脑洞贪心)

C. The Child and Toy time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output On Children's Day, the child got a toy

GKHack's Blog 1626
上一篇: Codeforces Round #201 (Div. 2) 347A Difference Row(脑洞)
下一篇: Codeforces Round #201 (Div. 2) 347C Alice and Bob(脑洞)
GKHack
博客等级 码龄11年 48粉丝 291原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值