Common BoardI solve the system by the Gauss method, but the 16-th test he passes. Then I tried to take first the Gauss method and the results of the initial matrix method of Seidel (iterative algorithm), but it does not always converge and the result becomes invalid even before the 16-second test. What is there a problem? I've tried the heap one, I've done everything I could, but still TLE. I guess there should be some tricky part or my implementation error. what have you guys done to avoid the TLE? I use heap to arrange the time, everytime there is a new timestamp that is different from the last one, I check the heap and delete the out-of-time nodes. I also use a bool array to record the existance of a node, as well as a link table to record the next label that can be used. I don't know why I got TLE all the time... #include<stdio.h> #include<iostream> using namespace std; char s[10001],str[80]; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif int j = 0; memset(s,'\0',sizeof(s)); while(gets(s)) { int len = strlen(s); int i = 0; while(i<len) { if(s[i]=='>') { j++; if(j>79)j=0; } else if(s[i]=='<') { j--; if(j<=0)j=0; } else if(s[i]!='\n' && s[i]!='\0') { str[j] = s[i]; j++; } i++; } memset(s,'\0',sizeof(s)); } for(int i = 0;i<80;i++) printf("%c",str[i]); return 0; } "at the beginning the e-screen contains 80 spaces" I add in begin memset(str,' ',sizeof(80)); I get WA#1 to former =( Thank you!!!You help me!!!I got AC!!!=) New tests have been added. 91 authors have lost AC after rejudge. Thanks to Sergey Kopeliovich. you should find nearest prime number to J if the number doesnt exist you should find odd number because even number's divisor sum is bigger:) Edited by author 30.05.2010 18:53 Edited by author 30.05.2010 18:53 Edited by author 30.05.2010 18:54 var a,c,b : array[1..10000]of longint; var n : longint; procedure sort(m,t:longint); var y,i,j,w:longint; begin i:=m;j:=t;y:=a[(m+t)div 2]; repeat while a[i]<y do inc(i); while a[j]>y do dec(j); if i<=j then begin w:=a[i];a[i]:=a[j];a[j]:=w; inc(i);dec(j); end; until i>j; if i<t then sort(i,t); if m<j then sort(m,j); end; PRocedure red; var i,j : longint; begin readln(n); for i:=1 to n do read(a[i]); sort(1,n); end; {=-=================} PRocedure get; var i,sum1,sum2 : longint; begin sum1:=a[n]; sum2:=0; for i:=n-1 downto 1 do begin if sum1>=sum2 then begin sum2:=sum2+a[i]; end else begin sum1:=sum1+a[i]; end; end; writeln(abs(sum1-sum2)); end; {=-=================} BEgin red; get; end. Try brudforce =) It realy works What does brudforce mean,my english is poor Try brudforce =) It realy works Bruteforce REALLY works in 0.14, 130K:)) 2Aybek_TKTL: bruteforce in this case is full search through all possible variants (if u are Russian, then полный перебор). I have WA at #5 test too. import java.util.Scanner; public class Queue { public static void main(String[] args) { Scanner input = new Scanner(System.in); koor A[] = new koor[50]; int i, j, st; int vaxt = 0; int temp, temp1, temp2; int max = 0; int N = input.nextInt(); for (i = 1; i <= N; i++) { A[i] = new koor(); A[i].T1 = input.nextInt(); A[i].T2 = input.nextInt(); A[i].T3 = input.nextInt(); } for (i = 1; i <= N - 1; i++) { for (j = 1; j <= N - 1; j++) { if (A[j].T1 > A[j + 1].T1) { temp = A[j].T1; A[j].T1 = A[j + 1].T1; A[j + 1].T1 = temp; temp1 = A[j].T2; A[j].T2 = A[j + 1].T2; A[j + 1].T2 = temp1; temp2 = A[j].T3; A[j].T3 = A[j + 1].T3; A[j + 1].T3 = temp2; } } }
st = A[1].T1 + A[1].T2; if (st > A[1].T3) { vaxt = st - A[1].T3; } for (i = 2; i <= N; i++) { if (st > A[i].T1) { st += A[i].T2; if (st > A[i].T3) { vaxt = st - A[i].T3; } } else { st = A[i].T1 + A[i].T2; if (st > A[i].T3) { vaxt = st - A[i].T3; } } if (vaxt > max) { max = vaxt; } } System.out.println(max); } } class koor { int T1; int T2; int T3; } Edited by author 30.05.2010 15:45 The only input line contains two integers separated with a space: N and K (0 < N ≤ 109, 1 < K ≤ 109). and There's a Test case with K = 1 which made me got 2 wrong answer...So funny big_deal 1014 28 May 2010 19:56 could anyone tell me,what is test 1 in 1014 ? 4 6 1 2 2 2 3 2 3 4 2 4 1 2 1 3 1 2 4 1 Cost: 4 Cost: 4 1: why not 1>4(cost 2, minimum. Description says if transition between A > B is possible then B > A is possible too) That gives answer: 2 2:1>3(cost 1) then 3>4(cost 2), 1+2=3 That gives answer: 3 Anyone mind explaining why its 4 and 4 in sample? "choose the minimal possible set of trans-planet passages so that he could pass from any planet to any other one via those passages" If you choose 1-3 and 3-4, you can't reach planet 2 from the other planets. Anybody knows? Edited by author 25.05.2010 20:52 There is no answer like NO; Please explain me this problem>Thank!!! Give me some tests,please,because I think I don't understand problem correctly,please.Thank in advance!!! Edited by author 16.02.2008 20:28 this problem seems hard at first, but it's very easy 2 4 5 3 Red Yellow Blue >40 3 4 5 3 Red Yellow Blue >60 3 4 5 3 Red Yellow >36 3 4 5 2 Red Yellow >20 3 4 5 2 Blue Thank you for tests!!!I have just last questions:can k be more than 3(k>3)and in 3-th & 5-th of your tests why there is only 2(in 3-th test) and 1(in 5-th test) strings,while k=3(in 3-th test) and k=2(in 5-th test). Thank in advance!!! Edited by author 17.02.2008 00:30 no, k <= 3 and I gave you some wrong tests) 3 4 5 3 Red Yellow >36 - can't be(k must be 2) 3 4 5 2 Blue Red >12 Thank you very much!!!I get AC!!! Edited by author 17.02.2008 19:33 Test is wrong (Alexander (201 - P TNU)). If input: 3 4 5 2 Red Yellow Output must be 20, not 36. Edited by author 25.05.2010 21:56 What I did was of course order 3 but it got AC in 0.062sec and 1133 kb memory. I wonder why n^3 would need .8 sec or TLE. I may do it in n^2 but please tell me about the infamous O(n) algo. What is the test 25? I've already solved the problem, but I want know why my first solution is wrong... Because Sandro can not teleport to the point where a demon is located. Anybody use this? It's right formula or no? a1:=(n*a(0)+a(n+1)-sum(i=1 to n+1 , c(i)*2^i))/(n+1) ? Edited by author 31.10.2009 19:00 Hi, if n = N+1, then formula is a1 = an/n + a0*(n-1)/n - sum(i=1, N, 2*(n-i)*ci) Your formula is OK except in a1 = an/n + a0*(n-1)/n - sum(i=1, N, 2*(n-i)*ci), the term sum(i=1, N, 2*(n-i)*ci) should divide by n a1 и a2 - соседи? (у них есть общая вершина) If no, please, tell me, where can I find class BigInteger. Such one, that I wrote myself, works too slow :( I think it's possible to solve it without BigNum.The question asks you to mod m...so it can't be over m Yes, but the number p can be too big, and it's impossible to calculate the answer faster, than O(n^2), where n = [lg(p)], i.e. it is a very slow method. Does anybody know faster one? Edited by author 20.03.2010 02:31 It is possible to solve this problem in O(lg(p) * ln(n)). And you don't need long arithmetic, just do all the computations modulo p. 64 bit integer is enough in this case. It can be even solved in O( lg(p) + ln(n) ) #include <iostream> #include <algorithm> #include <string> #include <cctype> #include <iomanip> #include <cmath> using namespace std; #define MaxN 500000 #define f0(i,n) for(i=0;i<n;i++) #define f1(i,n) for(i=1;i<n;i++) char x[MaxN]; int main() { int i=0; char c; while((c=getchar())!='\n') { x[i]=c; i++; } long int total=0,t=1; int j,k,l,m; m=i; int count=0; int counter; f1(i,MaxN) { if(i<10 && i>=0)t=1; if(i<100 && i>=10)t=2; if(i<1000 && i>=100)t=3; if(i<10000 && i>=1000)t=4; if(i<100000 && i>=10000)t=5; f0(j,m) { total=0; counter=1; for(k=j;k<j+t;k++) { l=x[k]-48; total+=pow(10,t-counter)*l; counter++; } if(total==i) { count++; break; } } if(count==0) { cout<<i<<endl; break; } count=0; } return 0; } Thanks!!! |
|