Common BoardI have "Time Limit" in test #4. Can you help me. [code deleted] Edited by moderator 01.06.2006 16:14 Of course you got TLE... you algo is O(n)and certainly will get TLE Real Help! First of all we must diminish number of candidate to optimal. MathHelp:if (A^k)%N==1 => fi(N)%k==0 where fi(N)-Eiler function of N Try find in Internet effective algorith for fi(N). we can see that number of candidates diminished from 1000000000 to 2*sqrt(1000000000)~64000 Also if Nod(A,N)>0 print 0. Final trick is using divide recursion when calculating (A^K)%N=>O(log K)-time and don't forget use __int64 when form A*B Edited by author 17.08.2007 02:26 Good point svr! :) But number of ways diminishes to amount of divisors of phi(N) which is way less than 64000, and it's enough to factorize phi(N) itself to get them all recursively. Edited by author 20.08.2008 17:46 NOD is russian for GCD :-) May be test 10 is something like 3 2 1 2 2 3 First player loses The start airport just has one airport connected. So, i wrote my program for a warn-up to commercial programming, but i have a problem at this problem. It gives me wrong answer at the first test and i need your help, guys from this site. Here's the code: // Percentofpeople.cpp : Defines the entry point for the console application. // // Your task is to find the minimal positive integer number Q so that the product of digits of Q is exactly equal to N. #include <iostream> #include <string> int main() { int number; // a number that we need to get std::string answer; std::cout << "Enter the number: " << std::endl; std::cin >> number; for (int i = 9; i >= 2; i--) { while (number > 1 && number % i == 0) // if we can divide number and before it gets to 1 we'll do the following code: { answer = std::to_string(i) + answer; // add the number that divides N completely number /= i; // divide } } if (number == 1) std::cout << answer; else std::cout << -1; std::cin.get(); std::cin.get(); return 0; } I dunno how it looks but i think you'll understand it. So, where is the problem? The problem is with numbers from 1 to 9 or what? First of all, you should remove or comment out this row std::cout << "Enter the number: " << std::endl; The robot doesn't know what this text is supposed to mean, it expects only a numerical answer in the output. After this, you should be getting WA3. What's wrong with me (or with this test)? Usually test #1 is the example. I don't see where the problem could come form. I know there were other people getting TL, could you tell what's the problem. What's wrong with this problem? I translated my code on C# and it got AC 0.015. Help me please.. Why WA 3? I "Use this letter as a formal description of the algorithm and follow the described format of system messages" and still get Wrong Answer.. This test is correct? 7 login a 1 fail: no such user logout a fail: no such user register a 1 success: new user added login a 1 success: user logged in login a 1 fail: already logged in login a 2 fail: incorrect password register a 2 fail: user already exist Maybe you tell a counterexample or hint? Thanks. Edited by author 02.08.2016 21:56 Your last row is: fail: user already exist Correct one is: fail: user already exists Pay attention. Other than that, test seems ok to me. Oh, god... Thank you, Oleg! I got AC. 1) 1 1 1 5 5 0 0 2 2 0 10 => OK 3 2) 2 1 1 2 2 -1 5 0 0 0 1 100 0 0 100 54 45 67 76 99 99 => OK 2 4 3) 2 1 2 3 4 5 6 7 8 9 10 11 12 -13 -14 -15 -16 -17 -18 -19 -20 => OK 1 2 В задаче, кстати, нифига не понятен случай n=1,т.к. понятие УВАЖЕНИЯ введено для ПАР. Но в тестах подразумевается, что человек сам себя уважает(хотя пары для него нет). Can you please explain - why the code below generates Runtime error during checking ? Thanks, import java.util.*; public class Task0002 { public static void main(String[] args) { Scanner scin = new Scanner(System.in); ArrayList<Double> values = new ArrayList<Double>(); String strIn; int lenScin = 0; do { strIn = scin.nextLine(); lenScin += strIn.length(); strIn = strIn.trim(); strIn = strIn.replaceAll(" ", " ");
// Process the line if(strIn.length()>0) { for(String s: strIn.split(" ")) { values.add(Double.parseDouble(s)); }; };
} while(scin.hasNextLine() && lenScin <= 262144); scin.close();
for(int i = values.size()-1; i>=0; i--) { double val = (double)values.get(i); System.out.println(Math.sqrt(val) + " "); };
} } Edited by author 02.08.2016 12:29 May be you also need to replace '\n' ? what test? I think you loose precision. Try to find simple solution without accuracy loosing. Yogendra Singh Chouhan Login [3] 27 Jul 2016 22:14 I wanted to see my previous submissions but I cant seem to find the login page. What to do? Oleg Baskakov Re: Login [2] 28 Jul 2016 00:09 Yogendra Singh Chouhan Re: Login [1] 2 Aug 2016 02:09 In the link you mentioned for last submissions, I can only see last two of my submissions but I remember solving other problems too, which I cant see. #include<iostream> #include<iomanip> #include<math.h> using namespace std; int main() { unsigned long long n; double a[128*1024]; int i=0; while(cin>>n) { a[i]=sqrt(n); i++; } cout<<setprecision(4)<<fixed; for(int b=i-1;b>=0;b--) { cout<<a[b]<<endl; } return 0; } Edited by author 01.08.2016 20:26 Hi I got MLE #7. Why?
#include <cstdio> #include <algorithm> int a[250000]; int main() { int n; std::scanf("%d", &n); for (int i = 0; i < n; i++) std::scanf("%d", a + i); if (n % 2) { std::nth_element(a, a + n / 2, a + n); std::printf("%d\n", a[n / 2]); } else { std::nth_element(a, a + n / 2, a + n); std::nth_element(a, a + n / 2 - 1, a + n); std::printf("%.1f\n", (a[n / 2] + .0 + a[n / 2 - 1]) / 2); } return 0; }
>int a[250000]; Empty helloworld already shows 100+ kb, so 250000 is not an option. The only way is to use ~200000 or so numbers. So why I don't have MLE #1? Because first 6 tests have a small N, and thus most of this array isn't initialized and used. Try to fill your array with random numbers in the beginning of your main() and you'll have MLE #1. By the way. std::nth_element(a, a + n / 2, a + n); // (1) std::nth_element(a, a + n / 2 - 1, a + n); // (2) Are you sure it must work? I suppose value found on step 1 can be moved on step 2. #include <stdio.h> #include<math.h> int main() { int n; double t[100]; scanf("%d", &n); int i; for(i=1; i<=n;i++){ scanf("%lf", &t[i]); } for(i=n; i>0; i--){ printf("%lf\n",sqrt(t[i])); } return 0; } Please read task and example carefully. 1) scanf("%d", &n); - do you see n in example input? 2) double t[100]; - where in task did you find "100" limitation? just in case thats the code #include <stdio.h> #include <stdbool.h> #include <math.h> static inline double dot(const double* a, const double* b) { return a[0]*b[0] + a[1]*b[1] + a[2]*b[2]; } static inline double mind(double a, double b) { return a < b ? a : b; } static inline double maxd(double a, double b) { return a > b ? a : b; } static inline bool intersect_ray_sphere(const double* p, const double* dir, const double* sc, double sr, double* t) { const double m[] = {p[0] - sc[0], p[1] - sc[1], p[2] - sc[2]}; const double b = dot(m, dir), c = dot(m,m) - sr*sr; if(c > 0 && b > 0) return false; const double discr = b*b - c; if(discr < 0) return false; *t = maxd(0, -b - sqrt(discr)); return true; } static inline bool intersect_moving_sphere_sphere(const double* c0, double r0, const double* v0, const double* c1, double r1, const double* v1, double* t) { // to transform to moving sphere vs stationery sphere: subtract v1 from both v1,v0 // to transform to ray-sphere intersection: expand sphere1 by radius of s1 const double r = r0+r1; double v[] = { v0[0] - v1[0], v0[1] - v1[1], v0[2] - v1[2] }; double vlen = sqrt(dot(v,v)); if(vlen < 1e-6) return false; v[0] /= vlen, v[1] /= vlen, v[2] /= vlen; bool ret = intersect_ray_sphere(c0, v, c1, r, t); *t /= vlen; return ret; } int main() { unsigned N; double Rd; scanf("%u %lf\n", &N, &Rd); double c[N][3], v[N][3]; for(unsigned i = 0, n = N ; i < n ; ++i) scanf("%lf %lf %lf %lf %lf %lf\n", &c[i][0], &c[i][1], &c[i][2], &v[i][0], &v[i][1], &v[i][2]); const double R = Rd / 2.0; double min_t; bool have_intersection = false; unsigned min_pair1, min_pair2; for(unsigned i = 0, n = N ; i < n ; ++i) for(unsigned j = i+1, m = N ; j < m ; ++j) { double t; bool intersect = intersect_moving_sphere_sphere(c[i], R, v[i], c[j], R, v[j], &t); if(intersect && (t < min_t || have_intersection == false)) min_t = t, min_pair1 = i, min_pair2 = j, have_intersection = true; } if(have_intersection) printf("ALARM!\n%.3f %u %u\n", min_t, min_pair1+1, min_pair2+1); else printf("OK\n"); return 0; } Edited by author 31.07.2016 21:50 Edited by author 31.07.2016 21:51 Edited by author 31.07.2016 22:01 program arrays; var k:array[1..20]of longint; d:array[0..20]of longint; n:integer; s:longint; procedure init; var i:integer; begin readln(n,s); for i:=1 to n do readln(d[i]); d[0]:=s; end; procedure solve; var i:integer; begin k[n]:=d[n-1]-1; for i:=n-1 downto 1 do k[i]:=(d[i-1] div d[i])-1; for i:=1 to n-1 do write(k[i],' '); writeln(k[n]); end; begin init; solve; end. const maxn=20; var w,n,i:longint; a,b:array [1..maxn] of longint; begin readln(w,n); for i:=1 to w do readln(a[i]); n:=n-1;i:=1; repeat b[i]:=n div a[i]; n:=n mod a[i]; inc(i); until n=0; for i:=1 to w do write(b[i],' '); end. > const maxn=20; > var w,n,i:longint; > a,b:array [1..maxn] of longint; > begin > readln(w,n); > for i:=1 to w do readln(a[i]); > n:=n-1;i:=1; > repeat > b[i]:=n div a[i]; > n:=n mod a[i]; > inc(i); > until n=0; > for i:=1 to w do write(b[i],' '); > end. #include <fstream.h> void main() { int n, s, t, i; cin >> n >> s; for(i=0; i<n; i++) { cin >> t; cout << (s / t) - 1 << " "; s = t; } } var n,s,d:longint; begin readln(n,s); dec(s); for n:=1 to n do begin readln(d); write(s div d,' '); s:=s mod d; end; end. What is the use of showing you and your code off ? Instead of getting proud of yourself, giving clarification is much more better Instead of getting proud of yourself and giving right code, giving clarification is much more better This problem may have four answers: inf, 0, 1, 2 :) Hi, I've solved the problem easily on C, but can't solve it on C# (almost the same code), getting Runtime Error on #2. Can someone point out what's wrong in my code? using System; namespace Application { class MainClass { public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] pos = new int[3]; for(int i=0; i<n; i++) { string[] s = Console.ReadLine().Split(' '); int ind = s[0][0] - 'X'; pos[ind] += int.Parse(s[1]); }
while(true) { if(pos[0] * pos[2] > 0) { int sign = pos[0] / Math.Abs(pos[0]); int min = Math.Min(Math.Abs(pos[0]), Math.Abs(pos[2])); pos[0] -= sign * min; pos[1] += sign * min; pos[2] -= sign * min; } else if(pos[0] * pos[1] < 0) { int sign = pos[0] / Math.Abs(pos[0]); int min = Math.Min(Math.Abs(pos[0]), Math.Abs(pos[1])); pos[0] -= sign * min; pos[1] += sign * min; pos[2] -= sign * min; } else if(pos[1] * pos[2] < 0) { int sign = pos[2] / Math.Abs(pos[2]); int min = Math.Min(Math.Abs(pos[1]), Math.Abs(pos[2])); pos[0] -= sign * min; pos[1] += sign * min; pos[2] -= sign * min; } else { break; } } int nOfDir = 0; if(pos[0] != 0) nOfDir++; if(pos[1] != 0) nOfDir++; if(pos[2] != 0) nOfDir++; Console.WriteLine(nOfDir); if(pos[0] != 0) Console.WriteLine("X " + (-pos[0]).ToString()); if(pos[1] != 0) Console.WriteLine("Y " + (-pos[1]).ToString()); if(pos[2] != 0) Console.WriteLine("Z " + (-pos[2]).ToString()); } } } To get AC instead of Console.ReadLine() I used Console.In.ReadToEnd().Split(new char[] { ' ', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries) I just use the scanf to read the input data. Why do I also receive a TLE response? |
|