UVa 12118 - Inspector's Dilemma <欧拉道路+DFS>

这道题题意比较好理解,但需要一些关于欧拉道路的思考。

刚开始考虑用并查集做,每个集(或者说每条链)有可能是环状,或者有多个奇点,这就需要多个入口和出口,需要统计,用并查集并不太好实现。然后考虑DFS的做法,需要计算每个节点的度数,统计每条链的奇点个数,并且注意每条连至少需要一个入口和一个出口,最后将多条链合并即可。

#include <bits/stdc++.h>
using namespace std;

int v, e, t, kase = 0;
const int maxn = 1024;
vector<int> Road[maxn];
bool vis[maxn];

void init()
{
    memset(vis, false, sizeof(vis));
    for(int i = 0; i < maxn; ++i)
        Road[i].clear();
}

int DFS(int n)
{
    if(vis[n]) return 0;
    int cnt = 0;
    vis[n] = true;
    cnt += (Road[n].size() & 1);
    for(size_t i = 0; i < Road[n].size(); ++i)
        cnt += DFS(Road[n][i]);
    return cnt;
}

int solve()
{
    int res = 0;
    for(int i = 1; i <= v; ++i)
        if(!vis[i] && !Road[i].empty())
            res += max(DFS(i), 2);
    return t * (max((res - 2) / 2, 0) + e);
}

int main()
{
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    while(init(), cin >> v >> e >> t, v || e || t){
        for(int i = 0; i < e; i++){
            int x, y; cin >> x >> y;
            Road[x].push_back(y); Road[y].push_back(x);
        }
        printf("Case %d: %d\n", ++kase, solve());
    }
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
在Unity的Inspector中编辑`List<KeyValuePair>`可以使用自定义的PropertyDrawer来实现。下面是一些步骤来帮助你完成这个过程: 1. 创建一个新的脚本文件,命名为`KeyValuePairListDrawer.cs`(或者你喜欢的其他名称)。 2. 在脚本文件中编写以下代码: ```csharp using UnityEngine; using UnityEditor; using System.Collections.Generic; [CustomPropertyDrawer(typeof(List<KeyValuePair<string, string>>))] public class KeyValuePairListDrawer : PropertyDrawer { public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); EditorGUI.LabelField(position, label); position.y += EditorGUIUtility.singleLineHeight; EditorGUI.indentLevel++; SerializedProperty list = property.FindPropertyRelative("list"); for (int i = 0; i < list.arraySize; i++) { SerializedProperty element = list.GetArrayElementAtIndex(i); SerializedProperty key = element.FindPropertyRelative("Key"); SerializedProperty value = element.FindPropertyRelative("Value"); Rect keyRect = new Rect(position.x, position.y, position.width * 0.4f, EditorGUIUtility.singleLineHeight); Rect valueRect = new Rect(position.x + position.width * 0.45f, position.y, position.width * 0.4f, EditorGUIUtility.singleLineHeight); EditorGUI.PropertyField(keyRect, key, GUIContent.none); EditorGUI.PropertyField(valueRect, value, GUIContent.none); position.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; } EditorGUI.indentLevel--; EditorGUI.EndProperty(); } public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { int count = property.FindPropertyRelative("list").arraySize; return EditorGUIUtility.singleLineHeight * (count + 1) + EditorGUIUtility.standardVerticalSpacing * count; } } ``` 3. 将脚本文件放置在项目中的任何文件夹中。 4. 在Inspector中使用`List<KeyValuePair<string, string>>`类型的属性时,它将自动使用我们创建的PropertyDrawer进行绘制和编辑。 现在,你可以在Inspector中编辑`List<KeyValuePair<string, string>>`类型的属性了。每个KeyValuePair都会显示为一个键值对,并且你可以为每个键和值输入不同的值。 注意:这个PropertyDrawer只支持`List<KeyValuePair<string, string>>`类型的属性。如果你想在Inspector中编辑其他类型的KeyValuePair列表,你需要进行适当的修改。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值