Common Board| Show all threads Hide all threads Show all messages Hide all messages | | who know test 5,,,help!!! | Virtuoz | 1800. Murphy's Law | 18 Jan 2011 03:50 | 2 | here is my code int main() { double l, h, w,N,angle; double P=3.14; double g=9.81,t,speed; cin>>l>>h>>w; t=sqrt(2*h/(g*100)); speed=w/60; N=t*speed; angle=N*360; while(angle>360) { angle=angle-1; } if(angle>90 && angle<270) cout<<"bread"; else cout<<"butter"; //system("pause"); } i think you need to remember about l in counting time te total hight should be h-0,5l because you must remember that after h-0,5l it can spin arround. and you have few more mistakes but i'm not sure of that because my one its not perfect to | | getting WA2 please help | Anupam Ghosh,Bengal Engg and Sc Uni,MtechIT,2006-09,India | 1510. Order | 18 Jan 2011 00:03 | 3 | is the problem as easy as it seems or there is some trick? ACM problems r never easy except a very few which i have solved.please provide some test cases. now getting TLE for test 19 can somebody please suggest some hints to solve the problem. try to check the variant when n = 1 | | Please add this test. | Zayakin Andrey[PermSU] | 1202. Rectangles Travel | 17 Jan 2011 19:18 | 1 | #include <cstdio> int main() { freopen("output.txt", "w", stdout); printf("99999\n"); printf("0 0 10 100\n"); for(int i =0 ; i < 99998; ++i) { printf("%d %d %d %d\n", (i+1)*10,0,(i+2)*10 , 100); } return 0; } My early solution get AC, but must get TL. Edited by author 19.01.2011 16:05 | | Sample output is wrong!!! (i thing) | Karavaev Artem | 1136. Parliament | 17 Jan 2011 15:29 | 3 | It seems to me, that in a problem a wrong example (Sample output). It should be 25 27 22 10 20 21 5 7 1 Please correct me if I something has not understood. thank. > It seems to me, that in a problem a wrong example (Sample output). > It should be 25 27 22 10 20 21 5 7 1 > Please correct me if I something has not understood. > thank. Edited by author 17.01.2011 15:31 | | Get me output for my input | Bogolyubskiy (MIET) | 1645. Ski Race | 17 Jan 2011 01:00 | 2 | | | Help, please! How to solve this problem? Any hits, please (+) | Victor Barinov (TNU) | 1016. Cube on the Walk | 16 Jan 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. Uncle Styopa and Buses | 16 Jan 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. Fibonacci Sequence | 16 Jan 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. Vasya's Dad 2 | 15 Jan 2011 18:12 | 1 | Hint hoan 15 Jan 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. Ostap and Partners | 15 Jan 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. Billboard | 15 Jan 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 Jan 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. Mathematicians and brackets | 15 Jan 2011 01:14 | 2 | why 6# Mamont 25 Sep 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. Billboard | 15 Jan 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. Gentlemen | 14 Jan 2011 20:56 | 1 | My WA7 Velea Alex 14 Jan 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. Spell Checker | 14 Jan 2011 16:41 | 1 | Try test "this sentence have one mistake" Answer is 1 | | TLE using BIT --> ??? | Mesh | 1028. Stars | 14 Jan 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. Billboard | 14 Jan 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. Stone Pile | 13 Jan 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. Line Painting | 13 Jan 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; } |
|
|