Common Board| Show all threads Hide all threads Show all messages Hide all messages | | Hint | [SPbSU ITMO] alant | 1347. Blog | 2 Apr 2009 15:08 | 1 | Hint [SPbSU ITMO] alant 2 Apr 2009 15:08 One blogger can mark another as his friend more than once. Of course, you should print his name in the list of friends only once. Good luck! | | I have Acc at 0.218 c, to | Валентин | 1013. K-based Numbers. Version 3 | 2 Apr 2009 10:56 | 1 | I believe that after some simplifications can be obtained even faster code | | To admin | yuyan | 1508. Japanese Puzzle | 2 Apr 2009 02:04 | 2 | Can you give me a hint about TEST#27?I have been checked my program for 2 days.And I can't find what's wrong with my program.I'm crazy! Here is my program: program puzzle; const maxn=410; var d,f:array [0..maxn,0..maxn] of longint; b,e,s,a:array [0..maxn] of longint; t,vis:array [0..maxn] of boolean; ch:array [0..maxn] of char; i,j,p,k,l,m,n:longint; procedure init; begin read(n,m); for i:=1 to m do read(a[i]);readln; for i:=1 to n do begin repeat read(ch[i]); until ch[i] in ['?','X','.']; end; readln; end; procedure solve; begin for i:=1 to n do begin s[i]:=s[i-1]; if ch[i]='X' then inc(s[i]); end; fillchar(d,sizeof(d),-$3f); d[n+1,m+1]:=0; k:=n; for i:=n downto 1 do begin for j:=m+1 downto 1 do begin d[i,j]:=d[i+1,j]; if (j=m+1) or (i+a[j]-1>n) or (ch[i]='.') then continue; if i+a[j]+1>n then l:=n+1 else l:=i+a[j]+1; if (i+a[j]-1<=k) and (d[l,j+1]>=0) and (d[l,j+1]+s[i+a[j]-1]-s[i-1]>d[i,j]) then d[i,j]:=d[l,j+1]+s[i+a[j]-1]-s[i-1]; end; if ch[i]='.' then k:=i-1; end; if d[1,1]<>s[n] then begin writeln('Impossible');exit; end; fillchar(f,sizeof(f),-$3f); f[0,0]:=0; k:=1; for i:=1 to n do begin for j:=0 to m do begin f[i,j]:=f[i-1,j]; if (j=0) or (i<a[j]) or (ch[i]='.') then continue; if i-a[j]-1<1 then l:=0 else l:=i-a[j]-1; if (i-a[j]+1>=k) and (f[l,j-1]>=0) and (f[l,j-1]+s[i]-s[i-a[j]]>f[i,j]) then f[i,j]:=f[l,j-1]+s[i]-s[i-a[j]]; end; if ch[i]='.' then k:=i+1; end; fillchar(vis,sizeof(vis),false); fillchar(t,sizeof(t),false); fillchar(b,sizeof(b),255); p:=0; for i:=1 to n do begin if ch[i]='.' then begin p:=i;continue; end; for j:=1 to m do begin if i-a[j]+1<=p then continue; if i+2<=n then k:=d[i+2,j+1] else begin if j<m then continue;k:=0; end; if i-a[j]-1>0 then inc(k,f[i-a[j]-1,j-1]) else begin if j>1 then continue; end; if s[i]-s[i-a[j]]+k=s[n] then begin for l:=i-a[j]+1 to i do t[l]:=true; if b[j]=-1 then begin b[j]:=i-a[j]+1;e[j]:=i; continue; end; if e[j]<i-a[j]+1 then begin b[j]:=i-a[j]+1;e[j]:=i; vis[j]:=true; end; if vis[j] then continue; b[j]:=i-a[j]+1; end; end; end; for i:=1 to n do if not t[i] and (ch[i]='?') then ch[i]:='.'; for i:=1 to m do begin if vis[i] then continue; for j:=b[i] to e[i] do ch[j]:='X'; end; for i:=1 to n do write(ch[i]);writeln; end; begin assign(input,'puzzle.in');reset(input); assign(output,'puzzle.out');rewrite(output); init; solve; close(input);close(output); end. At last.Sorry for my poor English. A test for you: 8 2 2 2 ??.X?.?? | | used greed is right? | 连连 | 1106. Two Teams | 1 Apr 2009 22:14 | 3 | I used greed, is the result of the test data right ? 7 2 3 0 3 1 0 1 2 4 5 0 3 0 3 0 7 0 6 0 4 1 2 3 7 if the result is wrong , please give some hint..... thanks Your result is really wrong. Just take a look: the first and the second mates have no friends in the other team. Edited by author 30.08.2008 15:39 Edited by author 30.08.2008 15:39 Edited by author 30.08.2008 15:39 it's a simple bfs problem. | | please give me ans for this tests... | Crash_access_violation | 1437. Gasoline Station | 1 Apr 2009 21:15 | 2 | who give AC, please, give me right answers for this tests : 1) 1 200 245 2) 0 13 131 3) 37 39 41 4) 29 41 97 5) 0 64 129 6) 81 27 243 7) 240 241 242 thanx Edited by author 14.08.2008 21:51 1)446 2)15 3)76 4)167 5)7 6)13 7)723 | | wa in test#20 | panyong0202 | 1215. Exactness of Projectile Hit | 1 Apr 2009 15:08 | 2 | I also have wa#20 Where's mistake? But you've solved it, maybe you'll help me? var i,n:integer; cx,cy,x1,y1,x2,y2,x3,y3,x4,y4:integer; x,y:array[1..102]of integer; h,min,zn,ras1,ras2:real; f:boolean; begin read(cx);read(cy);readln(n); for i:=1 to n do readln(x[i],y[i]); x[n+1]:=x[1];y[n+1]:=y[1]; f:=true; zn:=0; for i:=1 to n do begin x1:=x[i]-cx;y1:=y[i]-cy; x2:=x[i+1]-cx;y2:=y[i+1]-cy; if (zn=0)then begin zn:=x1*y2-x2*y1; if (zn=0)then begin if ((x[i]<=cx)and(cx<=x[i+1]))or((x[i]>=cx)and(cx>=x[i+1]))then f:=true else f:=false; break;break;break; end; end else begin if (zn*(x1*y2-x2*y1)<0)then begin f:=false; break;break;break; end; end; end; if (f=true)then write('0.000') else begin min:=0; f:=false; for i:=1 to n do begin x1:=cx-x[i];y1:=cy-y[i];x2:=x[i+1]-x[i];y2:=y[i+1]-y[i];x3:=cx-x[i+1];y3:=cy-y[i+1];x4:=x[i]-x[i+1];y4:=y[i]-y[i+1]; if (x1*x2+y1*y2>0)and(x3*x4+y3*y4>0)then begin x1:=x[i]-cx;y1:=y[i]-cy;x2:=x[i+1]-cx;y2:=y[i+1]-cy; h:=(abs(x1*y2-x2*y1))/(sqrt(sqr(x[i+1]-x[i])+sqr(y[i+1]-y[i]))); end else h:=0; ras1:=sqrt(sqr(cx-x[i])+sqr(cy-y[i]));ras2:=sqrt(sqr(cx-x[i+1])+sqr(cy-y[i+1])); if (ras2<ras1)then ras1:=ras2; if (ras1<h)or(h=0)then h:=ras1; if (f=false)or(h<min)then begin min:=h; f:=true; end; end; write((2*min):0:3); end; end. | | What is the Output for n=4? | Alexey | 1261. Tips | 1 Apr 2009 13:47 | 6 | Tell me, please, what is the Output for 1) N=4 2) N=10 3) N=3^m (For example, N=27) Please, help... Thanks a lot. Here are my answers but they are not unique I think 4 13 9 10 37 27 9 36 27 27 108 81 81 324 243 Thanks A Lot! I've got AC!!! What formalization? N=a-b; b>0; a and b have no digit 2 in 3-system? Edited by author 30.06.2007 13:50 Edited by author 30.06.2007 13:51 Why 10 37 27? a = 10(10)=101(3) b = 3(10) =010(3) a+b = 13(10)=111(3) IMHO, right ansver is 10 13 3 | | what is test22 | Erjin Zhou | 1429. Biscuits | 1 Apr 2009 11:22 | 1 | I got WA on test22 for a long time... what is test22? if anyone know,please email zhouerjin@gmail.com | | WA 10 | AlAnt | 1489. Points on a Parallelepiped | 31 Mar 2009 21:49 | 2 | WA 10 AlAnt 31 Oct 2006 11:24 Can somebody say me, what is in test 10? I don't know, why i got WA... Re: WA 10 [SPbSU ITMO] alant 31 Mar 2009 21:49 Finally I've got AC. My mistake was, I think, in printing something like "-0.*" when answer is less than epsilon. | | Can we get the test cases on which you judge our solution ? | Nitiraj Singh Rathore | | 31 Mar 2009 18:50 | 1 | Hi, My answer to the problem 1002 was having "time limit exceeded" problem and sent for test#5. Can I get the test cases on which you are judging our answers so that I can check if my program is working fine with these cases or what error is coming ??? | | if yor have WA #9 float poin error, i'am ascape it after | Валентин | 1075. Thread in a Space | 31 Mar 2009 18:43 | 1 | ac := sqrt(sqr(xa-xc) + sqr(ya-yc) + sqr(za-zc)); bc := sqrt(sqr(xb-xc) + sqr(yb-yc) + sqr(zb-zc)); ab := sqrt(sqr(xa-xb) + sqr(ya-yb) + sqr(za-zb)); //without this i have error if (ac = 0) or (bc = 0) or (ab = 0) then begin writeln(0); halt; end; //end | | Could somebody tell me what's the test 27? | yuyan | 1508. Japanese Puzzle | 31 Mar 2009 18:33 | 1 | I got WA on it about 20 times.I'm crazy now! Please help me. Thank you! | | Make the function faster | Mohit Kanwal | 1002. Phone Numbers | 31 Mar 2009 15:24 | 4 | Hi All, I am a beginner to this site and tried to solve the problem . I am using DP but time limit is exceeded on test # 5 . what algorithm shud I use or wat improvements can I do to my code. /////////////////////////////////////////////////////////// #include <iostream> #include <algorithm> #include <string> #include <map> #include <fstream> #include <vector> using namespace std; map <char, char> guide; void initialise() { guide['i'] = '1';guide['j'] = '1';guide['a'] = '2';guide['b'] = '2';guide['c'] = '2';guide['d'] = '3'; guide['e'] = '3';guide['f'] = '3';guide['g'] = '4'; guide['h'] = '4';guide['k'] = '5';guide['l'] = '5';guide['m'] = '6';guide['n'] = '6';guide['p'] = '7'; guide['r'] = '7';guide['s'] = '7';guide['t'] = '8';guide['u'] = '8';guide['v'] = '8';guide['w'] = '9'; guide['x'] = '9';guide['y'] = '9';guide['o'] = '0';guide['q'] = '0';guide['z'] = '0'; } string getcode(string& str) { string::iterator it; string s; for(it = str.begin();it!=str.end();it++) { s.push_back(guide[(*it)]); } return s; } /*void solve(map <string,vector<string> > m1,string& call) { string ret; typedef string::iterator iter; iter it; vector < <string> :: iterator > pos; typedef map <string,vector <string> > :: iterator t; for(it=call.begin();it!=call.end();it++) { for(iter i = it;i!=call.end();++i) { t mt = m1.find(string(it,i)); if(mt != m1.end()) {//we found the 1st word //must note the position and store in vector // keep erasing the last one if it is not found pos.push_back(i);
ret.append(mt->second[0]); it = i; it++; //need to find more } } } if(ret.length()!=call.length()) cout<<"No Solution"; else cout<<ret; }*/ string select(vector < vector<string::iterator> > &book,map <string , vector <string> > &m1,string &str) { string ret; int best = book[0].size(); int pos = 0; for(int i=1;i<book.size();i++) { if(book[i].size()<best) { pos = i; best = book[i].size(); } } for(int j = 0;j<best-1;j++) { ret.append(m1[string(book[pos][j],book[pos][j+1])][0]); ret.append(" "); } return ret; } string solve(map <string , vector <string> > &m1,string &str) { int best = 9000000000; bool no_soln = true; bool found = false; typedef string :: iterator iter; typedef map <string, vector <string> >::iterator it; vector <string :: iterator> sp; vector < vector<string::iterator> > db; sp.push_back(str.begin()); int c = 0; iter j = sp[c]; while(!(found) && c!=-1) { do { if (c>best || c==best-1) break; j++; it h = m1.find(string(sp[c],j)); if (h!=m1.end()) { //we found one word so push it //cout<<h->second[0]<<" "; sp.push_back(j); c++; } }while(j!=str.end()); //cout<<c<<" "; //check whether found or not if(sp[c] == str.end()) { if (best>c) best = c; cout<<best<<" "; no_soln = false; db.push_back(sp); sp.pop_back();c--; j = sp[c]; sp.pop_back();c--; } else {j = sp[c];sp.pop_back();c--;} } if (!(no_soln)) return select(db,m1,str); else return "No solution."; } void printing(map <string, vector <string> > &m1) { map<string,vector <string> > :: iterator it; it = m1.begin(); while(it != m1.end()) { cout<<(*it).first<<" "<<it->second[0]<<"\n"; it++; } } vector <string> readinput(istream &in) { vector <string> ret; string call; getline(in,call); while((call.compare("-1"))!=0) { map <string , vector<string> > dict; int words=0; //getline(in,call); in>>words; in.ignore(255,'\n'); string line; while(words>0) { getline(in,line); dict[getcode(line)].push_back(line); words--; } //printing(dict); ret.push_back(solve(dict,call)); getline(in,call); } return ret; } int main() { ifstream infile; infile.open("DATA.in"); ofstream outfile; outfile.open("DATA.out"); initialise(); vector <string> ans; ans = readinput(infile); for(int i=0;i<ans.size();i++) outfile<<ans[i]<<endl; /*string m; getline(cin,m); cout<<getcode(m); */ //getch(); infile.close(); outfile.close(); return 0; } Cud u give me a hint !!! Thanks 1. When you write: something::iterator iter; for(iter = container.begin(); iter != container.end(); ++iter) ... container.end() is called each iteration. something::iterator iter, iter_end; for(iter = container.begin(), iter_end = container.end(); iter != iter_end; ++iter) ... is better. 2. When you write: while(...) { int i; ... } i is allocated from stack each iteration. int i; while(...) {...} is better. 3. vector<smth>::push_back() is a very slow operation. It allocates a new piece of memory, copies copies all previous values and a new one to it, and frees the old piece of memory. Performance of push_back() is better in deque and list. 4. printf() and scanf() are better than cin, cout, ifstream, ofstream, fstream in performance. Edited by author 31.03.2009 15:38 | | Weak tests | Fyodor Menshikov | 1306. Sequence Median | 31 Mar 2009 15:10 | 4 | I know AC solution that fails the following test: 2 3000000000 3000000000 The problem test set awhile does not contain tests where median computed as average of two elements and sum of these elements is greater than 2^32 - 1. I know AC solution that fails the following test: 2 3000000000 3000000000 use a / 2.0 + b / 2.0 instead of (a + b) / 2.0 http://acm.timus.ru/news.aspx 3.02.2009. Problem 1306 Sequence Median. Statement updated Now each element of the sequence is a positive integer not greater than 2^31−1 inclusive (old limitation was 2^32−1). Edited by author 31.03.2009 15:10 | | WA on test7 | Erjin Zhou | 1430. Crime and Punishment | 31 Mar 2009 13:57 | 1 | I need help... what is the test 7? | | Tip: WA on Test #4 | Stefan Marinov | 1174. Weird Permutations | 31 Mar 2009 01:39 | 1 | Check whether the biggest possible answer does fit into the data type used. Edited by author 01.04.2009 21:58 | | what is wrong? | safeperson | 1001. Reverse Root | 30 Mar 2009 23:42 | 3 | #include<stdio.h> #include<math.h> int main(void) { double a[256*1024/sizeof(double)];
int i=0;
while(i < 256*1024/sizeof(double)) { scanf("%lf",&a[i]);
i++; } for(--i;i >=0 ; i--) printf("%.4lf\n",sqrt(a[i]));
return 0;
} The number of input numbers can be less than 256*1024. Use the fact that when scanf cannot read next double it returns 0 (it returns the number of successfully read parameters), and break your while then. just use <stack> from stl | | WA 3 | kal1sha | 1683. Fridge | 30 Mar 2009 22:54 | 2 | WA 3 kal1sha 5 Mar 2009 16:18 Give me tests... 24 5 11 6 3 2 1 48 6 23 12 6 3 2 1 correct? My AC Solution: 24 5 12 6 3 1 1 ---- 48 6 24 12 6 3 1 1 ---- 1024 10 512 256 128 64 32 16 8 4 2 1 Good luck. Edited by author 30.03.2009 22:54 | | If possible more then one solution, printf anyone? | spiker | 1683. Fridge | 30 Mar 2009 22:52 | 3 | I`m interesed too, is it correct answer for this example: ***input*** 12 ***output*** 4 6 3 1 1 as in exanple answer is a little different, it is 4 5 3 2 1 | | WA#1!!!!!!!!!!!!!WHY??????????? | Artem | 1403. Courier | 30 Mar 2009 14:58 | 1 | I have got wrong answer on first test!! my program out right test on my computer! |
|
|