Общий форум#include<math.h> #include<stdio.h> int main() { double arr[1000]; int i=0,count=0; while(scanf("%lf",&arr[i])) { arr[i] = sqrt(arr[i]); i++; count++; } for(i=count-1;i>=0;i--) printf("\n %0.4lf",arr[i]); return 0; } size of a = 1000 is not enought -> index was out of size size of a maybe more than. Because file size = 256 KB. Unlimit A[i]. So that use array here is difficut to solve this problem! Heavy-Light-Decomposition -> GOOD data structure! thank you all! here is my code: #include <stdio.h> int total(int count, int sum) { int result = 0; if( count > 1 ) { int i=0; for (; i <= 9; i++) { result += total(count - 1, sum - i); } } else { return sum < 10 && sum >= 0 ? 1 : 0; } return result; } int main () { unsigned a; int n,i,c,b;
scanf("%ud", &a); b = a / 2 * 9; for(i=0; i <= b; i++ ) { c = total(a/2, i); n += c * c; } printf("%d", n);
return 0; } i tried 2,4,6,8,the result is correct,but when i submit my solution,[wrong answer] is returned... Edited by author 02.09.2011 14:58 i got it,in visual stdio 2010,auto variable must initialized before used Hello Smart :D, Can you please explain how does your algorithm works? I find out that the summation of digits is multiplication of 9 at most; but why (c* c) ???? ( please explain the whole intention behind your algo as well. Thanks Here is the correct code #include <stdio.h> int total(int count, int sum) { int result = 0; if( count > 1 ) { int i=0; for (; i <= 9; i++) { result += total(count - 1, sum - i); } } else { return sum < 10 && sum >= 0 ? 1 : 0; } return result; } int main () { unsigned a; int n = 0; int i,c,b; scanf("%ud", &a); b = a / 2 * 9; for(i=0; i <= b; i++ ) { c = total(a/2, i); n += c * c; } printf("%d", n); return 0; } Here is the correct code In first line trochee, and iamb both has. why no "not a poem" ? Now, I understand, very easy :) Edited by author 15.02.2012 19:38 #include<stdio.h> int main(void){ int n,m; unsigned int k; scanf("%d %d",&n,&m); k=0; while(n>2 && m>2){ k=k+4; n-=2; m-=2; } if(n==2 && m>=2) k=k+2; else if(m==2 && n>2) k=k+3; else if(m==1 && n>1) k++; printf("%d",k); return 0; } Please check my submission 4323013. It gets AC although to the input 4 3 1 2 2 4 4 3 it answers 1 2 4 when the right answer is clearly 2 1 2 3 4 Your test was added, 15 authors lost AC. Edited by author 23.06.2012 12:37 Используйте связные списки вместо массивов и не надо будет никаких извращений с предпроверкой считываемых символов. Более того, пройдет даже с использованием cin cout вместо scanf printf. I solved with stack))) time - 0.078 seconds)))) I used only one string. Nothing else. Does anybody has any idea? Me too and I dont think I'm wrong Send your email. I help you. use DFS with memorization I don't understand the 2nd sample test. Is a player go on the path from where the othe player reach? Or are the players move on different path? Each player starts from the point that the other player selects. Here's an explanation for the 2nd test 1 / \ 2 3 / \ / \ 4 5 6 7 - + + 0 If the first player chooses the 2 node, the second player will choose the 4th and win. If the first player chooses the 3 node, the second player will choose the 7th node (he prefers to draw than to loose) So, the player will choose the 3rd node, as he prefers drawing rather than loosing. Edited by author 22.06.2012 16:52 abcd aaaaabcdaaaa ans : a a a a abcd a a a a When I print answers,I print them from the end))) Sorry for my poor English)))) Edited by author 22.06.2012 15:47 I got AC , but who can tell me how to use DP there (I solved this problem without DP , using log2 ) #include <iostream> int main() { int n,i; std::cin>>n; int sum=0; if(n<0) { for(i=n;i<=1;i++) sum+=i; std::cout<<sum;
} else {
for(i=n;i>=1;i--) sum+=i; std::cout<<sum; } return 0;} You outputs 0 on test 0 when should be 1. try so ;) #include <iostream> #include <cmath> using namespace std; int main() { int a, sum = 0; cin >> a; if( a > 0 ) { for ( int i = 1; i <= a; i++) sum += i; } else { for (int i = 1; i <= abs(a); i++) sum += i; sum = 1 - sum; } cout << sum; return 0; } tell me what's wrong in my code ??? #include <stdio.h> #include <math.h> void main () { long N=-1,sum=0; int i=0; scanf("%d",&N); if (abs(N)<=10000) { if (N>0) { for (i=N;i>1;--i) { sum+=i; } } else if (N<0) { for (i=N;i<-1;++i) { sum+=i; } } printf("%ld",sum); } } for (i=N;i<-1;++i) "лежащих между 1 и N включительно." may be because 1 != -1 ? for(i=N;i<=+1;i++) Edited by author 22.02.2012 02:08 Edited by author 07.03.2012 18:11 Edited by author 07.03.2012 18:11 Try so ;) #include <iostream> #include <cmath> using namespace std; int main() { int a, sum = 0; cin >> a; if( a > 0 ) { for ( int i = 1; i <= a; i++) sum += i; } else { for (int i = 1; i <= abs(a); i++) sum += i; sum = 1 - sum; } cout << sum; return 0; } The same trouble was with problem 1313. |
|