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 ...
随机推荐
- OC基础--对成员变量的封装
#import <Foundation/Foundation.h> //日期结构体 typedef struct{ int year; int month; int day; } Date ...
- 清除Linux OS 缓存
1.查看内存使用情况 [root@ip---- tpch_2_17_0]# free -m total used free shared buffers cached Mem: -/+ buffers ...
- wpf学习笔记
1.菜单:普通菜单.上下文菜单(ContextMenu) <Menu HorizontalAlignment="Left" Height="20" Ver ...
- Chinese economic influence in North Korea
Where this new investment is being targeted is also interesting雄性禿 . "If you look at the econom ...
- VMware-workstation-full-12.0.0-2985596&VMware-player-12.0.0-2985596
VMware-workstation-full-12.0.0-2985596 永久KEY:YV3D2-A0D50-481XP-KPNGE-ZV2ZF VMware-player-12.0.0-2985 ...
- java之并发编程:Lock
这是转的:http://www.cnblogs.com/dolphin0520/p/3923167.html * 在多线程编程里面一个重要的概念是锁定,如果一个资源是多个线程共享的,为了保证数据的完整 ...
- shape的简单用法
shap节点-----------------------------------定义shape的值,必须是下面的之一:"rectangle" 矩阵,这也是默认的shape&quo ...
- java实现服务端守护进程来监听客户端通过上传json文件写数据到hbase中
1.项目介绍: 由于大数据部门涉及到其他部门将数据传到数据中心,大部分公司采用的方式是用json文件的方式传输,因此就需要编写服务端和客户端的小程序了.而我主要实现服务端的代码,也有相应的客户端的测试 ...
- WebView---Android与js交互实例
Android 中可以通过webview来实现和js的交互,在程序中调用js代码,只需要将webview控件的支持js的属性设置为true 原文地址:http://blog.csdn.net/it10 ...
- 最小系统加载工具 systemjs
systemjs 是一个最小系统加载工具,用来创建插件来处理可替代的场景加载过程,包括加载 CSS 场景和图片,主要运行在浏览器和 NodeJS 中.它是 ES6 浏览器加载程序的的扩展,将应用在本地 ...