Общий форум| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения | | Why my programm is wrong ? | Aleksey S.S. | 1255. Кладбище мафии | 10 окт 2012 18:31 | 4 | >var n,k,ans1,ans2:longint; > >begin > read(n,k); > if n<k then write('0') else begin > ans1:=(n div k)*(n + n mod k); > ans2:=(n-k)*4; > if ans1>ans2 then write(ans1) else write(ans2); end; >end. My program is very short. My method is like yours and I can't find the bug in it. What was wrong with yours? For 8 3 answer is 21, not 20 | | I’ve AC, but I still have a question! | Veniamin | 1224. Спираль | 10 окт 2012 17:32 | 3 | I’ve AC, but I still have a question! My first program used “unsigned long” type, and didn’t pass Test 12 Then I changed all types to “unsigned long long” , and program was AC. So, my question is why my first program failed on Test12? As you know n,m<=2^31-1;So, the biggest result is 0xFFFFFFFD! This result can be represented by unsigned long! So, I didn’t announce my program, because it is bad style. I’m sure that those programmers who solved this issue can understand my question…. Best Wishes, Veniamin. Each of n and m is <= 2^31-1. Yes, they are unsigned long. But max unsigned long + 1 is? Overflow, of course !! Your solution doesn't print n or m exactly but you have to calculate either 2*m or 2*n, aren't you? Thanks.I also meet this question. | | help, please; i can't get AC, but i know that my program is wright | Foxy | 1068. Сумма | 10 окт 2012 11:53 | 3 | > here is my source (C++): --------------------------- #include <stdio.h> int i;long sum=0; int n; void main() { scanf("%d",&n); if(n<1) for(i=1;i>=n;i--) sum+=i; else for(i=1;i<=n;i++) sum+=i; printf("%ld",sum); } -------------------------- Try to delete void because i did so , and my programm was right good Luck ! | | Which alhoritm? | Abbath1349 | 1889. Объявление в аэропорту | 10 окт 2012 00:27 | 1 | can you say which alhoritm it is? topologial sort? | | Help PLEASE, i don't understand | green_smile | 1821. Биатлон | 9 окт 2012 23:27 | 2 | input 6 Zaitseva 21:38.2 Hauswald 21:21.0 Boulygina 22:04.4 Henkel 22:06.1 Wilhelm 21:11.1 Jonsson 22:05.8 My program: 4 Hauswald Henkel Wilhelm Zaitseva explain me please what's wrong??? why Henkel isn't in Test? it's code program z1821; var n,i,j,m,x,max,ol:integer; s,s1:string; names:array[1..100]of string; times:array[1..100]of integer; reznames:array[1..100] of string; begin readln(n); j:=1; for i:=1 to n do begin readln (s); while s[j]<>' ' do begin inc(j); end; names[i]:=copy(s,1,j); // delete(s1,1,length(s1)); // s1:=copy(s,j+1,2); // val(s1,times[i],ol); // delete(s1,1,2); // s1:=copy(s,j+4,2); // times[i]:=times[i]*600; // val(s1,x,ol); // times[i]:=times[i]+x*10; // delete(s1,1,1); // s1:=copy(s,j+7,1); // val(s1,x,ol); // times[i]:=times[i]+x; // j:=1; //it's input, don't look on it =) end; for i:=2 to n do times[i]:=times[i]-300*(i-1); max:=times[1]+1; m:=0; j:=1; for i:=1 to n do begin if times[i]<max then begin max:=times[i]; reznames[j]:=names[i]; m:=m+1; j:=j+1; end; end; for i := 1 to m-1 do for j := 1 to m-i do if reznames[j] > reznames[j+1] then begin s1 := copy(reznames[j],1,length(reznames[j])); reznames[j] :=copy(reznames[j+1],1,length(reznames[j+1])); reznames[j+1] :=copy(s1,1,length(s1)); end; writeln(m); for i := 1 to m do writeln(reznames[i]); end. Edited by author 09.10.2012 23:47 | | Wrong answer 4! Please help! | Grigorenko Vlad | 1131. Копирование | 9 окт 2012 16:31 | 2 | #include<stdio.h> int main(void){ int n,k,time,n1,i; scanf("%d%d",&n,&k); i=1; n1=1; time=0; while(n1<k && n1<n){ n1=n1+i; i++; time++; } if(n - n1>0){ if((n-n1) % k == 0) time=time+(n-n1)/k; else time=time+(n-n1)/k+1; } printf("%d",time); return 0; } Hints: 1) your while loop condition is not quite right. 2) you are not growing n1 properly in the while loop 3) your "if (n - n1>0)" is not necessary, if n-n1 == 0 then the division result will be zero 4) integer ceiling of x/y can be done in a single step like this: (x + y - 1)/y 5) it's generally a good idea to finish each line of output with a newline character In general: do some examples on paper, and step through your code in the debugger, or put in a bunch of print statements to follow the progress of the solution, and you'll discover where the problems are. | | I have WA5. Please check my tests | <-UnderFelixAbove-> | 1377. Лара Крофт | 9 окт 2012 08:46 | 5 | I don't know what problem in my program. That's why I ask you to check my tests: 100 100 1 1 50 50 9996 100 100 5 3 65 34 7783 5 6 1 1 5 6 9 2 2 1 2 2 1 1 5 5 1 1 3 3 24 I am waiting your comments. Thank you. Hello! The answer for this test: 2 2 1 2 2 1 is "2", but your answer is "1". Good luck! Thank you Master! I'm so careless)). Btw, in test #5 N = M = 100. I made inaccurate array definition and get this information. :) My program didn't pass #5 test, because not correctly process the case when N = 2, M > 2 or M = 2, N > 2. | | what is wrong | mahmoudnoaman | 1001. Обратный корень | 9 окт 2012 06:24 | 1 | // modify precision #include <iostream> #include<math.h> #include<limits> using namespace std; int main () { //typedef std::numeric_limits<double>dbl; double A; double B; cin>>A; B=sqrt(A); cout.setf(ios::fixed); cout.precision(4); cout<<fixed<<B<<endl; return 0; } | | No subject | Radiovoin | 1196. Экзамен по истории | 9 окт 2012 02:44 | 1 | Edited by author 09.10.2012 02:55 | | WA test 2 | MiR | 1290. Саботаж | 8 окт 2012 11:20 | 10 | Can you help me, plz? Edited by author 26.07.2006 15:15 Edited by author 27.07.2006 19:37 My program also WA#2. I have implemented 'inserted sort'. Sorts correctly. Don't know what's the problem... PS. What should output program if n == 0? I print '1'. Any right implemented sort (which passes time limit) gets AC. So I think you are mistaken. PS: for n=0 answer is empty output. Why for n=0 output is empty(i agree that it get AC, but...)? Is it wrong? : 0 --> (one number in input)1-->1 what is the problem with output if n==0 ? If n=0 nothing should be output ! If n=0 nothing should be output ! <html> <title>Codeforces.com</title> <body bgcolor="#F0FF0F"> Test Yourself ! <a color="#FF0000" href=" http://codeforces.com">Codeforces.com</a> </body> </html> If n=0 nothing should be output ! | | Useful tests | Hikmat Ahmedov | 1889. Объявление в аэропорту | 8 окт 2012 06:25 | 3 | I spent so much time to figure out my mistakes(You can see it from my attempts :) ). You can save your time by checking theese tests. Hope they are helpful. 4 unknown unknown unknown unknown Answer: 1 2 4 2 unknown unknown Answer: 1 2 12 A B unknown unknown unknown unknown unknown unknown unknown unknown unknown unknown Answer: 12 4 A B C D Answer: 4 8 A A B B unknown unknown unknown unknown Answer: 4 6 A A B B unknown unknown Answer: 3 6 unknown A A B unknown B Answer: 2 6 A unknown unknown A unknown unknown Answer: 1 6 A unknown A unknown unknown unknown Answer: 1 2 4 A A A B Answer: Igor is wrong. First and second tests are not correct. "It is guaranteed that Igor could recognize the language of at least one of the phrases." Some Others: 8 A unknown B unknown unknown unknown unknown unknown Answer: 4 8 10 unknown unknown unknown A unknown unknown unknown unknown B unknown Answer: 2 5 10 12 unknown A unknown unknown unknown B unknown unknown unknown C unknown unknown Answer: 3 4 6 12 12 unknown A unknown unknown unknown B unknown D unknown C unknown unknown Answer: 4 6 12 12 unknown A unknown unknown unknown B unknown D D C unknown unknown Answer: 4 | | how to do? | Czw's Brother | 1124. Мозаика | 8 окт 2012 02:55 | 4 | My solution is the following: First read the input and count how many pieces are placed in the wrong boxes(i.e. there color is not the same as the color of the box) lets call that number cnt. You must move these pieces at least once. Then I build a graph for which the boxes are the nodes and there is an edge between two boxes a and b iff there is a piece of color b in the box of color a. After building the graph one should count the number of connected components in it(lets call it count). Now the answer to our problem is simply cnt + max(count-1,0) as one should do at least max(count-1,0) moving of his hand to another box and it is always possible to solve the problem in exactly that many moves of the hand without moving a piece. LSBG, thank you so much, it's the better solution I've ever seen))) | | Help me to understand statement, please! | crdp | 1277. Cops and Thieves | 8 окт 2012 00:59 | 2 | In second test case, only possible way to block all possible routes is to control stations 2 and 3. But, both these stations are next to museum station, so we aren't able to control them! What's wrong? I've got AC, suggesting that there is exactly one station which is next to the station A - it's A. | | WR in test #1 | mihran | 1263. Выборы | 7 окт 2012 21:43 | 2 | // PROGRAM 1263 IN C++ # include <iostream.h> # include <stdio.h> int main() { int N,M,a[10000]; double k,l=0; cin>>N>>M; if (N>=1 && N<=10000 && M>=1 && M<=10000) { for (int i=0;i<=M-1;i++) cin >>a[i]; for (int p=1;p<=N;p++) { for (int h=0;h<=M-1;h++) { if (a[h]==p) l++; } k=(l/M)*100; l=0; printf ("%.2f",k); cout <<'%'<<endl; } } return 0; } Edited by author 07.10.2012 21:43 Edited by author 07.10.2012 21:44 | | Help plz | ACSpeed - Nguyen Khac Tung | 1684. Последнее слово Джека | 7 окт 2012 20:55 | 2 | Help plz ACSpeed - Nguyen Khac Tung 30 янв 2012 16:06 abracadabra arbadacarba In example 2 , why is this answer wrong : NO a r b a d a c a r b a All of them are "its nonempty prefix" ? All of them should be "non-empty" and "prefix" ... well in ur case "r" itself is not a prefix so ..this is WA hope this explains and helps.. | | Anyone Crash Test 3? | Georgy Kerensky | 1471. Расстояние в дереве | 7 окт 2012 19:41 | 10 | What is crash?(stack overflow) what to do?I use normal dfs and pass just two variables to it:((( write dfs without recursion or you can just add {$M 16777216} for Pascal and #pragma comment(linker, "/STACK:16777216") for C/C++ to your recursive solution. Thank you very much, I don't know how to express my thanks to you! Thanks !!! I also got Crash on Test #3. I use BFS with a global queue, and global vectors and arrays. Does anybody know why my program crashes. Here's my code: #include <cstdio> #include <vector> #include <queue> using namespace std; int a[5000][5000]; int dist[5000][5000]; vector <int> v[5000]; vector <int> used; queue <int> q; int parent[5000]; int n,m; int usd[5000]; void input() { scanf("%d",&n); int x,y,c; for (int i=0;i<n-1;i++) { scanf("%d%d%d",&x,&y,&c); a[x][y]=a[y][x]=c; v[x].push_back(y); v[y].push_back(x); } } void bld() { q.push(0); int c; while (!q.empty()) { c=q.front(); q.pop();
// printf("%d ",c);
usd[c]=1; for (int i=0;i<used.size();i++) { dist[c][used[i]]=dist[used[i]][c]=a[c][parent[c]]+dist[parent[c]][used[i]]; }
for (int i=0;i<v[c].size();i++) { if (usd[v[c][i]]==0) { // printf("%d - %d ",v[c][i],c); parent[v[c][i]]=c; q.push(v[c][i]); } } used.push_back(c); } } void print() { scanf("%d",&m); int x,y; for (int i=0;i<m;i++) { scanf("%d%d",&x,&y); printf("%d\n",dist[x][y]); } } int main() { input(); bld();
print(); return 0; } N ≤ 50000 but your arrays only 5000 I have this problem in Java. Could you help me to fix it? My solution crashes on this test case.I used BFS+LCA to solve it,used global queue and arrays of size 50005,which should be enough,as the problem says there will be 50000 nodes.I also used randomised source for BFS,but still it's not working.Can anyone please help? Here's my code #include<cstdio> #include<cstring> #include<queue> using namespace std; class edge{ public: int to,prev,w; }; edge edges[100100]; int last[100100],p[50005],d[50005],L[50005],P[50005][20]; int N,num; bool check[50005]; queue<int>Q; void addedge(int u,int v,int w) { edges[num].to=v; edges[num].w=w; edges[num].prev=last[u]; last[u]=num; num++; } void BFS(int sc) { int u,v,i; while(!Q.empty()) Q.pop(); Q.push(sc); check[sc]=true;p[sc]=-1;d[sc]=0;L[sc]=0; while(!Q.empty()) { u=Q.front(); Q.pop(); for(i=last[u]; i!=-1; i=edges[i].prev) {
v=edges[i].to; if(!check[v]) { check[v]=true; p[v]=u; d[v]=d[u]+edges[i].w; L[v]=L[u]+1; Q.push(v); } } } } int Find(int u,int v) { //make u at higher level if(L[u]>L[v]) { int temp=u; u=v; v=temp; } if(u==v) return u;
int log,i,j; for(log=1; log<N; log*=2); //bring u and v to same level for(i=log; i>=0 ;i--) if(L[v]-L[u]>=(1<<i)) v=P[v][i]; if(u==v) return u;
for(i=log; i>=0; i--){ if(P[u][i]!=-1 && P[u][i]!=P[v][i]) { u=P[u][i];v=P[v][i]; } } return p[u];
} int main() { int m,i,j,k,a,b,c,log,x; //freopen("timus.txt","r",stdin); while(scanf("%d",&N)!=EOF) { num=0; for(i=0; i<N; i++) last[i]=-1; for(i=1; i<N; i++) { scanf("%d%d%d",&a,&b,&c); x=a; addedge(a,b,c); addedge(b,a,c); } for(i=0; i<N; i++) check[i]=false; BFS(x); //for(i=0; i<N; i++) printf("%d %d %d %d\n",i,p[i],L[i],d[i]); memset(P,-1,sizeof(P)); for(log=1; log<N; log*=2); for(i=0; i<N; i++) P[i][0]=p[i]; for(j=1; j<=log; j++){
for(i=0; i<N; i++) { if(P[i][j-1]!=-1) P[i][j]=P[P[i][j-1]][j-1]; } }
scanf("%d",&m); while(m--) { scanf("%d%d",&a,&b); int LCA=Find(a,b); int dis=d[a]+d[b]-2*d[LCA]; printf("%d\n",dis); } }
return 0; } Edited by author 07.10.2012 01:43 Can anyone please help me?? | | Why not "abra bra cada" | Kumaar | 1684. Последнее слово Джека | 7 окт 2012 19:37 | 4 | Even this answer is ok right? because 'bra' isn't prefix WA #3 please suggest I do not have to take 1st string's legth in consideration... I am doing kmp failure function tabulation... for suffix match of string b with prefixes of a and thus ... only b's string length is taken care of .... plz suggest some test case where I might be wrong.. what m doing is this -------------------------- // n is the string length of b f.resize(n+2); f[0]=-1; int x; for(int i=1;i<=n;i++) { x=f[i-1]; while(x>=0&&a[x+1]!=b[i-1]) x=f[x]; if(a[x+1]==b[i-1]) f[i]=x+1; else f[i]=-1; } -------------------------------------------- Edited by author 07.10.2012 20:52 | | If you have WA#3 | bsu.mmf.team | 1684. Последнее слово Джека | 7 окт 2012 19:33 | 2 | Pay attention to the fact that sizes of strings may distinguish. I do not have to take 1st string's legth in consideration... I am doing kmp failure function tabulation... for suffix match of string b with prefixes of a and thus ... only b's string length is taken care of .... plz suggest some test case where I might be wrong.. what m doing is this -------------------------- // n is the string length of b f.resize(n+2); f[0]=-1; int x; for(int i=1;i<=n;i++) { x=f[i-1]; while(x>=0&&a[x+1]!=b[i-1]) x=f[x]; if(a[x+1]==b[i-1]) f[i]=x+1; else f[i]=-1; } -------------------------------------------- | | Accepted | Bekzhan | 1100. Таблица результатов | 7 окт 2012 14:32 | 6 | I used stable_sort and had wrote this comparator: bool cmp(PII a, PII b) { return (a.first > b.first) } You need "Sarkazm" table, man. First time I use bubblesort, but TLE. | | Compilation error | Yuri | 1149. Танцы синуса | 7 окт 2012 01:29 | 4 | What's going on?! I've now any errors and warnings. I'm using only <iostream.h>. > What's going on?! > I've now any errors and warnings. > I'm using only <iostream.h>. #include <iostream.h> int main(void) { unsigned int n; cin>>n; char *a,*val; unsigned int na; a=new char[2000]; val=new char[4]; if(n==0) { cout<<'0'; return 0; } a[0]='s'; a[1]='i'; a[2]='n'; a[3]='('; a[4]='1'; a[5]=')'; a[6]=0; na=6; unsigned int j; for(unsigned int i=0;i<n-1;i++) cout<<'('; for(unsigned int i=2;i<=n;i++){ cout<<a; cout<<'+'; cout<<(n-i+2); cout<<')'; //изменение а na=na-i+1; //игнорируем скобки справа if((i % 2)==0) a[na]=(char)'-'; else a[na]='+'; a[na+1]='s'; a[na+2]='i'; a[na+3]='n'; a[na+4]='('; na+=5; if(i<10){ val[0]=(char)('0'+i); val[1]=0; } else if(i<100) { val[0]=(char)('0'+i/10); val[1]=(char)('0'+i-i/10*10); val[2]=(char)0; } else { val[0]=(char)('0'+i/100); val[1]=(char)('0'+(i-i/100*100)/10); val[2]=(char)('0'+i-i/10*10); val[3]=(char)0; } j=0; while(val[j]!=0){ a[na]=val[j]; j++; na++; } for(j=0;j<i;j++) a[na+j]=')'; na+=j; a[na]=0; } cout<<a; cout<<"+1"; return 0; } > > > What's going on?! > > I've now any errors and warnings. > > I'm using only <iostream.h>. > #include <iostream.h> > > int main(void) > { > unsigned int n; > cin>>n; > char *a,*val; > unsigned int na; > > a=new char[2000]; > val=new char[4]; > > if(n==0) > { > cout<<'0'; > return 0; > } > > a[0]='s'; > a[1]='i'; > a[2]='n'; > a[3]='('; > a[4]='1'; > a[5]=')'; > a[6]=0; > na=6; > > unsigned int j; > > for(unsigned int i=0;i<n-1;i++) //~~~~~~~~~~~~~~~ > cout<<'('; > > for(unsigned int i=2;i<=n;i++){ //~~~~~~~~~~~~~~~redefinition > cout<<a; > cout<<'+'; > > cout<<(n-i+2); > cout<<')'; > > //§Ъ§Щ§Ю§Ц§Я§Ц§Я§Ъ§Ц §С > na=na-i+1; //§Ъ§Ф§Я§а§в§Ъ§в§е§Ц§Ю §г§Ь§а§Т§Ь§Ъ §г§б§в§С§У§С > if((i % 2)==0) > a[na]=(char)'-'; > else > a[na]='+'; > a[na+1]='s'; > a[na+2]='i'; > a[na+3]='n'; > a[na+4]='('; > na+=5; > if(i<10){ > val[0]=(char)('0'+i); > val[1]=0; > } > else if(i<100) > { > val[0]=(char)('0'+i/10); > val[1]=(char)('0'+i-i/10*10); > val[2]=(char)0; > } > else > { > val[0]=(char)('0'+i/100); > val[1]=(char)('0'+(i-i/100*100)/10); > val[2]=(char)('0'+i-i/10*10); > val[3]=(char)0; > } > j=0; > while(val[j]!=0){ > a[na]=val[j]; > j++; > na++; > } > for(j=0;j<i;j++) > a[na+j]=')'; > na+=j; > > a[na]=0; > } > > cout<<a; > cout<<"+1"; > > return 0; > } > > > THIS CODE WILL LEAD YOU TO AC (PAY ATTENTION TO CORRECTIONS): #include <iostream> //not # include <iostream.h> using namespace std; //to be able to use cin,cout and many other functions int main(void) { unsigned int n; cin>>n; char *a,*val; unsigned int na; a=new char[2000]; val=new char[4]; if(n==0) { cout<<'0'; return 0; } a[0]='s'; a[1]='i'; a[2]='n'; a[3]='('; a[4]='1'; a[5]=')'; a[6]=0; na=6; unsigned int j; for(unsigned int i=0;i<n-1;i++) cout<<'('; for(unsigned int i=2;i<=n;i++){ cout<<a; cout<<'+'; cout<<(n-i+2); cout<<')'; //изменение а na=na-i+1; //игнорируем скобки справа if((i % 2)==0) a[na]=(char)'-'; else a[na]='+'; a[na+1]='s'; a[na+2]='i'; a[na+3]='n'; a[na+4]='('; na+=5; if(i<10){ val[0]=(char)('0'+i); val[1]=0; } else if(i<100) { val[0]=(char)('0'+i/10); val[1]=(char)('0'+i-i/10*10); val[2]=(char)0; } else { val[0]=(char)('0'+i/100); val[1]=(char)('0'+(i-i/100*100)/10); val[2]=(char)('0'+i-i/10*10); val[3]=(char)0; } j=0; while(val[j]!=0){ a[na]=val[j]; j++; na++; } for(j=0;j<i;j++) a[na+j]=')'; na+=j; a[na]=0; } cout<<a; cout<<"+1"; return 0; } Edited by author 07.10.2012 01:31 Edited by author 07.10.2012 01:31 |
|
|