Пример #1
0
    static void Main()
    {
        var(n, m, s) = Read3();
        var es  = Array.ConvertAll(new bool[m], _ => Read4());
        var cds = Array.ConvertAll(new bool[n], _ => Read2());

        var jMax = 2500;
        var map  = new WeightedMap(n + 1, jMax + 1);

        foreach (var(u, v, a, b) in es)
        {
            for (int j = 0; j + a <= jMax; j++)
            {
                map.AddEdge(new Point(u, j + a), new Point(v, j), b, true);
                map.AddEdge(new Point(v, j + a), new Point(u, j), b, true);
            }
        }
        for (int i = 1; i <= n; i++)
        {
            var(c, d) = cds[i - 1];
            for (int j = 0; j < jMax; j++)
            {
                map.AddEdge(new Point(i, j), new Point(i, Math.Min(jMax, j + c)), d, true);
            }
        }

        s = Math.Min(s, jMax);
        var r  = map.Dijkstra((1, s), (-1, -1));
        var rj = Enumerable.Range(0, jMax + 1).ToArray();

        for (int i = 2; i <= n; i++)
        {
            Console.WriteLine(rj.Min(j => r[i, j]));
        }
    }
Пример #2
0
 public void EnterSight(GameObject gameObject)
 {
     foreach (InfluenceSource source in gameObject.GetComponentsFromParentInChildren <InfluenceSource>())
     {
         if (source.parentMap.isPresenceMap && source.type != type)
         {
             var wMap = new WeightedMap();
             wMap.map    = source.parentMap;
             wMap.weight = preferenceMap.GetWeight(source.type);
             maps.Add(wMap);
         }
     }
 }
Пример #3
0
	// Update is called once per frame
	void Update () 
	{
		if (map == null) 
		{
			points = GameObject.FindGameObjectsWithTag (itemTag);
			map = new WeightedMap (points);
		}
			
		//if there is no target get one 
		if (!isReturn && target == null) 
		{
			target = map.PopHeighestWeight ();

			if (target == null)
				isReturn = true;
		}
		else if (!isReturn)
		{
			//find the item
			this.GetComponent <Animator>().SetTrigger ("Sprinting");
			this.GetComponent <NavMeshAgent> ().destination = target.transform.position;

			//if we are near the item get it
			if (Vector3.Distance (this.transform.position, target.transform.position) < 3)
			{
				DestroyObject (target.transform.root.gameObject);
			}
		}

		//if is return is active go to the summonigng well
		if (isReturn) 
		{
			this.GetComponent <NavMeshAgent> ().destination = homePosition;
			if (Vector3.Distance (this.transform.position, homePosition) < 3)
				isReturn = false;
		}

		//sets the rule for when the ai should return back to its summoning well
		if (this.GetComponent <Stats> ().mana < (this.GetComponent <Stats> ().maxMana / 2))
			isReturn = true;
		else
			isReturn = false;

		//if we are close to the player then 
		if (target != null && Vector3.Distance (this.transform.position, GameObject.FindGameObjectWithTag ("Player").transform.position) < 6)
			this.GetComponent <SpellCaster> ().enabled = true;
		else
			this.GetComponent <SpellCaster> ().enabled = false;


	}
Пример #4
0
    static void Main()
    {
        var(n, m) = Read2();
        var es = Array.ConvertAll(new bool[m], _ => (Edge)Read());

        var map = new WeightedMap(n + 1, es, false);

        var id      = n;
        var idMap   = new int[n + 1, 51];
        var idMap_r = new List <(int v, long w)>(Enumerable.Range(0, n + 1).Select(i => (i, 0L)));

        void InitId(int v, long w)
        {
            if (idMap[v, w] != 0)
            {
                return;
            }
            idMap[v, w] = ++id;
            idMap_r.Add((v, w));
        }

        foreach (var(v, u, w) in es)
        {
            InitId(v, w);
            InitId(u, w);
        }

        // 辺を静的に構築すると MLE。
        var r = ShortestPathCore.Dijkstra(id + 1, v =>
        {
            if (v <= n)
            {
                return(Array.ConvertAll(map[v], e => new Edge(v, idMap[e.To, e.Cost], 0)));
            }
            else
            {
                var(v0, w) = idMap_r[v];
                return(Array.ConvertAll(map[v0], e => new Edge(v, e.To, (w + e.Cost) * (w + e.Cost))));
            }
        }, 1);

        Console.WriteLine(string.Join(" ", Enumerable.Range(1, n).Select(v => r.GetCost(v))));
    }