Skip to content

Commit adc3b73

Browse files
author
unknown
committed
added modified files
1 parent 0a00eb5 commit adc3b73

File tree

900 files changed

+15700
-19842
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

900 files changed

+15700
-19842
lines changed

lib/Constructor/ConstructorSolver.cs

+30-9
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ public SolutionSpec Work()
4343
}
4444

4545
int i = 0;
46-
GivenPolygons
47-
.OrderByDescending(p => p.GetUnsignedSquare())
48-
.First(polygon =>
46+
var result = GivenPolygons
47+
.OrderByDescending(HasRightAngle)
48+
.ThenByDescending(p => p.GetUnsignedSquare())
49+
.FirstOrDefault(polygon =>
4950
{
5051
Console.WriteLine($"{i++}/{GivenPolygons.Length} started");
5152
return polygon.Segments.Any(segment => StartWithPolygonSegment(polygon, segment));
@@ -55,6 +56,19 @@ public SolutionSpec Work()
5556
return GenerateSolution();
5657
}
5758

59+
private bool HasRightAngle(Polygon polygon)
60+
{
61+
for (int i = 0; i < polygon.Segments.Length; i++)
62+
{
63+
var s1 = polygon.Segments[i];
64+
var s2 = polygon.Segments[(i + 1)%polygon.Segments.Length];
65+
if ((s1.End - s1.Start).ScalarProd(s2.End - s2.Start) == 0)
66+
return true;
67+
}
68+
69+
return false;
70+
}
71+
5872
private SolutionSpec GenerateSolution()
5973
{
6074
var dict = new Dictionary<Vector, int>();
@@ -145,17 +159,19 @@ private bool DoIt()
145159

146160
foreach (var pair in Vertexes.Where(pair => !Variants.ContainsKey(pair.Key) && !UsedVertexes.Contains(pair.Key)))
147161
{
148-
var rounds = GetRounds(pair.Key, 1000); //возвращает Null если цикл уже построен
149-
if (rounds != null)
162+
var rounds = GetRounds(pair.Key, 10); //возвращает Null если цикл уже построен
163+
if (rounds != null && rounds.Count <= 10)
150164
Variants[pair.Key] = rounds;
151-
else
165+
else if(rounds == null)
152166
{
153167
UsedVertexes.Add(pair.Key);
154168
continue;
155169
}
156-
if (Variants[pair.Key].Count == 0)
170+
if ((Variants.GetOrDefault(pair.Key)?.Count ?? 0) == 0)
157171
return false;
158172
}
173+
if (Variants.Count == 0)
174+
return false;
159175

160176
var simplest = Variants.Min(v => v.Value.Count);
161177
var variant = Variants.First(v => v.Value.Count == simplest);
@@ -248,8 +264,13 @@ private void DoRound(Polygon polygon, Polygon startPolygon, Segment startSegment
248264
{
249265
if(!SegmentsMatrix.TryAddPolygon(pPolygon))
250266
continue;
251-
var newSegment = pPolygon.Segments.Where(s => s.Start.Equals(vertex) || s.End.Equals(vertex)).First(s => !s.Equals(segment));
252-
267+
var newSegment = pPolygon.Segments.Where(s => s.Start.Equals(vertex) || s.End.Equals(vertex)).FirstOrDefault(s => !s.Equals(segment));
268+
if (newSegment == null)
269+
{
270+
SegmentsMatrix.RemovePolygon(pPolygon);
271+
return;
272+
}
273+
253274
stack.Push(pPolygon);
254275
DoRound(pPolygon, startPolygon, startSegment, newSegment, result, stack, vertex, maxCount, deep + 1);
255276
stack.Pop();

lib/Constructor/SegmentsFinder.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ public static List<Polygon> GetRealPolygons(ProblemSpec problem)
2929
}
3030
foreach (var holePolygon in holePolygons)
3131
{
32-
var polygon = polygons.Last(p => ArePointsPolygon(p.Vertices, holePolygon));
33-
polygons.Remove(polygon);
32+
var polygon = polygons.LastOrDefault(p => ArePointsPolygon(p.Vertices, holePolygon));
33+
if(polygon != null)
34+
polygons.Remove(polygon);
3435
}
3536

3637
return polygons;
@@ -73,6 +74,8 @@ private static IEnumerable<Vector> GeneratePolygon(Segment startSegment, Diction
7374
}
7475
}
7576
segment = best;
77+
if(segment == null)
78+
yield break;
7679
yield return segment.Start;
7780
usedSegments.Add(Tuple.Create(segment.Start, segment.End));
7881
}

problems/023.response.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"solution_size":1341,"ok":true,"resemblance":0.905045,"problem_id":23,"solution_spec_hash":"30e2427d8bcfc94e5421f20e5ece3bdd67aa3bf9"}
1+
{"solution_size":227,"ok":true,"resemblance":1.0,"problem_id":23,"solution_spec_hash":"00f4acb60248e3e1d6dc610a01d1e1418e00de20"}

problems/023.solution.txt

+25-77
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,32 @@
1-
31
2-
446/525,226/525
3-
439/525,10/21
4-
724/1575,56/75
5-
4513/26250,352/625
6-
79/525,83/210
7-
598/2625,683/5250
8-
16621/18945,32906/73675
9-
6929/8050,791/1725
10-
395774/447825,214126/447825
11-
17387/1640625,2016757/3281250
12-
12871/1430625,150727/953750
13-
353/1050,0
14-
1067/1575,0
15-
1,111614/311325
16-
1,143692964/249003825
17-
227089/434700,1
18-
23939/223650,1
19-
0,7699513/12340650
20-
0,5976/13175
21-
0,9085879619/59939763450
22-
462977/4629450,0
23-
325909/1543150,0
24-
6697/25200,0
25-
0,51773/591150
26-
0,3165250583/5158962900
27-
0,15190417/106262100
28-
0,343501021/555818550
1+
12
2+
1/2,10/21
3+
1/2,11/21
4+
43/126,0
5+
1,19/84
6+
0,17/42
7+
1,25/42
8+
83/126,1
9+
0,65/84
2910
1,0
11+
0,0
3012
1,1
3113
0,1
32-
0,0
33-
20
34-
8 11 12 0 1 2 3 4 5
35-
5 12 27 13 6 0
36-
3 0 7 1
37-
6 14 28 15 2 1 8
38-
6 2 16 29 17 9 3
39-
5 4 3 18 19 10
40-
4 20 21 5 4
41-
3 22 11 5
42-
3 6 7 0
43-
3 1 7 8
44-
4 13 14 8 6
45-
3 8 7 6
46-
3 21 22 5
47-
5 30 20 4 10 23
48-
4 24 18 3 9
49-
3 19 25 10
50-
3 10 25 23
51-
3 15 16 2
52-
3 17 26 9
53-
3 26 24 9
54-
-1/42,0
14+
6
15+
4 8 2 0 3
16+
4 0 4 9 2
17+
4 5 1 0 3
18+
4 5 1 6 10
19+
4 7 1 0 4
20+
4 11 7 1 6
5521
1/42,0
56-
7/18,2/7
57-
22/75,46/75
58-
29/210,143/210
59-
-29/210,143/210
60-
443/53046,0
61-
0,3/161
6222
-1/42,0
23+
-7/18,2/7
24+
23/84,1/2
25+
2/21,1/2
26+
-2/21,1/2
27+
7/18,2/7
28+
-23/84,1/2
6329
29/210,143/210
64-
-29/210,143/210
6530
-22/75,46/75
66-
-7/18,2/7
67-
496603/7081606,69720/505829
68-
-956213/6640102,312306/3320051
69-
490301/1552500,485648/905625
70-
-17293/399375,305219/931875
71-
102021/822710,143/210
72-
97186408/874569675,304250641/583046450
73-
-118477441/799196846,2703407383/3995984230
74-
-15026/66135,80527/154315
75-
-1139/4409,13857/22045
76-
-1529341/6638100,46338401/79657200
77-
-13094161/64435350,42049723/64435350
78-
657467903/5158962900,143/210
79-
-289673509/1930428150,7738221787/11582568900
80-
23695911/185272850,376017011/555818550
81-
-821237/7463750,5013326/11195625
82-
-1204493/7463750,5784089/11195625
83-
-96729/781250,3265369/8203125
84-
-57757856/207440625,252133541/414881250
31+
22/75,46/75
32+
-29/210,143/210

problems/027.response.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"solution_size":3577,"ok":true,"resemblance":0.764715,"problem_id":27,"solution_spec_hash":"3d4e1f73576697a2bc601f4f9256899db1ff375a"}
1+
{"solution_size":903,"ok":true,"resemblance":1.0,"problem_id":27,"solution_spec_hash":"70e30ef8289836acbeeb1db3e28bcd1a471d6af8"}

0 commit comments

Comments
 (0)