Discussion of Problem 1020. RopeShow all threads Hide all threads Show all messages Hide all messages | if WA 4 | Lemmiwinks | 1020. Rope | 20 Aug 2021 20:42 | 2 | if WA 4 Lemmiwinks 24 Jun 2021 20:22 use the formula sqrt(abs(x1 - x2)**2 + abs(y1 - y2)**2) not abs(x1 - x2) + abs(y1 - y2) | mathematical proof | emilchess | 1020. Rope | 3 Dec 2020 21:53 | 7 | Draw a polygon. the sum of its angles is pi*(n-2). The sum of pieces of circles is R*(n*pi-(n-2)*pi)=2*R*pi (you can see it easily if u draw) Beautiful. Solved it by calculating angles between vectors of consecutive nails. How is the sum of its angles pi*(n-2)? OP means the sum of angles in a n-polygon is pi*(n-2). This can be attained inductively: 1. The sum of angles in a triangle is pi. 2. for any n-polygon, it can be divided into a (n-1)-polygon and a triangle. | Proper hints for the the test cases out there | samio | 1020. Rope | 21 Feb 2020 01:27 | 1 | Well, you have to know how to determine the distance between two points first. It can be calculated by, dis = sqrt((x1-x2)^2+(y1-y2)^2). You can say that, we can just calculate the distance in between the points but why the raidius of the nails are given. Its because the rope is wrapped around each and every nails. But the rope is not in fully contact with nails. The more nails we get, the less contact we have in between rope and nails. The amount of which the rope is in contact with nail is : s = parameter of a nail/the number of nails. So we are just required to print out : d(d is the sum of the distance between them) + number of nails * s(s is the amount which the rope is in contact with nails) If you have problem understanding my word or for better understanding, give this a go : https://ideone.com/t1M3rK Edited by author 21.02.2020 01:31 | WHY WA ON TEST #4??I am really stuck in this!!!plz help! | michel mizrahi | 1020. Rope | 20 Nov 2019 17:27 | 6 | I can't understand what's wrong with my code is my algorithm wrong? or what? my code: #include <stdio.h> #include <math.h> double x[102],y[102]; double dist(int i, int j){ int d1=abs(x[i]-x[j]),d2=abs(y[i]-y[j]); if(d1==0) return (d2); else if(d2==0) return (d1); else return sqrt(d1*d1 + d2*d2); } int main(){ int i; double n,s=0,r,pi=2*acos(0); scanf("%Lf %Lf",&n,&r); for(i=0;i<n;i++) scanf("%Lf %Lf",&x[i],&y[i]); for(i=1;i<n;i++) s+=dist(i,i-1); s+=dist(0,n-1); s+=2*pi*r; printf("%.2Lf\n",s); return 0; } if someone can help me I would appreciate very much thanks! Your algorithm is right. But it seems to me very strange, that d1 and d2 in your code are integers, while x and y are not. double x[102],y[102]; double dist(int i, int j){ int d1=abs(x[i]-x[j]),d2=abs(y[i]-y[j]); ...} And double n seems strange to me too. Test #4: 3 1.2 12.24 13.34 0.00 24.75 -33.36 70.12 Solution: 153.41 thank you both of you guys :D!!!!!! (and sorry for my bad english :$) I finally got ac, just some stupid and silly mistakes! the answer should be 149.64 isn't it??? where am I wrong? . Edited by author 20.11.2019 17:29 | Why Runtime error on test 4?? | FromNothingToFinal | 1020. Rope | 10 Nov 2019 19:07 | 2 | public class Problem { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int r = sc.nextInt(); double l = 0; if (n != 1) { double x1 = sc.nextDouble(); double y1 = sc.nextDouble(); double memoryX = x1, memoryY = y1; for (int i = 1; i <= n; i++) { if (i == n) { l += Math.sqrt((memoryX - x1) * (memoryX - x1) + (memoryY - y1) * (memoryY - y1)); continue; } double x = sc.nextDouble(); double y = sc.nextDouble(); l += Math.sqrt((x - memoryX) * (x - memoryX) + (y - memoryY) * (y - memoryY)); memoryX = x; memoryY = y; } } l += 2*Math.PI*r; System.out.printf("%.2f", l); sc.close(); } } radius can be float number | Advices with RE and WA | roman velichkin | 1020. Rope | 10 Nov 2019 19:07 | 1 | Radius and coords can be float N can be 1 | WA on test 2,plz help ! | milon603 | 1020. Rope | 27 Apr 2019 15:00 | 2 | #include<stdio.h> #include<math.h> #define PI acos(-1) int main() { int N,i; double r; scanf("%d%lf",&N,&r); double xx,yy,cx,cy,fx,fy,sum=0,tsum=0,y,x,z; y=2*r; x=PI*r/2.0; z=N*(y-x); scanf("%lf%lf",&xx,&yy); fx=xx; fy=yy; for(i=2;i<=N;i++) { scanf("%lf%lf",&cx,&cy); sum=y+sum+sqrt((xx-cx)*(xx-cx)+(yy-cy)*(yy-cy)); xx=cx; yy=cy; if(i==N) { sum=y+sum+sqrt((xx-fx)*(xx-fx)+(yy-fy)*(yy-fy)); break; } } tsum=sum-z; printf("%.2lf\n",tsum); return 0; } | WA#3 | VladimirZagorodskih | 1020. Rope | 15 Mar 2019 02:18 | 5 | WA#3 VladimirZagorodskih 28 Feb 2010 10:57 I couldn't understand my mistake! On my tests it works correct. program project1; var n, i : longint; r, res, x, y, x1, y1, x0, y0 : extended; begin {$IFNDEF ONLINE_JUDGE} assign(input, 'input.txt'); assign(output, 'output.txt'); reset(input); rewrite(output); {$ENDIF} readln(n, r); readln(x, y); x0:=x; y0:=y; res:=2*pi*r; for i:=1 to n-1 do begin readln(x1, y1); res:=res+sqrt(sqr(x1-x)+sqr(y1-y)); y:=y1; x:=x1; end; res:=trunc(res*100)/100; write((res+sqrt(sqr(x1-x0)+sqr(y1-y0))):1:2); {$IFNDEF ONLINE_JUDGE} close(input); close(output); {$ENDIF} end. Re: WA#3 Petrova Valentina [USU] 3 Mar 2011 23:46 I've got the same problem=) May be there is a mistake with counting doubles (extended) and printing the answer... I suppose Edited by author 03.03.2011 23:46 Edited by author 03.03.2011 23:47 On the test 3 n=1, so you need to print the perimeter of nail. Good luck Re: WA#3 Mehedi Imam Shafi 26 Sep 2016 10:51 On the test 3 n=1, so you need to print the perimeter of nail. Good luck thanks helped Re: WA#3 Mozammal Hossain 15 Mar 2019 02:18 for n=1,r=1. What will be the answer? is there any effect on axes position? | Wrong Answer on test #4, C | Regret | 1020. Rope | 11 Sep 2018 16:28 | 2 | #include <stdio.h> #include <math.h> #define M_PI 3.14159 int main() { int N; float R, result = 0; scanf("%d", &N); scanf("%f", &R); if (N == 1) { result = 2 * R * M_PI; } else { float nails[N][2];
for (int i = 0; i < N; i++) { for (int j = 0; j < 2; j++) { scanf("%f", &nails[i][j]); } }
for (int i = 1; i <= N; i++) { result += sqrt((nails[i][0] - nails[i - 1][0]) * (nails[i][0] - nails[i - 1][0]) + (nails[i][1] - nails[i - 1][1]) * (nails[i][1] - nails[i - 1][1])); }
result += (M_PI * 2 * R);
} printf("%.2f", result); return 0; } Edited by author 11.09.2018 16:32 | Please, say. Where I Wrong? (C#) | Serge | 1020. Rope | 15 Jan 2018 05:46 | 1 | Edited by author 15.01.2018 06:34 | What is wrong? / WA#1 | Segrey_Shustov_rus | 1020. Rope | 4 Jun 2017 19:47 | 3 | #include <iostream> #include <iomanip> #include <cmath> using std::cin; using std::cout; using std::endl; using std::setprecision; using std::fixed; int main() { int n; double r,s=0,x,y,x0,y0,xn,yn; cin >> n >> r; if (n==1) { cin >> x >> y; } if (n>1) {
cin >> x >> y; for (int i=1;i<=n-1;i++) { cin >> x0 >> y0; s=s+sqrt((x0-x)*(x0-x)+(y0-y)*(y0-y)); x=x0;y=y0; } s=s+sqrt((xn-x)*(xn-x)+(yn-y)*(yn-y)); } s=s+2*3.1415*r; cout << fixed << setprecision(2) << s << endl; return 0; } DEV-C++ 5.11 Edited by author 04.06.2017 12:53 Thank you. I feel very sorry for such a stupid mistake... | Help me witn test#3!!! | sexygrisha | 1020. Rope | 7 Mar 2017 08:31 | 1 | Edited by author 08.03.2017 14:32 | что не так? | Kovalyshyn Artur | 1020. Rope | 9 Feb 2017 19:16 | 2 | import java.text.DecimalFormat; import java.util.Scanner; /** * Created by user on 06.02.2017. */ public class nytka { public static void main(String[] args) { double c = 0; Scanner sc = new Scanner(System.in); String a = sc.next(); int b = Integer.valueOf(a); String q = sc.next(); double r = Double.valueOf(q); double[] x = new double[b]; double[] y = new double[b]; if (100>b) { if (b > 0){ for (int i = 0; i <= b - 1; i++) { String x2 = sc.next(); double x1 = Double.valueOf(x2); x[i] = x1; String y2 = sc.next(); double y1 = Double.valueOf(y2); y[i] = y1; } for (int i = b - 1; i > 0; i--) { double rez = Math.sqrt(((x[i] - x[i - 1]) * (x[i] - x[i - 1])) + ((y[i] - y[i - 1]) * (y[i] - y[i - 1]))); c = c + rez; } } } double end = Math.sqrt(((x[b-1]-x[0])*(x[b-1]-x[0]))+((y[b-1]-y[0])*(y[b-1]-y[0]))); c = c + end; double rad = (Math.PI*r*r)*(b/2); double endrez = c + rad; DecimalFormat f = new DecimalFormat("#,##0.00"); System.out.print(f.format(endrez)); } } You should clarify error - WA/TLE/runtime; and show test number. b can be 100 by task description. b can be 1 by task description. Conditions like "if (b correct) then solve else do nothing" are useless. Ok, you found b==102. So what? How should you check if WA is because program mistake or because you detected invalid b? Usually if input data can be invalid then some specific program behavior is declared and required. Here - on timus - input is supposed to be always valid, no any input-error-behavior expected. You should fail program in specific way (different from regular WA) this case or remove condition at all. Edited by author 09.02.2017 19:21 | What is wrong? / Что не так? | bulka94 | 1020. Rope | 9 Feb 2017 19:07 | 3 | using System; using System.Threading; using System.Globalization; namespace TestOfCSharp { class Program { static void Main(string[] args) { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int R = int.Parse(input[1]); double sum = 0; for (int i = 0; i < N; i++) { input = Console.ReadLine().Split(' '); sum += double.Parse(input[0]) + double.Parse(input[1]); } sum += 2 * Math.PI * R; Console.WriteLine("{0:F2}", sum); } } } Edited by author 20.12.2013 05:18 (pi*r^2) Edited by author 09.02.2017 18:21 > sum += double.Parse(input[0]) + double.Parse(input[1]); How it should work? Google "points distance formula". | No subject | Mukul Barai | 1020. Rope | 11 Jan 2017 16:18 | 1 | Edited by author 11.01.2017 16:19 Edited by author 11.01.2017 16:21 | What's wrong with it?I am getting WA. | Ram Prakash P | 1020. Rope | 8 Dec 2016 19:54 | 2 | #include <iostream> #include <cmath> #include <iomanip> using namespace std; int main() { int i,j,N,p; std::cin>>N; float cd[N][2],R,dist = 0.0; std::cin>>R;
for(p = 0;p < N;p++) std::cin>>cd[p][0]>>cd[p][1];
i = 0; j = i + 1;
dist = (2 * std::acos(-1.0) * R); while(i < N) { dist += std::sqrt( ( (cd[j][0] - cd[i][0]) * (cd[j][0] - cd[i][0]) ) + ( (cd[j][1] - cd[i][1]) * (cd[j][1] - cd[i][1]) ) ); i++; j = (i + 1) % N; }
std::cout <<std::setprecision(2) << std::fixed <<dist; return 0; } | why it is wrong answer???sad... | xinxin | 1020. Rope | 10 Oct 2016 19:02 | 3 | #include<stdio.h.> #include<string.h> #include<math.h> int main() { double len=0; int n,r,i,j; scanf("%d %d",&n,&r); double a[200][2]; for(i=0;i<n;i++) for(j=0;j<2;j++) scanf("%lf",&a[i][j]); for(i=1;i<n;i++) len=len+sqrt((a[i][1]-a[i-1][1])*(a[i][1]-a[i-1][1])+(a[i][0]-a[i-1][0])*(a[i][0]-a[i-1][0])); len=len+sqrt((a[i-1][1]-a[0][1])*(a[i-1][1]-a[0][1])+(a[i-1][0]-a[0][0])*(a[i-1][0]-a[0][0])); len=len+3.141*2*r; printf("%.2lf",len); fflush(stdin); getchar(); return 0; } I guess the 8th and 9th line. The value of radius is a real number instead of an integer, which is considered to be with decimal point. Thus "double r;" "scanf("%d %lf", ..)" maybe works. Also note. Is pi=3.141 accurate enough? I used 3.14159 in my AC program | Wrong Answer Test #1 Please Help! Why it is wrong? | Evgeniy_Rus | 1020. Rope | 11 Jun 2016 21:42 | 2 | Edited by author 01.06.2014 20:04 | help me pls! | Levan | 1020. Rope | 1 Jan 2016 21:08 | 3 | WA #3 #include <iostream> #include <cmath> #include <map> #include <vector> #include <cmath> #include <stdio.h> #include <iomanip> #include <math.h> using namespace std; int main() { const double PI = acos(-1.); int n; double r; cin >> n >> r;
double x1, y1; cin >> x1 >> y1;
if(n == 1) { cout << fixed << setprecision(2) << r << endl; return 0; }
double vaultx, vaulty; vaultx = x1; vaulty = y1;
double x2, y2; double d; double p = 0.0; for(int i = 0; i < n - 1; i++) { cin >> x2 >> y2;
d = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)); p += d;
x1 = x2; y1 = y2; }
p += sqrt(pow(x1 - vaultx, 2) + pow(y1 - vaulty, 2));
p += 2 * PI * r;
cout << fixed << setprecision(2) << p << endl;
return 0; } if(n == 1) { cout << fixed << setprecision(2) << 2 * PI * r << endl; return 0; } | JAVA, test 3, what is wrong? | ssau6207Voekov | 1020. Rope | 18 Nov 2015 09:43 | 2 | import java.io.*; import java.math.BigInteger; import java.util.*; import static java.lang.Math.*; public class p2015_11_17_DZnaOlympSSAU_Timus1020_Thread implements Runnable { final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null; BufferedReader in; PrintWriter out; StringTokenizer tok = new StringTokenizer(""); void init() throws FileNotFoundException { if (ONLINE_JUDGE) { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } else { in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } } String readString() throws IOException { while (!tok.hasMoreTokens()) { try { tok = new StringTokenizer(in.readLine()); } catch (Exception e) { return null; } } return tok.nextToken(); } int readInt() throws IOException { return Integer.parseInt(readString()); } long readLong() throws IOException { return Long.parseLong(readString()); } double readDouble() throws IOException { return Double.parseDouble(readString()); } public static void main(String[] args) { new Thread(null, new p2015_11_17_DZnaOlympSSAU_Timus1020_Thread(), "", 256 * (1L << 20)).start(); } long timeBegin, timeEnd; void time() { timeEnd = System.currentTimeMillis(); System.err.println("Time = " + (timeEnd - timeBegin)); } public void run() { try { timeBegin = System.currentTimeMillis(); init(); solve(); out.close(); time(); } catch (Exception e) { e.printStackTrace(System.err); System.exit(-1); } } void solve() throws IOException { int numberOfNails=readInt(); double radiusOfNails=readDouble(); if (numberOfNails==1){ out.println(2*PI*radiusOfNails); } else { double xFirstNail = readDouble(); double yFirstNail = readDouble(); double xLastNail=xFirstNail; double yLastNail=yFirstNail; double xOfTheCurrentNail=xFirstNail; double yOfTheCurrentNail=yFirstNail; double lengthOfTheThread=0; for (int currentNail = 2; currentNail <= numberOfNails; currentNail++) { xLastNail=xOfTheCurrentNail; yLastNail=yOfTheCurrentNail; xOfTheCurrentNail=readDouble(); yOfTheCurrentNail=readDouble(); lengthOfTheThread+=(Math.sqrt((xOfTheCurrentNail-xLastNail)*(xOfTheCurrentNail-xLastNail)+(yOfTheCurrentNail-yLastNail)*(yOfTheCurrentNail-yLastNail))); } lengthOfTheThread+=(Math.sqrt((xFirstNail-xOfTheCurrentNail)*(xFirstNail-xOfTheCurrentNail)+(yFirstNail-yOfTheCurrentNail)*(yFirstNail-yOfTheCurrentNail))); lengthOfTheThread+=(2*PI*radiusOfNails); System.out.println( String.format("%.2f", lengthOfTheThread) ); } } } I found a problem. When n==1, program print (2*PI*radiusOfNails), but must ("%.2f",2*PI*radiusOfNails) |
|
|