Общий форум| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения | | Get me output for my input | Bogolyubskiy (MIET) | 1645. Лыжная гонка | 17 янв 2011 01:00 | 2 | | | Help, please! How to solve this problem? Any hits, please (+) | Victor Barinov (TNU) | 1016. Кубик на прогулке | 16 янв 2011 22:06 | 7 | Hello, everybody! I tryed to solve this problem for a week. I DO NOT KNOW WHAT TO DO. I can't think out anything :( Thanks. Dijkstra, Dijkstra... You can make a graph, where every vertex defines a state of the cube (I mean position and rotation) and every edge defines how much does it cost to move from one position to the other, then use Dijkstra, Bellman or whatever you want. I think it will help. Edited by author 02.02.2005 21:21 I think BFS is useable too! I think you can write that iff you have already accepted your solution. I think you can use BFS if numbers on top, bottom, left, right, front and back sides of cube are equal, else Dijkstra or bruteforce :) | | Anybody would like to share some ideas? Thanks. | [York Hotel] 3xian | 1791. Дядя Стёпа и автобусы | 16 янв 2011 21:36 | 7 | Anybody would like to share some ideas? Thanks. Greedy algorithm. For every bus you can comptute "Critical time"=p[i]+t[i]-i. If 1st Bus from "Small Vasyuki" will pass the road after critical time of ith bus from "Small Vasyuki" then ith bus will be late. If jth bus from "Small Vasyuki" will pass the road after (critical time + j-1) then ith bus will be late. If k1-1 buses from "Small Vasyuki" passed and k2-1 buses from "Big Vasyuki" passed then buses from direction with lower critcaltime(of some bus)+k (k1 or k2) are prefered. Edited by author 17.10.2010 14:17 Let 'l' and 'r' be the waiting buses on each direction. Let l[i].f be l[i].t + l[i].p I define the priority between buses as follows: 1. If l[i].t < r[j].t then l[i] should pass first. 2. If l[i].t > r[j].t then r[j] should pass first. ELSE (l[i].t==r[j].t) 3. If l[i].f < r[j].f then l[i] should pass first. 4. If l[i].f > r[j].f then r[i] should pass first. ELSE (l[i].f==r[j].f) 5. If l[i+1] should pass before r[j+1] then l[i] should pass first, else r[j] Can anyone provide a counterexample for this approach? Thanks in advance. --- Nevermind, I was terribly wrong. Edited by author 18.10.2010 22:10 You said about greedy criterion as it is your discovery. More rightly to note math theorem, name of schedulling problem, article in wiki. We have two decks of cards. On each step we dicide from which of them to take one card. For decision we must compare two new states acording two way of choice. You formula is criterion of compairing. But prove is unknown and criterion may be very deep but not absolute greedy. Edited by author 19.10.2010 16:01 Consider the following algorithm: current_time = 0 While there are buses, select a bus i according to Avriskin's priority. If current_time + 1 > ti + pi then answer "NO" else current_time = max(current_time, ti) + 1 and erase the bus. Does anyone see something wrong? I used simple dynamic programming :) | | This problem has fine precalc solution | Cat36 | 1133. Последовательность Фибоначчи | 16 янв 2011 16:40 | 6 | sorry, bad english This sequence can be calculated as k1*((1+sqrt(5))/2)^n +k2*((1-sqrt(5))/2)^n By precalculation we can find such prime p, what: 1. p>4000000000; 2. exist such n, what n*n==5 (mod p) So, this sequence by modulo p can be calculated us k1*a^n + k2*b^n, where a,b,k1,k2 - integer It's all Edited by author 13.07.2009 11:09 Note that if you go this road, you are better using Java, since you will need modPow and modInverse. What about its complexity? | | Hint | hoan | 1492. Папа у Васи 2 | 15 янв 2011 18:12 | 1 | Hint hoan 15 янв 2011 18:12 Use eps= 1e-9.first i don't use eps and get WA#3. this test help me: input: 3 -15000 0 -14999 0 15000 1 output: Yes -15000.0000 0.5000 -14999.0000 0.5000 14999.0000 0.5000 15000.0000 0.5000 -15000.0000 -0.5000 -14999.0000 -0.5000 14999.0000 0.5000 15000.0000 0.5000 thank's to AlexF[USTU] about this note. hope can help you. | | Something strange | tereshinvs | 1701. Остап и партнёры | 15 янв 2011 16:38 | 1 | I submited one file for 3 times and got 3 different results: WA 1, WA 8 and WA 16... Sorry. I think it's my fail. $R+ and $Q+ helped me to get only WA8 No, WA1 with same text again... PS Sorry for spam... Edited by author 15.01.2011 17:34 Edited by author 15.01.2011 17:43 | | Weak tests again | I&K | 1436. Рекламный щит | 15 янв 2011 14:43 | 6 | My solutions based on the wrong assumption that the view angle has only one maximum on abscissa axis (and with some tricks regarding to range of search or partition method in ternary search) pass all tests. Seems that more tests needed. Can the view angle has more than one maximum? Yes. It's zero at negative infinity, increases when moving to positive infinity and than decreases to zero at the point of intersection of the line containing billboard segment and the abscissa axis (assuming the segment itself doesn't intersect the axis). If we continue to move the view point to the positive infinity, the angle increases and decreases again. Now I understand what you meen. I searched maximum on the segment between point of intersection of board with abscissa axis and positive or negative infinity. I considered only this segment and was surprised that there can be more than one maximum on it. Some new tests were added. Now your solutions got WA. But if you change constants in your ternary search you will get AC again. You are right. I've changed "infinity" from 10^6 to 10^4 and got AC. Can you explain why? It's the secont time I decreased segment for search and got AC. | | seems to be impossible in C# | Kolyanich | 1220. Stacks | 15 янв 2011 02:37 | 1 | my simple test solution consist of only int N = int.Parse(Console.ReadLine()); GC.Collect(); Console.WriteLine("400"); Console.WriteLine("200"); Console.WriteLine("300"); and eats 1156 KB, MLE#1 | | why 6# | Mamont | 1574. Математики и скобки | 15 янв 2011 01:14 | 2 | why 6# Mamont 25 сен 2009 23:51 I made testing on computer and all tests have pass Ok Please, say me what is 6 test? test with incorrect sequence, for example "((" must return 0 | | does billboard have a "front side" ? | Kolyanich | 1436. Рекламный щит | 15 янв 2011 00:18 | 2 | In other words, is for input {A, B, C, D} result always equal to result for input {C, D, A, B} ? Yes, program with exchanging points' coordinates got AC. | | My WA7 | Velea Alex | 1244. Джентльмены | 14 янв 2011 20:56 | 1 | My WA7 Velea Alex 14 янв 2011 20:56 try this test too : ) 7 4 4 4 3 2 corrent : -1 my WA was : 0 | | WA #2 Maybe this will help | [MAI] Zhuravlyow Andrei | 1038. Проверка орфографии | 14 янв 2011 16:41 | 1 | Try test "this sentence have one mistake" Answer is 1 | | TLE using BIT --> ??? | Mesh | 1028. Звёзды | 14 янв 2011 15:55 | 8 | Hello, my code gives TLE using a Binary Indexed Tree, and I find the thing quite strange... Here is my solution: #include <iostream> using namespace std; #define MAXX 32001 int tree[ MAXX ]; int l[ 15000 ]; inline void update( int x ) { while ( x <= MAXX ) { tree[ x ]++; x += ( x & -x ); } } inline int query( int x ) { int sum = 0; while ( x > 0 ) { sum += tree[ x ]; x -= ( x & -x ); } return sum; } int main() { int n, x, y; cin >> n; for ( int i = 0; i < n; i++ ) { scanf( "%d %d", &x, &y );
l[ query( x ) ]++;
update( x ); } for ( int i = 0; i < n; i++ ) printf( "%d\n", l[ i ] ); } while ( x > 0 ) { sum += tree[ x ]; x -= ( x & -x ); } - Your prog should be work incorrectly with x = 0. Try x++, y++ after scanf. Explain me, please, why this program works correctly I received AC using algo O(n^1.5). Who can explain me solution O(n*log(n))? Thank you, that saved me ;) Thank you, that saved me ;) I got AC when add x++; and y++; is this solution using one dimensional Fenwick? why it works? => coordinat y's not needed! UPD: "Stars with equal Y coordinates are listed in ascending order of X coordinate." thanks Edited by author 14.01.2011 15:47 Edited by author 14.01.2011 15:52its my TLE3 solution: 2D Fenwik + RB tree (map) #include <iostream> #include <algorithm> #include <vector> #include <map> using namespace std; int N = 0,M = 0; map<int,map<int,int> > Btree; int rsq(int x,int y) { int res = 0; while(x >= 0) { int i = y; while(i >= 0) { res += Btree[x][i]; i = (i & (i + 1)) - 1; } x = (x & (x + 1)) - 1; } return res; } void upd(int x,int y,int d) { while(x < M) { int i = y; while(i < N) { Btree[x][i] += d; i = i | (i + 1); } x = x | (x + 1); } } bool cond(pair<int,int> a,pair<int,int> b) { return a.second < b.second; } int res[15001] = {0}; int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); int n; scanf("%d",&n); vector<pair<int,int> > mp; for(int i = 0; i < n; i++) { int x,y; scanf("%d%d",&x,&y); M = max(M,x); N = max(N,y); x--; y--; mp.push_back(make_pair(x,y)); } for(int i = 0; i < n; i++) upd(mp[i].first,mp[i].second,1); for(int i = 0; i < n; i++) { res[rsq(mp[i].first,mp[i].second)]++; } for(int i = 1; i <= n; i++) { printf("%d\n",res[i]); } return 0; } | | weak tests?... | tereshinvs | 1436. Рекламный щит | 14 янв 2011 01:54 | 2 | My programm search the greatest angle in x in [x1..x2] and got AC. But it's wrong. For example in test 0 3 1 1. PS Maybe i'm wrong Edited by author 13.01.2011 21:20 New tests were added. 84 authors lost AC. Edited by author 14.01.2011 02:29 | | problem with the task\ С++\ Задача 1005 | Giorgi | 1005. Куча камней | 13 янв 2011 23:25 | 6 | program correctly solves all problems, but for some reason the site shows that the program is wrong ... can you explain why? #include<iostream> using namespace std; int main() { double ves_k[20]; int i,num; double t,perv,vtor,res; cin>>num; if(num<1||num>20) goto vozvrat; for(i=0; i<num; i++){ cin>>ves_k[i]; if(ves_k[i]<1||ves_k[i]>10000) goto vozvrat; } if(num!=1){ for(int a=1; a<i; a++) for(int b=i-1; b>=a; b--){ if(ves_k[b-1]>ves_k[b]) { t=ves_k[b-1]; ves_k[b-1]=ves_k[b]; ves_k[b]=t; } } perv=ves_k[num-1]; vtor=ves_k[num-2]; for(i=num-3; i>=0; i--){ if(perv>=vtor) vtor+=ves_k[i]; else perv+=ves_k[i]; } res=perv-vtor; if(res<0) res=-res; } else res=ves_k[0];
cout<<res; vozvrat: return 0; } Edited by author 13.01.2011 02:22 print out your answer with end line. cout << res << endl; Greedy algorithm is wrong! You should check all 2^n situations. Greedy algorithm is wrong! You should check all 2^n situations. why the wrong ... it calculates all the results correctly, you can check yourself You can find some tests on the forum and check yourself that greedy algo is wrong. I know that the greedy algorithm is not always appropriate, but in this case, it should work | | [solved] WA #6, can't figure out what's wrong | qkthePmj | 1019. Перекрашивание прямой | 13 янв 2011 14:52 | 3 | Good time of day. I constantly get WA on test #6. Does anybody know why may this happen? Here's my code, seems to give correct answers for any correct test found in discussions: #include <stdio.h> #include <iostream> #include <map> using namespace std; typedef unsigned int uint; const uint MAX_N = 5000; const bool COLOR_BLACK = false; const bool COLOR_WHITE = true; typedef pair <uint, bool> LinePair; typedef map<uint, LinePair> TLines; TLines lines; void paint(uint c, uint d, const bool clr) { if (c == d) return; uint a, b; bool c2; if (lines.empty()) { lines[c] = LinePair(d, clr); return; } TLines::iterator i = lines.begin(); //пропускаем все отрезки, что левее нашего и не накладываются на него while (c > (i->second).first) ++i; //работаем с накладывающимися отрезками while ((d >= i->first) && (i != lines.end())) { //для удобства написания a = i->first; b = (i->second).first; c2 = (i->second).second; if (a >= c) { if (d >= b) { lines.erase(i); } else if (clr == c2) { d = b; lines.erase(i); } else { lines.erase(i); lines[d] = LinePair(b, c2); } } else { if (d >= b) { if (clr == c2) { c = a; lines.erase(i); } else { (i->second).first = c; } } else if (clr == c2) { c = a; d = b; } else { (i->second).first = c; lines[d] = LinePair(b, c2); } } ++i; } //собственно добавление заданного отрезка lines[c] = LinePair(d, clr); return; } int main() { uint n, b, e; char ch; bool clr; #ifndef ONLINE_JUDGE freopen("input.txt", "rt", stdin); //freopen("output.txt", "wt", stdout); #endif lines.clear(); paint(0, 1e+9, COLOR_WHITE); cin >> n; for (uint i = 0; i < n; i++) { cin >> b >> e >> ch; if (ch == 'b') clr = COLOR_BLACK; else clr = COLOR_WHITE; paint(b, e, clr); } TLines::const_iterator maxLine; uint max = 0; for (TLines::const_iterator i = lines.begin(); i != lines.end(); ++i) { if (((i->second).second == COLOR_WHITE) && ((i->second).first - i->first > max)) { max = (i->second).first - i->first; maxLine = i; } #ifndef ONLINE_JUDGE cout << i->first << '\t' << (i->second).first << '\t' << (i->second).second << endl; #endif } cout << maxLine->first << " " << (maxLine->second).first << endl; return 0; } Edited by author 05.01.2011 03:29 I've got AC. I just needed not to use iterator after erasing it. But the solution is far from optimal, I'm gonna rewrite it. AC #include <stdio.h> #include <iostream> #include <map> using namespace std; typedef unsigned int uint; const uint MAX_N = 5000; const bool COLOR_BLACK = false; const bool COLOR_WHITE = true; typedef pair <uint, bool> LinePair; typedef map<uint, LinePair> TLines; TLines lines; void paint(uint c, uint d, const bool clr) { if (c == d) return; uint a, b; bool c2; if (lines.empty()) { lines[c] = LinePair(d, clr); return; } TLines::iterator i = lines.begin(); //пропускаем все отрезки, что левее нашего и не накладываются на него while (c > (i->second).first) ++i; //работаем с накладывающимися отрезками while ((d >= i->first) && (i != lines.end())) { //для удобства написания a = i->first; b = (i->second).first; c2 = (i->second).second; if (a >= c) { if (d >= b) { i = lines.erase(i); } else if (clr == c2) { d = b; i = lines.erase(i); } else { i = lines.erase(i); lines[d] = LinePair(b, c2); } } else { if (d >= b) { if (clr == c2) { c = a; i = lines.erase(i); } else { (i->second).first = c; i++;
} } else if (clr == c2) { c = a; d = b; i++; } else { (i->second).first = c; lines[d] = LinePair(b, c2); i++; } } } //собственно добавление заданного отрезка lines[c] = LinePair(d, clr); return; } int main() { uint n, b, e; char ch; bool clr; #ifndef ONLINE_JUDGE freopen("input.txt", "rt", stdin); //freopen("output.txt", "wt", stdout); #endif lines.clear(); paint(0, 1e+9, COLOR_WHITE); cin >> n; for (uint i = 0; i < n; i++) { cin >> b >> e >> ch; if (ch == 'b') clr = COLOR_BLACK; else clr = COLOR_WHITE; paint(b, e, clr); } TLines::const_iterator maxLine; uint max = 0; for (TLines::const_iterator i = lines.begin(); i != lines.end(); ++i) { if (((i->second).second == COLOR_WHITE) && ((i->second).first - i->first > max)) { max = (i->second).first - i->first; maxLine = i; } #ifndef ONLINE_JUDGE cout << i->first << '\t' << (i->second).first << '\t' << (i->second).second << endl; #endif } cout << maxLine->first << " " << (maxLine->second).first << endl; return 0; } | | I get AC with 2 paths | Platto Pavel | 1220. Stacks | 13 янв 2011 11:35 | 2 | First, very stupied method: used just 2 arrays for A and B values, 0.609s, 673KB. Second, some hint: used multi-stack and for pointers at next element used unsigned short, 0.031s, 677KB. Sorry, for bad english:-) I used 2 arrays for A and B values and O(n) algorithm | | C/C++ malloc function doesn`t work | atamachi | | 13 янв 2011 00:12 | 3 | Hello, I try to solve problem 1209 with allocating memory, but i receive compilation error. --------------------------------------------------------- e2c33114-a1cd-488e-b50b-9a2950afaee7 e2c33114-a1cd-488e-b50b-9a2950afaee7(8) : error C2143: syntax error : missing ';' before 'type' e2c33114-a1cd-488e-b50b-9a2950afaee7(19) : error C2065: 'AA' : undeclared identifier e2c33114-a1cd-488e-b50b-9a2950afaee7(19) : error C2109: subscript requires array or pointer type e2c33114-a1cd-488e-b50b-9a2950afaee7(24) : error C2065: 'AA' : undeclared identifier e2c33114-a1cd-488e-b50b-9a2950afaee7(24) : error C2109: subscript requires array or pointer type e2c33114-a1cd-488e-b50b-9a2950afaee7(30) : error C2065: 'AA' : undeclared identifier e2c33114-a1cd-488e-b50b-9a2950afaee7(30) : error C2109: subscript requires array or pointer type e2c33114-a1cd-488e-b50b-9a2950afaee7(32) : error C2065: 'AA' : undeclared identifier e2c33114-a1cd-488e-b50b-9a2950afaee7(32) : warning C4022: 'free' : pointer mismatch for actual parameter 1 --------------------------------------------------------- Code example: --------------------------------------------------------- #include <stdio.h> #include <malloc.h> int main() { int N; scanf("%d", &N); int *AA = (int *)malloc(N*sizeof(int)); ... ... ... free(AA); return 0; } --------------------------------------------------------- What the matter ? Thank you for answers. Edited by author 12.01.2011 23:44 This is correct code for C++, not for C, because when using C compiler, only forward var declarations are permited { int N = 0; int* AA = NULL; // ... AA = (int*)malloc(..); // etc. } This is correct code for C++, not for C, because when using C compiler, only forward var declarations are permited { int N = 0; int* AA = NULL; // ... AA = (int*)malloc(..); // etc. } I receive this kind of errors again... Compilation errors. ------------------ 311e64be-7d0c-42db-86d6-9276eb18480e(8) : error C2143: syntax error : missing ';' before 'type' 311e64be-7d0c-42db-86d6-9276eb18480e(9) : error C2065: 'AA' : undeclared identifier 311e64be-7d0c-42db-86d6-9276eb18480e(9) : warning C4047: '=' : 'int' differs in levels of indirection from 'int *' 311e64be-7d0c-42db-86d6-9276eb18480e(20) : error C2065: 'AA' : undeclared identifier 311e64be-7d0c-42db-86d6-9276eb18480e(20) : error C2109: subscript requires array or pointer type 311e64be-7d0c-42db-86d6-9276eb18480e(25) : error C2065: 'AA' : undeclared identifier 311e64be-7d0c-42db-86d6-9276eb18480e(25) : error C2109: subscript requires array or pointer type 311e64be-7d0c-42db-86d6-9276eb18480e(31) : error C2065: 'AA' : undeclared identifier 311e64be-7d0c-42db-86d6-9276eb18480e(31) : error C2109: subscript requires array or pointer type 311e64be-7d0c-42db-86d6-9276eb18480e(33) : error C2065: 'AA' : undeclared identifier 311e64be-7d0c-42db-86d6-9276eb18480e(33) : warning C4022: 'free' : pointer mismatch for actual parameter 1 ------------------ Full code ------------------ #include <stdio.h> #include <malloc.h> int main() { int total_zero, count_zero, i, N, K, s; scanf("%d", &N); int* AA = NULL; AA = (int*)malloc(N*sizeof(int)); s = 0; for( ; N > 0; N--){ scanf("%d", &K); total_zero = count_zero = i = 0; while( 1 ){ i++; if(total_zero == count_zero){ count_zero = 0; total_zero++; if(i == K){ AA[s++] = 1; break; } } if(i == K){ AA[s++] = 0; break; } count_zero++; } } for(i = 0; i < s; i++) printf("%d ", AA[i]); fputc('\n', stdout); free(AA); return 0; } ------------------ error C2143: syntax error : missing ';' before 'type' It is very strange. | | Only some hours to solve it ! I think it's simple problem. Although at the first sight, it's likely hard. | Phan Hoài Nam (Harvey Nash) | 1189. Pairs of Integers | 12 янв 2011 15:27 | 1 | You can go from last digit to the first (the leftmost digit to the rightmost digit). For example : 302 Considering 2 : There are some possibilities: 0 + 2, 1 + 1, 2 + 0, 6 + 6, 5 + 7 ... (first operant is of the larger number, second operant is of the smaller number). Considering 0 : For each possibilities, you try to find out some possibilities that can be combined to produce 0 : 0 + 0... You can try any combinations to produce 0 if two operants used to produce 2 is equal, if they are different, you only have an only way, it reduce very much calculations). Considering 3 : The last digit, you can stop here and consider whether you have achieved a solution. | | There is one useful test here | Burunduk1 | 1037. Управление памятью | 12 янв 2011 14:50 | 4 | It helped me to get AC. Test: 1 + 1 + 1 + 10 . 2 11 . 3 600 + 601 . 1 609 . 2 611 . 3 Right answer: 1 2 3 + + 4 - + - this is giving correct output for me but i am failing in test case 2 why ? can u help this is giving correct output for me but i am failing in test case 2 why ? can u help Thank you very much! I can't get AC without it,either~ |
|
|