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 ...
随机推荐
- ASP.NET中Onclick和OnserverClick事件的区别
对于服务器按钮控件(即<asp:Button>类型的按钮): 服务器响应事件:OnClick 客户端响应属性:OnClientClick 对于html按钮控件(即<input typ ...
- Hollister Outlet Store
(link to hollisterco site), It's a major try. After a photographer's viewpoint, Which roughly splend ...
- 支付宝集成后报错ALI38173
原因: 支付时传的参数不正确. 出现这个错误, 说明支付功能已经集成成功, 前后台核对下参数就能找到原因了.
- 在一台机器上模拟mongodb分片
首先选择一个目录在其中建立以下2个文件夹:data和log 在data下建立9个文件夹: 其中前3个为配置服务器所在文件夹,按照官网要求,一个集群需要3个config server rs-a-n和rs ...
- MFC listcontrol导出excel表格
// 导出ExcelCString CBackGroundDlg::ExportAsExcel(CString filename, CListCtrl &resultlist, CWnd * ...
- Octave安装和使用
1. Installer Download octave4.0 gnuplot 5.0.4 2. Installation (1) Octave 安装Octave时提示发现系统装有Win8,继续安装 ...
- Android事件分发机制(下)
这篇文章继续讨论Android事件分发机制,首先我们来探讨一下,什么是ViewGroup?它和普通的View有什么区别? 顾名思义,ViewGroup就是一组View的集合,它包含很多的子View和子 ...
- oracle 用户创建这个挺靠谱
CREATE TEMPORARY TABLESPACE test_tempTEMPFILE 'C:\oracle\product\10.1.0\oradata\orcl\test_temp01.dbf ...
- IIS7+windows 64位配置注意事项
问题和解决办法 1 如果网站为Asp:再asp中注意启用父路径 2 操作必须使用一个可更新的查询:给用户iis_iusrs 一个完全控制的权限 3 Windows(64位IIS)未在本地计算机上 ...
- C++关于Condition Variable
#include <condition_variable> #include <mutex> #include <future> #include <iost ...