From d8881d65c35e628e4ad380781dfde838fca0be3b Mon Sep 17 00:00:00 2001 From: Ta180m Date: Sat, 30 May 2020 17:51:17 -0500 Subject: [PATCH] Fixed segfaults? --- cowntact.txt | 98 +------------------------------------------------ output | Bin 1927 -> 731 bytes src/encode.cpp | 2 + 3 files changed, 3 insertions(+), 97 deletions(-) diff --git a/cowntact.txt b/cowntact.txt index 0032fdf..e7dd232 100644 --- a/cowntact.txt +++ b/cowntact.txt @@ -1,97 +1 @@ -Farmer John is planning to build N (1<=N<=105) farms that will be connected by N-1 roads, forming a tree. Typically, whenever one of his farms is having an issue he is not told the specific farm that is having an issue. Instead, he is told that one of the farms along the path from some farm A to another farm B is having an issue. This is often confusing for Farmer John, as he usually drives offroad tractors and isn't familiar with the road system. -Farmer John considers the location of a farm to be a 2D point. He would prefer to be told that there is a problem in one of the farms in a specified axis-aligned rectangular box. This way Farmer John can decide for himself how to navigate between the farms. Bessie told him that this is a little too ambitious, so he will be satisfied if he is notified with at most two axis-aligned rectangular boxes whose intersection (of farms) is empty and whose union is exactly the farms along the path from A to B. You must help Farmer John determine where he should build his farms such that this condition is satisfied. - -This is an interactive problem, you will not be using standard (or file) I/O. Solutions that use standard (or file) I/O will be disqualified. However, you ARE ALLOWED to use global and static variables. You must implement the following functions to help Farmer John: - -void addRoad(int A, int B): processes a road between farms A and B (0<=A,B<=N-1). -void buildFarms(): determines where Farmer John should build all his farms. -void notifyFJ(int A, int B): notifies Farmer John with either one or two boxes that satisfy the aforementioned conditions. -Your implementation of the above functions will be able to call the functions given below. You may assume that notifyFJ will be called Q times (1<=Q<=105). - -int getN(): gets the value of N. -int getQ(): gets the value of Q. -void setFarmLocation(int ID, int X, int Y): determines that Farmer John should build farm ID (0<=ID<=N-1) at location (X,Y) where (1<=X,Y<=N). Should only be called from buildFarms. -void addBox(int X1, int Y1, int X2, int Y2): adds a box to notify Farmer John where (1<=X1<=X2<=N) and (1<=Y1<=Y2<=N). Should only be called from notifyFJ. -The interactive protocol works as follows. First, addRoad will be called N-1 times, to inform your program of the road system. Then, buildFarms will be called and you must determine where Farmer John should build each farm and call setFarmLocation for every farm accordingly. Finally, there will be Q calls to notifyFJ where you must make either one or two calls to addBox to notify Farmer John. - -It is guaranteed there is always a valid way to notify Farmer John using either one or two boxes. The memory limit for this problem is set to 512MB, above the usual 256MB limit. -$$$$$$$$$$ -.............. -,,,,.,.,.,.,.,:":ef[]wlf[wepk[]] -For a C++ solution, use this template: - -#include "grader.h" - -void addRoad(int a, int b){ - // Fill in code here -} - -void buildFarms(){ - // Fill in code here -} - -void notifyFJ(int a, int b){ - // Fill in code here -} -For a Java solution, use this template: - -import java.io.IOException; -// If you find it necessary, you may import other standard libraries here. -public class boxes extends Grader { - - // Copy this exactly: - -@Override - public static void main(String args[]) throws IOException { new boxes().run(); } - - -@Override - public void addRoad(int a, int b) { - // Fill in code here - } - -@Override - public void buildFarms(){ - // Fill in code here - } - -@Override - public void notifyFJ(int a, int b){ - // Fill in code here - } -} -Sample Interaction - -Grader calls addRoad(0,1) - -Grader calls addRoad(1,2) - -Grader calls buildFarms() - -Solution calls setFarmLocation(0,1,1) - -Solution calls setFarmLocation(1,1,2) - -Solution calls setFarmLocation(2,2,2) - -Solution ends buildFarms() - -Grader calls notifyFJ(0,0) - -Solution calls addBox(1,1,1,1) - -Solution ends notifyFJ(0,0) - -Grader calls notifyFJ(0,2) - -Solution calls addBox(1,1,1,2) - -Solution calls addBox(2,2,2,2) - -Solution ends notifyFJ(0,2) - -Grader terminates, and solution passes test-case - -(Note: if you do not pass the first test case, the grader will indicate this as usual. However, note that the short sample interaction above does not correspond to the first test case or any other). - -Problem credits: Spencer Compton \ No newline at end of file +<>()899&*(%&#(^()#*Q_)#O%FSGDSGD#@%G) \ No newline at end of file diff --git a/output b/output index 83147e4e171bf4c3b1e73cd589de22ed02145223..9013b27f4eacaba1af0b2dd42fe771bb07aa3b7e 100644 GIT binary patch literal 731 zcmV<10wnz!RF6B|;>LIHb-!y@HSbzIJJ-Q!b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V5k+>|G_-(_25};yAj>&EMJ7VST*Xyvdugv&LX@ll@nrDn>|G^;P95KUd zr%ja;6Qtr?9=-cRR`2*nYXsnCG=B;r!4K_hPMm&&LEuI@*z@L;sc~Vb$EHWtGWvkwXx*oVK`(drw%*V9)&11)v&v@VOXO$xI3&eL`Qf?zABD1( z^kUzRbnlM2d~&F{JPk(u?jmiMhHx;$dJK`% zAjxT#57kTPvRoy~Dx!RAw!9?8@?mL6zIPNG=kYu84WinOwgg*9%uM7&3z8KRcb~PR zJizF)BrS`0NaWEAajEN0%ay0SprO?G5P#9enEz^0HODyo!0`~zK#fM9&!-D4Q-R|6 zJVKEP<%jBYZ_cBq%9j`p!#rb;gni1*fzXZ-a3m{tYc;Ge_Sg z<{%H)L8G*Z2$lgcrH)7v0zrq?A*9r`qq1oT>^A9uCY%)uWknzfvu_>VyXD^bi6P(l zA6>fS&YWR=_k_BG6e-!XRFfeF#v#Zh{>;6@r{)j-2!l`Q94)*RZ+$o32Fo{_Kf=bC z$pw~q#MUj71IMpFXUsHJc4dZhzqD~N*Kd3Zc4oC5Cyx{Jomt`ZNvCD}6+yHoLSkYH zDgqosWk=w+_;PJam;UR4Kp^nr^gkA4Or}}AMDr_u5zkzn4?{fAh*5QZC9|(;z~?z6 YvlNV(qxV6Jdtpr|t(dR|Cxqtz03o^($^ZZW diff --git a/src/encode.cpp b/src/encode.cpp index c006581..6b3751b 100644 --- a/src/encode.cpp +++ b/src/encode.cpp @@ -363,6 +363,7 @@ void stripUnicode(string & str) string huffmancompress(string s) { + if (s.size() < 2) return ""; vector enc = huffman::encode(s); ofstream cout("output"); string ans; @@ -379,6 +380,7 @@ string huffmancompress(string s) int huffmancompresslength(string s) { + if (s.size() < 2) return 0; vector enc = huffman::encode(s); return (enc.size() + 7) / 8; }