naoqi机器人总结28

长方体 (nowcoder.com)

#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<(4*(sqrt(1.0*a*c/b)+sqrt(1.0*a*b/c)+sqrt(1.0*b*c/a)))<<endl;
    return 0;
}

P3387 【模板】缩点 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

#include<iostream>
#include<queue>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 10010
#define M 200010
#define LL long long
using namespace std;int n,m,v[N],le[N],lg[N],tote,totg,a,b,rd[N],f[N];
struct node{int next,to;}e[M],g[M];
inline void adde(int u,int v){e[++tote]=(node){le[u],v};le[u]=tote;return;}
inline void addg(int u,int v){g[++totg]=(node){lg[u],v};lg[u]=totg;return;}
bool vis[N];

int low[N],dfn[N],stk[N],top,cnt,which[N];
inline void Tarjan(int x)
{
	low[x]=dfn[x]=++cnt;
	stk[++top]=x;vis[x]=true;
	for(register int i=le[x];i;i=e[i].next)
	{
		int y=e[i].to;
		if(dfn[y]==0)
		{
			Tarjan(y);
			low[x]=min(low[x],low[y]);
		}
		else if(vis[y]) low[x]=min(low[x],dfn[y]);
	}
	if(dfn[x]==low[x])
	{
		int y;
		while(y=stk[top--])
		{
			which[y]=x;vis[y]=false;
			if(x==y) break;
			v[x]+=v[y];
		}
		return;
	}
}
signed main()
{
    cin>>n>>m;
	for(register int i=1;i<=n;i++) cin>>v[i];
	for(register int i=1;i<=m;i++) cin>>a>>b,adde(a,b);
	for(register int i=1;i<=n;i++) if(!dfn[i]) Tarjan(i);
	for(register int x=1;x<=n;x++)
	 for(register int i=le[x];i;i=e[i].next)
	{
		int y=e[i].to;
		if(which[x]!=which[y]) addg(which[x],which[y]),rd[which[y]]++;
	}
	queue<int>q;
	for(register int i=1;i<=n;i++) if(which[i]==i&&rd[i]==0) q.push(i),f[i]=v[i];
	while(q.size())
	{
		int x=q.front();q.pop();
		for(register int i=lg[x];i;i=g[i].next)
		{
			int y=g[i].to;
			f[y]=max(f[y],f[x]+v[y]);
			if(--rd[y]==0) q.push(y);
		}
	}
	int res=0;
	for(register int i=1;i<=n;i++) res=max(res,f[i]);
	printf("%d",res);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值