Общий форумc++: #include<iostream> using namespace std; long long sqr(int x, int y){ long long a=1; for(int i=1;i<=y;i++) a*=x; return a; } int main(){ int n,y,m,a=-1; cin>>n>>m>>y; if(y>=m){ cout<<-1<<endl; return 0; } for(int x=0;x<m;x++) if((sqr(x,n))%m==y){ cout<<x<<" "; a+=2; } cout<<endl; if(a==-1 && y<m) cout<<-1<<endl; return 0; } please help me! Edited by author 20.01.2011 20:31 Edited by author 20.01.2011 20:33 You should include math libarary like <math.h> or <cmath> Of course not! I've coded function sqr! Problem is in "long long int" - not enough for 998^999 Reading by Console.Readline() or Console.ReadToEnd gets Memory Limit, reading by Console.Read() gets Time Limit. Is there any other way to read without getting MLE and TLE? Hint is wrong. I had WA#15, but after changing in Java code "int" to "long" task was accepted. # include <stdio.h> # include <algorithm> using namespace std; struct daw { long long rg,lf,nd,vl,mx; }; long long a,b; long long w[409]; long long c[409][5]; long long v[409][409]; daw d[409]; void btr(long long x) { if(d[x*2+1].vl!=0) btr(x*2+1);
if(d[x*2+2].vl!=0) btr(x*2+2);
if(x!=0) d[(x-1)/2].nd=d[(x-1)/2].nd+d[x].nd+1; } long long dp(long long x, long long y) { // prlong longf("%d %d",x,y);getchar();
if(y==0) return 0;
if(v[x][y]>0) return v[x][y];
for(long long i=0;i<=y;i++) if(d[x].nd-d[x*2+2].nd>=i && d[x*2+1].vl>0 && d[x*2+2].vl>0) { long long q=0;
if(i!=0) q+=d[x].lf;
if(i!=y) q+=d[x].rg;
if(i==0) v[x][y]=max(v[x][y],dp(x*2+2,y-1)+q);
else if(i==y) v[x][y]=max(v[x][y],dp(x*2+1,y-1)+q);
else v[x][y]=max(v[x][y],dp(x*2+1,i-1)+dp(x*2+2,y-i-1)+q); }
return v[x][y]; } int main() { scanf("%lld %lld",&a,&b);
for(long long i=0;i<a-1;i++) scanf("%lld %lld %lld",&c[i][0],&c[i][1],&c[i][2]);
d[0].vl=1; w[1]=1;
for(long long i=0;i<a-1;i++) for(long long j=0;j<a-1;j++) { if(d[i].vl==c[j][0] && w[c[j][1]]==0) { if(d[i*2+1].vl==0) {d[i].lf=c[j][2]; d[i*2+1].vl=c[j][1];}
else {d[i].rg=c[j][2]; d[i*2+2].vl=c[j][1];}
w[c[j][0]]=1; }
if(d[i].vl==c[j][1] && w[c[j][0]]==0) { if(d[i*2+1].vl==0) {d[i].lf=c[j][2]; d[i*2+1].vl=c[j][0];}
else {d[i].rg=c[j][2]; d[i*2+2].vl=c[j][0];}
w[c[j][0]]=1; } }
btr(0);
if(b==1) {printf("%lld",max(d[0].rg,d[0].lf));return 0;}
printf("%lld",dp(0,b));
getchar(); getchar(); } Thanks [edit] I used formula for day of week instead of pascal function. Got ac. I am using dayofweek to get the weekday for the first of the month in the question. I am getting WA7. I think my formatting is OK but I am getting wrong answers for some inputs. The two supplied examples are OK, and 20 10 2050 mon 3 10 17 24 31 tue 4 11 18 25 wed 5 12 19 26 thu 6 13 [20] 27 fri 7 14 21 28 sat 1 8 15 22 29 sun 2 9 16 23 30 and 25 11 1885 mon 2 9 16 23 30 tue 3 10 17 24 wed 4 11 18 [25] thu 5 12 19 26 fri 6 13 20 27 sat 7 14 21 28 sun 1 8 15 22 29 but not 4 7 1890 mon [ 4] 11 18 25 tue 5 12 19 26 wed 6 13 20 27 thu 7 14 21 28 fri 1 8 15 22 29 sat 2 9 16 23 30 sun 3 10 17 24 31 or 1 1 1600 mon [ 1] 8 15 22 29 tue 2 9 16 23 30 wed 3 10 17 24 31 thu 4 11 18 25 fri 5 12 19 26 sat 6 13 20 27 sun 7 14 21 28 from what I have seen in the forum. Any ideas please? Thanks Edited by author 05.12.2012 22:33 var a,b:integer; begin readln(a,b); writeln(a+b); end. probably you are wrong this is so hard problem :) !!! var a,b:longint; begin read(a,b); writeln(a+b); end. (Try this,not readln,but read) :) Edited by author 12.04.2010 16:14 "highly protable"? May be "highly profitable"? And "in those aairs"? May be "in those affairs"? Edited by author 05.12.2012 10:26 Firstly i calculate the longest rope lenths at each tree. Then just try to tether goats to every tree, calculating the square. If sum of 2 maxrope are larger then lenght between trees: double maxrad = std::max(maxr[i], maxr[j]); double minrad = l - maxrad; if (minrad < 1.0) { maxrad = maxrad - (1 - minrad); minrad = 1.0; } if (maxrad >= 1.0) maxsize = std::max(maxsize, square(maxrad)+sqree(minrad)); Try this test 4 0 0 5 0 6 0 6.5 0 Right answer is 53.4071 Thx, really nice test. Now AC :) Yeah... I was caught by that too :)) Help me!, I got WA 5!. :-s stuck in WA5 too>"< can't understand Give me some tests Edited by author 13.01.2013 05:15 I solved using too mush time Can anyone explain me how some people did it in 0.031?? Please) This problem can be solved via sorting by angle in this time)) C++, 0.015 sec, 196 Kb #include <iostream> using namespace std; int main() { int n,k; cin>>n>>k; int m=n/k + ((n%k==0) ? 0:1); int * A=new int [m*k]; for (int i=0;i<n;i++) { cin>>A[i]; } for (int i=n;i<m*k;i++) A[i]=-1; for (int i=0;i<m;i++) { for (int j=0;j<k;j++) { int h=j*m+i; if (A[h]<0) cout<<" "; if (A[h]>-1 && A[h]<10) cout<<" "<<A[h]; if (A[h]>9 && A[h]<100) cout<<" "<<A[h]; if (A[h]>99 && A[h]<1000) cout<<" "<<A[h]; } cout<<endl; } return 0; } Waiting of comments C, 0.015 sec, 112 kb main() { short n,k,a[101],i,j; scanf("%d %d",&n,&k); k=(n+k-1)/k; for(i=0;i<n;i++)scanf("%i",&a[i]); for(j=0;j<k;puts(""),j++) for(i=j;i<n;i+=k) printf("%4d",a[i]); } What's incorrect????? int main() { int n, k; scanf("%d %d", &n, &k); vector<int> mas(100);
mas.assign(100, -1); for (int i=0; i<n; i++) scanf("%d", &mas[i]); int s=n/k; if(n%k!=0) s++; for (int i=0; i<s; i++) { for(int j=0; j<k; j++) if (mas[s*j+i]!=-1) printf("%4d", mas[s*j+i]); printf("\n"); } return 0; } Edited by author 26.04.2011 20:30 vector<int>mas; mas.assign(111,-1); 100 1 1 2 3 4 .. 99 100 ans: 1 2 3 4 .. 99 100 Edited by author 09.07.2011 17:54 My AC code : ans: 1 2 3 4 . . . 99 100 i think there must be some stupid mistake.My all tests pass it. please provide me good tests or please,kindly let me know the problem in the code: [code deleted] AC at last(.187 sec 121 kb) very very stupid mistake. if(x==n-x) just print x not x and n-x :P Edited by author 12.07.2010 10:41 Edited by author 13.07.2010 18:43 if(x==n-x) It's possible only if n==2 is it possible to happen x == n-x ??? if yes, then 2*x = n; but n is prime and is not divisible by 2. Can someone give me some tests? I have WA#10, I don't know what else I can fix to solve this problem. I used hashes, but I think that my simple algorithm can have collisions, because I make hash mod 10000000; //sorry for my english. also I changed algorithm, now I don't use mod. But, I still have WA#10. I used stack + hash, but, all the same Edited by author 03.12.2012 19:10 Edited by author 03.12.2012 19:34 Where's my mistake? #include <iostream> #include <cmath> using namespace std; int main() { double n, s; cin >> n; s = (1 + n) * (abs(n / 2.) + (n < 1)); cout << s; return 0; } Is it necessary to make a complete graph. Is it possible to find the solution in a more easy way? I always get stuck on #4. Just simple BFS. Now i am stuck on problem 1. What is the output here? My program has the output of the example. Has something changed? Edited by author 03.12.2012 04:30 |
|