Общий форумuses crt; var s:string; a,k:longint; begin read(a); k:=9; repeat if a mod k=0 then begin s:=chr(k+48)+s; a:=a div k; end else k:=k-1; until k=1; if a=1 then begin write(s); end else write('-1'); end. Edited by author 13.05.2014 06:59 Edited by author 13.05.2014 07:22 Edited by author 13.05.2014 07:23 Hint #1: The mouse or the cheese can be less than 10cm from the polygons Hint #2: Be careful of your first segment from the mouse or the last segment from the cheese. If you do not check correctly, they might cross a polygon. For example, think of the case of a very thin rectangle with the long side called A and a mouse that is less than 10cm from the rectangle. You have to make sure that the mouse runs to side A not the side opposite to A. if n=1(k any) we need 2 minuten, but when n=2 , k=5 we need 1 minutes. Why??? this is bug, it is imposible. if i have n = 1 and k = 10000, i need two minutes i found the bug Edited by author 13.05.2014 22:15 Any ideas, what's wrong? (I used greedy alogorithm) I've this test wrong too. Here's my code: #include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <utility> #include <set> #include <ctime> using namespace std; #define forn(i,n) for (int i = 0; i < (int)n; i++) struct bus { int l, r, type, num; friend bool operator<(const bus &bus1, const bus &bus2) { if (bus1.type != bus2.type) { return bus1.r < bus2.r; } else { return bus1.num < bus2.num; } } }; int n, m; vector<pair<int, int> > v1, v2; bus mas[300000]; multiset<bus> s; multiset<bus>::iterator iter; int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); scanf("%d", &n); v1.resize(n); forn(i,n) { scanf("%d%d", &v1[i].first, &v1[i].second); v1[i].second += v1[i].first - 1; } scanf("%d", &m); v2.resize(m); forn(i,m) { scanf("%d%d", &v2[i].first, &v2[i].second); v2[i].second += v2[i].first - 1; } for (int i = 1; i <= n; i++) { mas[i].l = v1[i - 1].first; mas[i].r = v1[i - 1].second; mas[i].type = 1; mas[i].num = i; } for (int i = 1; i <= m; i++) { mas[i + n].l = v2[i - 1].first; mas[i + n].r = v2[i - 1].second; mas[i + n].type = 2; mas[i + n].num = i; } int p1 = 1, p2 = n + 1; int t = min(mas[p1].l, mas[p2].l); while ((p1 <= n && p2 <= m + n) || t <= 230000000) { while (p1 <= n && mas[p1].l <= t) { if (mas[p1].r < t) { printf("NO"); return 0; } else { s.insert(mas[p1++]); } } while (p2 <= m + n && mas[p2].l <= t) { if (mas[p2].r < t) { printf("NO"); return 0; } else { s.insert(mas[p2++]); } } iter = s.begin(); if (iter != s.end()) { if ((*iter).r < t) { printf("NO"); return 0; } else { s.erase(iter); } t++; } else { t = 230000000; if (p1 <= n) { t = min(t, mas[p1].l); } if (p2 <= n + m) { t = min(t, mas[p2].l); } if (t == 230000000) { printf("YES"); return 0; } } } printf("YES"); //printf("%.5lf", 1.0 * clock() / (1.0 * CLOCKS_PER_SEC)); } Where's bug? 1 1 3 2 1 4 1 2 answer is "YES" WereWolf can eat his sister or brother. But He cannot eat his father and mother, also grandfather ... so on....grandmother... Sample 5 4 4 1 4 1 2 Why answer is 3 2 but not 3 1 ? 2*1+1*2 <= 4 (p = 4, p — максимальная сила всплеска, которую маги ещё могут пережить, пережить тоесть включно) ??? To kill the weakest 3 coins with one spell it would have to have spell power 2, which means you get 3*2 = 6 > 4 damage reflected. I strongly dislike being forced to specific languages. Java is too slow to solve the problem? OK. Why ban it? var n:integer; begin while not seekeof do begin read(n); write(sqrt(n):0:4); end; end. Wrong answer, but why??? #include <cmath> #include <cstdio> #include <iostream> using namespace std; typedef long long LL; int main() { LL N,A,P,up; cin>>N; up=(LL)ceil((1.00+sqrt(1.00+8.00*(double)N))/2.00); P=up; while (((2*N)%P)!=0) { P--; }
A=(((2*N)/P)-P+1)/2;
cout<<A<<" "<<P<<endl; } This is my code...but this is giving WA on #2. I can't understand the reason. It seems to give correct answer on the tests I do on my computer..?!
At first sight, I strongly suggest you to avoid operating repeteadly with floating points, the little errors will accummulate, and WA comes to the order. at second sight the logic is just not right. Look, I got the same algorithm that a dude with TLE at test9, but with a less complex break condition. private static int sq(long A,long N){ double aux= Math.sqrt( ((A*A)<<2) - (A<<2) + 1 + 8*N); int r = (int)aux; if ((double)r==aux) return r; else return -1; } public static void main (String[]args){ Scanner s=new Scanner(System.in); int N= s.nextInt(); long A=1,P=1,root=0; while (true){ root= sq(A,N); if (root==-1) A++; else{ P= (1-(A<<1)+root)/2; break; } } System.out.println(A+" "+(P)); } import java.util.Scanner; public class _1011 { public static void main(String[] args) throws Exception { Scanner s = new Scanner(System.in); double p, q; p = Double.parseDouble(s.nextLine()); q = Double.parseDouble(s.nextLine()); p /= 100; q /= 100; answer(p, q, 1, 1, 0); } public static void answer(double p, double q, double m, double mp, long n) { long t = (long) (m / q) + 1; if (p * t < mp) { System.out.println(n + t); } else { answer(p, q, 1 - q * t + m, 1 - p * t + mp, n + t); } } } import java.util.Scanner; public class _1048 { public static void main(String[] args) throws Exception { Scanner s = new Scanner(System.in); int n, ind, i; n = s.nextInt(); int[] a = new int[n]; int[] b = new int[n]; int[] res = new int[n]; for (i = 0; i < n; i++) { a[i] = s.nextInt(); b[i] = s.nextInt(); } for (i = n - 1; i >= 1; i--) { ind = (a[i] + b[i]) / 10; if (ind > 0) { res[n - i] = ind; res[n - i - 1] += (a[i] + b[i]) % 10; } else res[n - 1 - i] += a[i] + b[i]; if (res[n - i - 1] >= 10) { res[n - i] += res[n - i - 1] / 10; res[n - i - 1] = res[n - i - 1] % 10; } } res[n - 1] += a[0] + b[0]; for (i = n - 1; i > -1; i--) System.out.print(res[i]); } } [delete] Edited by author 07.05.2014 10:53 Edited by author 07.05.2014 10:53 import java.util.Scanner; public class _1645 { public static void main(String[] args) { Scanner s = new Scanner(System.in); int i, j; long n, min, max; n = s.nextInt(); long[] a = new long[(int) n]; for (i = 0; i < n; i++) { a[i] = s.nextInt(); } for (i = 0; i < n; i++) { min = 1; max = n; for (j = 0; j < n; j++) { if (j > i & (a[j] < a[i])) { min++; } if (j < i & (a[j] > a[i])) { max--; } } System.out.println(min + " " + max); } } } Here is the formula to find the 1 numbers: (sqr(n)+n+2)/2 n varies from 0 to .... Here is the code for the mentioned task. I use Dev-Pascal and when I run it on my computer there is no any problem, but when I send it to the server the following error occurs: "Runtime error (access violation)" MY CODE: program TASK_1209; var b, x, y: string; a: real; i, n, w, k: integer; begin x := '1' + x; for i:=1 to 10 do begin a := exp(ln(10) * i); str(trunc(a), b); x := x + b; end; readln(k); n := 0; repeat n := n + 1; readln(w); y := y + x[w] + ' '; until n = k; write(y); readln; end. import java.util.Scanner; public class _1506 { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n, k, j, i; n = s.nextInt(); k = s.nextInt(); k = (n + k - 1) / k; int[] a = new int[n]; for (i = 0; i < n; i++) { a[i] = s.nextInt(); } for (j = 0; j < k; System.out.println(""), j++) for (i = j; i < n; i += k) { System.out.print(" " + a[i]); } } } First: When N is 0 exit the program and print nothing. Second: get attention in "range" of Array or vector (or what you use to save the team name) test 3: N = 0; test 5: N = any, but output is nothing. Hope it help you! Backtracking works on this problem) I wrote code, using it, and i thought it'll got TL. But when I tried, it get AC) (Sorry for my poor english) The running time of a simple backtracking search will depend on the move search order you use. For example, this order: moves = [ a, e, f, b, c, g, h, d ] where a = (1,-2) b = (1,2) c = (-1,2) d = (-1,-2) e = (2,1) f = (2,-1) g = (-2,1) h = (-2,-1) works great for n = 7, but not 6 or 8. |
|