Общий форумHere is my code #include <stdio.h> #define MaxN 100000+252 #define MaxPop MaxN/2+1 struct pointer { int s; char o; }; struct pointer GetPointer(int i) { struct pointer p; p.s=i/250; p.o=i % 250; return p;
} struct Stack { int V; struct pointer pred; }; int GetAdress(struct pointer p) { return p.s*250+p.o; } int A[1001]; int MP; struct Stack B[MaxN]; int Pop(int S) { int E; E=B[A[S]].V; A[S]=GetAdress(B[A[S]].pred); return E; } int Push(int S, int E) { int i=A[S]; MP++; B[MP].V=E; B[MP].pred=GetPointer(i); A[S]=MP; return 0; } int main() {
int N,i,j,E,k; int S; char command[10]; scanf("%d",&N);
MP=0; B[MP].V=0; B[MP].pred=GetPointer(0); for (i=1;i<1000;i++) A[i]=0; k=0; for (i=1;i<=N;i++) {
scanf("%s",command); if (command[1] == 'U'){ scanf("%d %d",&S,&E); Push(S,E); } else { scanf("%d",&S); k++; printf("%d\n",Pop(S)); } }
return 0; } Edited by author 10.02.2013 18:10 What is test 6? I am stuck at it for a very long time! What is the true way to change k-(needed numbers) http://pastebin.com/f27Pt0HC - code #include <iostream>; #include <map>; #include <string>; using namespace std; // dfs( копия матрицы, кол-во вершин, указатель на юзет, в который будут добавлятся числа Исенбаева, проверяемое ребро, число Исенбаева в данный момент) int dfs(int **gr, int n, int *&q, int v, int k) { for(int i=0;i<n;i++) if ( (gr[v][i]==-1)&&(q[i]==1000) )//если из v в i есть путь и если i не обойдена { q[i]=min(k,q[i]);//чтобы избавится от 1000 dfs(gr,n,q,i,k+1); } return 1; } int main() { int x,i,j,m,n; map<string,int> a; n=0; cin>>m; int **gr=new int*[3*m]; //матрица смежности for(int i=0;i<3*m;i++) gr[i]=new int[3*m]; string s1,s2,s3; for(int i=0; i<m; i++)//ввод фамилий по 3 в строке { cin>>s1>>s2>>s3; if (a[s1]==0) a[s1]=++n; if (a[s2]==0) a[s2]=++n; if (a[s3]==0) a[s3]=++n; gr[ a[s1] ] [ a[s2] ] =-1; gr[ a[s2] ] [ a[s1] ] =-1; gr[ a[s3] ] [ a[s1] ] =-1; gr[ a[s1] ] [ a[s3] ] =-1; gr[ a[s3] ] [ a[s2] ] =-1; gr[ a[s2] ] [ a[s3] ] =-1; }; int k=1; x=a["Isenbaev"]; int *used=new int[n]; for(int i=0;i<n;used[i++]=1000); int *&q=used; cout<<dfs(gr,n,used,x,1); i=0; used[x]=0; for(map<string,int>::const_iterator x=a.begin();x!=a.end();++x,i++) if(used[i]<1000) cout<<x->first<<' '<<used[i]<<endl; else cout<<x->first<<" undefined"<<endl; delete gr,used; return 0; } Could anyone give me the test#6? godsuriyel@gmail.com thanks! I print all answers before now AC,thanks ok Edited by author 09.02.2013 23:40 /* * You should only define the SURC_TEST macros * in the compile directives! */ #include <stdio.h> void main(void) { int nT, a, b, nResult; #ifndef SURC_TEST scanf ("%d", &nT); #else nT = 27; #endif for (int iT = 0; iT < nT; ++iT) { #ifndef SURC_TEST scanf ("%d %d", &a, &b); #else switch (iT) { case 0: a = 30; b = 89; break; case 1: a = 2; b = 16; break; case 2: a = 3; b = 243; break; case 3: a = 1; b = 1; break; case 4: a = 2; b = 2; break; case 5: a = 2; b = 72; break; case 6: a = 1; b = 536870912; break; case 7: a = 1; b = 536870912; break; case 8: a = 1; b = 214358881; break; case 9: a = 1; b = 147008443; break; case 10: a = 1; b = 352275361; break; case 11: a = 1; b = 28934443; break; case 12: a = 1; b = 214921799; break; case 13: a = 1; b = 1042441; break; case 14: a = 1; b = 2627641; break; case 15: a = 1; b = 6086089; break; case 16: a = 1; b = 12823561; break; case 17: a = 1; b = 24730729; break; case 18: a = 1; b = 44930209; break; case 19: a = 1; b = 77810041; break; case 20: a = 1; b = 129254161; break; case 21: a = 1; b = 207561649; break; case 22: a = 1; b = 319730161; break; case 23: a = 1; b = 480091921; break; case 24: a = 1; b = 707081281; break; case 25: a = 1; b = 31973; break; case 26: a = 1; b = 499999999; break; default: a = 1; b = 1; break; } #endif nResult = 0; /********** ALGORITM START ******** * Insert your algorithm here. * input: a, b * result write to: nResult */ // ********* ALGIROTM END ********* #ifndef SURC_TEST printf ("%d\n", nResult); #else int nRightResult; switch (iT) { case 0: nRightResult = 0; break; case 1: nRightResult = 4; break; case 2: nRightResult = 5; break; case 3: case 4: nRightResult = 1; break; case 5: nRightResult = 5; break; case 6: case 7: nRightResult = 30; break; case 8: nRightResult = 9; break; case 9: nRightResult = 6; break; case 10: nRightResult = 5; break; case 11: case 12: nRightResult = 4; break; case 13: case 14: case 15: case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23: case 24: nRightResult = 3; break; case 25: nRightResult = 2; break; case 26: nRightResult = 3; break; default: nRightResult = 1; break; } if (nResult == nRightResult) printf ("%d\tT\n", iT); else printf ("%d\tF: %d (should be: %d)\n", iT, nResult, nRightResult); #endif } } Edited by author 09.02.2013 22:15 Edited by author 09.02.2013 22:15 who know 13 test . Please help me
If you use dfs, try this test 5 1 3 01000 10111 01000 01000 01000 Answer is: 0 00000 00000 00000 00000 00000 It is rather useful. Thanks. Some tests 7 2 1 2 3 4 5 6 7 Answer 1 5 2 6 3 7 4 7 6 1 2 3 4 5 6 7 Answer 1 3 4 5 6 7 2 This answer can't be right. Only the last column may be smaller. Here 5 columns are smaller. OK, second test is not correct, I think now. ALL tests from the discussion passed and still WA7. Any suggestions? The key for solution was realizing that the ends of the sticks was on the same distance from origin. How to prove that? I have a function F(angleA, angleB). I took derivatives dF/angleA and dF/angleB, they must be equal to zero. Then what? Refer to my new topic :) Cheers var i,j,k,n:longint; begin read(n); for i:=1 to 250 do if sqr(i)=n then begin write(1); exit; end; for i:=1 to 250 do for j:=1 to 250 do if sqr(i)+sqr(j)=n then begin write(2); exit; end; for i:=1 to 250 do for j:=1 to 250 do for k:=1 to 250 do if sqr(i)+sqr(j)+sqr(k)=n then begin write(3); exit; end; write(4); end. If N was bigger, you would have time limit. I don't think so. My code got AC. #include<stdio.h> int i,j,k; long int n; int main() { scanf("%d",&n);
for(i=1;(i*i)<=n;i++) if((i*i)==n) { printf("%d",1); return 0; } for(i=1;i*i<=n;i++) for(j=1;j*j<=n;j++) if((i*i+j*j)==n) { printf("%d",2); return 0; }
for(i=1;i*i<=n;i++) for(j=1;j*j<=n;j++) for(k=1;k*k<=n;k++) if((i*i+j*j+k*k)==n) { printf("%d",3);
return 0; }
printf("%d",4); return 0;
} But this solution is bad. I think it's DP in this problem O(n*sqrt(n)); for(i=1;(i*i)<=n;i++) if((i*i)==n) { printf("%d",1); return 0; } you can just write if (sqrt(n) * sqrt(n) == n) this is the most epic answer I've read....hhhh :) u are awesome thanks dud and good luck # include <math.h> # include <stdio.h> # include <algorithm> using namespace std; int a,b,c,x,y; int main() { scanf("%d %d %d",&a,&b,&c);
for(int i=1;i<10001;i++) { x=0; y=0;
for(int j=1;j<=(int)sqrt((double)i)+1;j++) if(i%j==0) x++;
if(i-c>0) { for(int j=1;j<=(int)sqrt((double)(i-c))+1;j++) if(i%j==0) y++; }
if(b==x && a==y) {printf("%d",i);getchar();getchar();return 0;} }
printf("0");system("Pause"); } //SESC USU SUDO RM -RF var a,b,c,d,i:integer; begin readln(a); readln(b); for i:=1 to 10000 do begin if i mod 2 = 0 then if b-c <> 0 then c:=c+1 else d:=d+1 else if a-c <> 0 then c:=c+1 else d:=d+1; end; case d of 1..200000 : writeln ('yes'); 0 : writeln ('no'); end; end. Edited by author 01.12.2012 17:39 Edited by author 01.12.2012 17:39 Edited by author 01.12.2012 17:39 var a,b:integer; begin if(a mod 2 =1) or (b mod 2=0) then writeln('no') else writeln('yes') end. or wa1? var c,d : integer; a,b : string[4]; begin readln(a); readln(b); val(a,c); c:=c mod 2; val(b,d); d:=d mod 2; writeln(c,d); if (c=1) or (d=0) then writeln('no') else writeln('yes'); end. 1 0 Must be "Death" Why? You can rotate the only accessible ring 1/2 turns, and the second ring will stay in its initial position. really curious about it, do you have any idea? Am I right? 19 1 1 1 10 6 4 100 60 12 1000 840 32 10000 7560 64 100000 83160 128 1000000 720720 240 10000000 8648640 448 100000000 73513440 768 1000000000 735134400 1344 10000000000 6983776800 2304 100000000000 97772875200 4032 1000000000000 963761198400 6720 10000000000000 9316358251200 10752 100000000000000 97821761637600 17280 1000000000000000 866421317361600 26880 10000000000000000 8086598962041600 41472 100000000000000000 74801040398884800 64512 1000000000000000000 856811873911587456 491520 No, for 10^18 correct answer is 897612484786617600 103680 Big thanks! :) Try using unsigned long long and compute the numbers untill 10^19 I can't understand what's wrong? #include <iostream> using namespace std; int main() { int n,s=1,max,j,i; cin>>n; int *a=new int[n]; for(i=0; i<n;i++) cin>>a[i]; s=1;max=0; for(i=0;i<n;i++) { j=i+1; while(a[i]<a[j]) j++; if (j-i>=s) { if (max>0) s=j-i+1; else s=j-i; max=i; } }; cout<<max+1;
delete a; return 0; } Edited by author 07.02.2013 01:30 In paskal when n=10000 you can not write this expression n*(n+1)*(n+2)/2 in some variables it is very long and big number so in C++ it is very easy just write(here is my AC program): #include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { long long n; cin>>n; cout<<n*(n+1)*(n+2)/2<<endl; system("PAUSE"); return EXIT_SUCCESS; } Edited by author 27.04.2008 17:47 In Pascal you can use Int64 why is it true? can u explain me please?) |
|