P9077 [PA2018] Poddrzewo
题目
- 修改序列中第
i 个数。 - 删除序列中第
i 个数。 - 交换序列中第
i,j 个数。
按照正常思路来想我们要建一个图,一个无环的图。
但是看样例一:读入了
好像题目中的每一个要求都符合了。
节点
那现在题目要求就变成了怎样的条件才能满足直接用节点一连节点二呢?
很显然只要
#include <bits/stdc++.h>
using namespace std;
int n,jh;
int main ( ) {
cin >> n ;
for (int i = 1;i <= n;i++) {
int x;
cin >> x ;
if (x == 1) jh++;//统计1的个数
}
if (jh >= 2) cout << "0" << endl ;//满足情况直接输出
else cout << 2 - jh << endl ;//不满足时计算所需的改变次数
cout << "2" << endl << "1 2" << endl ;
}