1124: [POI2008]枪战Maf

1124: [POI2008]枪战Maf

Time Limit: 10 Sec   Memory Limit: 162 MB
Submit: 500   Solved: 199
[ Submit][ Status][ Discuss]

Description

有n个人,每个人手里有一把手枪。一开始所有人都选定一个人瞄准(有可能瞄准自己)。然后他们按某个顺序开枪,且任意时刻只有一个人开枪。因此,对于不同的开枪顺序,最后死的人也不同。

Input

输入n人数<1000000 每个人的aim

Output

你要求最后死亡数目的最小和最大可能

Sample Input

8
2 3 2 2 6 7 8 5

Sample Output

3 5

HINT

Source

[ Submit][ Status][ Discuss]

来考虑贪心
如果要求伤亡最少,
注意到有些点可能入度为0,也就是说,,没人能杀得了他们
那干脆就让他们杀人好了,免得他们枪口指着的人去为害人间(什么逻辑>_<)
剩下的就是一些环了,每个环的贡献显然是(size+1)/2  (一开始想成size/2,这是一个环呀。。GG)

如果要求伤亡最多,
对于图中每个环,显然可以找到一种方法,使得剩下的只有一个人
如果有环外的人指向这个环,显然,我们就可以将这个环赶尽杀绝,否则就留下一人
其他,就是入度为0的人能活下来了


哦对了,本题还有自环
这个一开始就忒判掉好了,毕竟,这种傻逼不适合来到人间
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<bitset>
#include<algorithm>
#include<cstring>
#include<map>
#include<stack>
#include<set>
#include<cmath>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;

const int maxn = 1E6 + 10;

int a1,a2,n,cnt,dfs_clock,shoot[maxn],in[maxn],
	belong[maxn],dfn[maxn],low[maxn],siz[maxn];
bool die[maxn],vis[maxn];

queue <int> Q;
stack <int> s;

void dfs(int x,int from)
{
	dfn[x] = low[x] = ++dfs_clock;
	s.push(x);
	if (!dfn[shoot[x]]) {
		dfs(shoot[x],x);
		low[x] = min(low[x],low[shoot[x]]);
	}
	else if (!belong[shoot[x]]) low[x] = min(low[x],low[shoot[x]]);
	if (low[x] >= dfn[x]) {
		int now = 0; ++cnt;
		for (;;) {
			int top = s.top(); s.pop();
			belong[top] = cnt;
			++now;
			if (top == x) break;
		}
		siz[cnt] = now;
	}
}

int main()
{
	#ifdef DMC
		freopen("DMC.txt","r",stdin);
	#endif
	
	cin >> n; a2 = n;
	for (int i = 1; i <= n; i++) scanf("%d",&shoot[i]),++in[shoot[i]];
	for (int i = 1; i <= n; i++) {
		if (!in[i]) Q.push(i),vis[i] = 1;
		if (i == shoot[i]) ++a1,vis[i] = i;
	}
	while (!Q.empty()) {
		int k = Q.front(); Q.pop();
		if (vis[shoot[k]]) continue;
		vis[shoot[k]] = 1;
		++a1; int Nex = shoot[shoot[k]]; --in[Nex];
		if (!in[Nex] && !vis[Nex]) vis[Nex] = 1,Q.push(Nex);
	}
	for (int i = 1; i <= n; i++) {
		if (vis[i]) continue;
		int now = 1; vis[i] = 1;
		for (int j = shoot[i]; ; j = shoot[j]) {
			if (vis[j]) break;
			++now; vis[j] = 1;
		}
		a1 += (now+1)/2;
	}
	cout << a1 << ' ';
	for (int i = 1; i <= n; i++)
		if (!belong[i]) dfs(i,0);
	for (int i = 1; i <= n; i++) 
		if (belong[i] != belong[shoot[i]] || i == shoot[i]) 
			die[belong[shoot[i]]] = 1;
	for (int i = 1; i <= cnt; i++) 
		if (!die[i]) --a2;
	cout << a2;
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值