Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения |
whats wrong???????? | shailendrasky | 1209. 1, 10, 100, 1000... | 27 дек 2013 01:52 | 1 |
#include <stdio.h> int main() { long int k,a,n; scanf("%ld",&n); while(n--) { scanf("%ld",&k); a=1; while(k-a>0) k=k-(a++); if(k==1) printf("1\n"); else printf("0\n"); } } Edited by author 27.12.2013 01:54 |
simple algo | dula | 1209. 1, 10, 100, 1000... | 27 дек 2013 01:47 | 2 |
if((8*(input) - 7) -> integer) cout << 1; else cout << 0; wrong!!! check for input=3.....!!!!! if((8*(input) - 7) -> integer) cout << 1; else cout << 0; |
WA 3 ---->C++ pls help | DeDaRm | 1209. 1, 10, 100, 1000... | 5 дек 2013 19:32 | 1 |
#include <iostream> #include <cmath> using namespace std; int main () { int x,e; double nk; cin >> x; int *b=new int[x]; for (e=0; e<x; ++e) { cin >> b[e]; } for (e=0 ; e<x; ++e ) { nk = (pow((8*b[e]-7),0.5)-1)/2; long int k = static_cast< int >( nk ); if ( nk==k ) { cout << "1 "; } else { cout << "0 "; } } system ("pause > void"); } Edited by author 05.12.2013 19:32 |
It accepted!!! | ScaleS | 1209. 1, 10, 100, 1000... | 8 ноя 2013 22:25 | 5 |
var n,i : word; p : real; function check(A : real):boolean; begin if frac((1+sqrt(8*A-7))/2) = 0.0 then check := true else check:=false; end; begin readln(n); for i:=1 to n do begin readln(p); if check(p) then write('1 ') else write('0 '); end; end. Yes, because the difference of correct answer (when you use -1) and your is 2, so there is no difference to use +1 or -1! )))) frac((1+sqrt(8*A-7))/2) Where from it formula? What means? Could you take a look at my c++ code? I did the same as you but i never pass test #3 !! #include <iostream> #include <cmath> bool isOne (long n) { double intPart; double para = (1 + sqrt ( 8 * n -7)) / 2; double fractPart = modf(para, &intPart); if (fractPart == 0.0) return true; else return false; } int main() { using namespace std; long value; long num, i = 0; cin >> num; while (i < num) { cin >> value; if (isOne (value)) cout << "1 "; else cout << "0 "; i++; } return 0; } |
Test #1 | Added | 1209. 1, 10, 100, 1000... | 14 сен 2013 13:24 | 1 |
What's wrong with Test #1? I've 0 0 1 0 |
WA 1 help!!! | Alexandr-pro | 1209. 1, 10, 100, 1000... | 7 сен 2013 18:27 | 1 |
#include <stdio.h> #define c 65535 int main() { long long k = 0; long long a[c]; long n = 0,i,ot[c],j,t;
a[0]=1; for (i=1; i<=c; i++) { a[i]=a[i-1]+i; } scanf("%ld",&n); for (i=0; i<n; i++) { scanf("%lld",&k); for (j=0; j<c; j++) { t=0; if (a[j]==k) { t=1; break; } } ot[i]=t;
} for (i=0; i<n; i++) { printf("%ld ",ot[i]); } return 0;
} |
Test #3 -Time limit exceeded (C#) | Arantir | 1209. 1, 10, 100, 1000... | 14 авг 2013 15:52 | 3 |
Why it is so slowly??? I use standard formula with "sqrt(8*N-7)". int L = int.Parse(Console.ReadLine()); string answer = ""; for (int i = 0; i < L; i++) { if (Math.Sqrt(8 * long.Parse(Console.ReadLine()) - 7) % 1 == 0) answer += "1 "; else answer += "0 "; } Console.Write(answer); I can't imagine shortest solution... What's the matter? Many people has used C# successful in problem 1209. Edited by author 28.11.2011 03:09 I don't know c# but I think it's correct. why you don't use c++? Why it is so slowly??? I use standard formula with "sqrt(8*N-7)". int L = int.Parse(Console.ReadLine()); string answer = ""; for (int i = 0; i < L; i++) { if (Math.Sqrt(8 * long.Parse(Console.ReadLine()) - 7) % 1 == 0) answer += "1 "; else answer += "0 "; } Console.Write(answer); I can't imagine shortest solution... What's the matter? Many people has used C# successful in problem 1209. Edited by author 28.11.2011 03:09 Compare with this code static void Main(string[] args) { int len = int.Parse(Console.ReadLine()); int[] mas = new int[len]; int max = 0; for (int f = 0; f < len; f++) { mas[f] = int.Parse(Console.ReadLine()); if (mas[f] > max) max = mas[f]; } foreach (long i in mas) { double ig = (Math.Sqrt(8*i-7))%1; if (ig == 0) Console.Write("1 "); else Console.Write("0 "); } } |
TL test3 | Andrey | 1209. 1, 10, 100, 1000... | 20 июл 2013 13:13 | 1 |
Делал на питоне: import math def solve(): n = input() s = '' for i in xrange(n): k = input() d = math.sqrt((k << 3) - 7) result = int(d) if result == d and result & 1: s += '1 ' else: s += '0 ' print s solve() Выдает TL, как ускорить? Пробовал сразу ответ выводить - на моих тестах это дольше по времени. k << 3 заменял на k * 8, result & 1 менял на result % 2 - все равно TL. Python 2.7 Для себя понял, что самое времязатратное - ввод/вывод. Поэтому AC получил так: import math import sys stringArray = sys.stdin.read().split() i = 0 s = '' for string in stringArray: if i == 0: i += 1 continue k = int(string) d = math.sqrt((k << 3) - 7) result = int(d) if result == d and result & 1: s += '1 ' else: s += '0 ' print s Но все равно интересует - есть ли способ ускорить первое решение? |
Unable to understand question | annonynous | 1209. 1, 10, 100, 1000... | 22 июн 2013 18:20 | 4 |
for the given 5 sample how 4 values 0 0 1 0 are coming. please explain anybody 1101001000 1 0 0 0 0 k: 1234567891011 example: k = 2 ==> 1 k = 3 ==> 0 k = 7 ==> 1 You must know how to generate the sequence first! And then the input gives the position for the given 5 sample how 4 values 0 0 1 0 are coming. please explain anybody |
No subject | second | 1209. 1, 10, 100, 1000... | 2 май 2013 21:32 | 1 |
Edited by author 03.05.2013 12:20 |
where is wrong?Help me,please! | csyzcyj | 1209. 1, 10, 100, 1000... | 25 мар 2013 20:13 | 3 |
My program(LANG c)is in the following: #include<stdio.h> #include<stdlib.h> #include<cmath> int k[60000],value,i,n; int main() { scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&k[i]); for(i=1;i<=n;i++) { if(k[i]==0) printf("0 "); else { value=(int)sqrt((k[i]-1)*2); if((value*(value+1))==2*(k[i]-1)) if(i==n) printf("1\n"); else printf("1 "); else if(i==n) printf("0\n"); else printf("0 "); } } return 0; } BUT it can't compile,said that " d9b0f699-b537-45eb-b286-ce7765096c87d9b0f699-b537-45eb-b286-ce7765096c87(16) : error C2668: 'sqrt' : ambiguous call to overloaded functionS:\checker\compile\vc10\include\math.h(589): could be 'long double sqrt(long double)' S:\checker\compile\vc10\include\math.h(541): or 'float sqrt(float)' S:\checker\compile\vc10\include\math.h(127): or 'double sqrt(double)' while trying to match the argument list '(int)' " BUT in my computer(Windows 7),I can compile and run it,and the answer is right. So I don't know where is wrong?And I don't know how to modify it.Help me,please! Edited by author 22.02.2013 15:09 length array int k[65535] becouse (1 ≤ N ≤ 65535) My program(LANG c)is in the following: ................... int k[60000],value,i,n; ................... value=(int)sqrt((k[i]-1)*2); // sqrt(double((k[i]-1)*2)) ................... Edited by author 22.02.2013 15:09 your wrong is use (int) with sqrt. template for SQRT is sqrt(double). you must to give for sqrt double variable, and if you need int variable, you must to appropriate value in int variable. Signs after a comma will be removed. I am sorry for my bad English. Edited by author 25.03.2013 20:14 |
Test 1 help please. | freelife | 1209. 1, 10, 100, 1000... | 5 мар 2013 01:54 | 2 |
Hi! Please help russian shoolboy Where the error is? I realized that '1'-s are in the field of the sequence. 1 2 4 7 11 16 int main() { long a,j,i,n; cin>>n; for(int x=0; x<n; x++) { cin>>a; i=1; j=1; while (a>i) { i=i+j; j++; } if (a==i) cout<<1; else cout<<0; } return 0; } while (a>i) { i=i+j; j++; } |
Time limit exceeded | david | 1209. 1, 10, 100, 1000... | 11 фев 2013 02:49 | 2 |
What's wrong? var n,p,k,i:longint; m:array [1..65535] of longint; begin readln(n); p:=1; k:=0; for i:=1 to n do readln(m[i]); for i:=1 to n do begin while m[i]>p do begin p:=p+k; k:=k+1; end; if p=m[i] then write(1,' ') else write(0,' '); p:=1; k:=0; end; end. you shold use maths method, maths formula |
Test 3 crash - floating-point invalid operation | SemenB | 1209. 1, 10, 100, 1000... | 7 янв 2013 00:51 | 1 |
Please help Why am I getting floating-point invalid operation on test 3? Would it be possible to see the test values? program pr_1; var n, i, x: longint; a: real; begin read(n); for i:=1 to n do begin read(x); a:= (1 + sqrt(8*x-7))/2; if (Frac(a) = 0.0) then write('1 ') else write('0 '); end; end. |
Why? | AJProg | 1209. 1, 10, 100, 1000... | 7 ноя 2012 02:39 | 2 |
Why? AJProg 5 мар 2012 01:09 Could you please explain where this formula comes sqrt (8 * N-7) Edited by author 05.03.2012 01:14 Edited by author 05.03.2012 01:17 Извините, что по-русски. Формула немного другая. Единицы стоят на местах, выражаемых формулой Sn = n*(n+1)/2 + 1, где nэN и n>0. Эта формула получена из соображений арифметической прогрессии. Из этой формулы можно получить, что n = sqrt(2*Sn-1.75) - 0.5 или n = (sqrt(8*Sn-7)-1)/2. Если nэN и n>0, то Sn существует, и на месте Sn стоит единица, иначе - ноль. |
wrong wrong wrong | primumnah@gmail.com | 1209. 1, 10, 100, 1000... | 4 ноя 2012 01:12 | 1 |
Вот такой код. Хочу найти ошибку. Но найти не могу. Для всех перебранных случаев все вычисляется как надо. Не пойму как пройти тест. #include <iostream> using namespace std; int foo(short pos); int main() { long i; short int y; cin>>i; for(int cnt_1 = 0; i > cnt_1; cnt_1++){ cin>>y; cout<<foo(y)<<" "; } } int foo(short int pos) { short int res(1); short int i(0); do { res = res + i; i++; } while(res<pos); if(res != pos) return 0; else return 1; } Какая тут ошибка? |
why i get WA on test 3?(C) | Ahmet Terzi(Ottoman)Devlet-i Âli Osman | 1209. 1, 10, 100, 1000... | 31 авг 2012 17:55 | 1 |
#include <stdio.h> #include <math.h> main() { int a,x[65535],i,t,delta; float x1; scanf("%d",&a); for( i = 0 ; i < a ; i++ ) scanf("%d",&x[i]); for( i = 0 ; i < a ; i++ ) { t = (x[i] - 1) * 2; delta = 1 + 4 * t; x1 = sqrt(delta); printf("%d ",fmod(x1,1.0) == 0); } return 0; } |
Тут где ошибка помогите | Hamdam | 1209. 1, 10, 100, 1000... | 6 июн 2012 23:16 | 4 |
#include <iostream> using namespace std; int main () { unsigned int A[65536]; unsigned short int N,Y; cin>>N; for (int i=1; i<=N;i++) cin>>A[i]; for (int i=1;i<=N; i++) { int S=0,j=1; bool k=true; while (k) { S+=j; j++; if (A[i]<=S) k=false; } Y=S-A[i]; if (((j-1)-Y)==1) cout<<"1"<<" "; else cout<<"0"<<" "; } return 0; } Edited by author 06.06.2012 18:42 hi mister Hamdam your code has any mistake it's truely code is mine so you want to see it? please phone to me if you have any questions phone number: +998916378115 Ok!!! Let's take it!!! #include <iostream> #include <math.h> using namespace std; int main() { long float m,n; int N; cin>>N; for (int i=1; i<=N; i++) { cin>>m; n=(1+sqrt(8*m-7))/2; if((1+sqrt(8*m-7))/2==floor((1+sqrt(8*m-7))/2)) cout<<1<<" "; else cout<<0<<" "; } cin>>N; return 0; } Kottakon raxmat ! Edited by author 06.06.2012 23:17 |
Time Limit In Java | RoninFeng | 1209. 1, 10, 100, 1000... | 22 фев 2012 05:09 | 4 |
Hi! Why could be time limit on 3 test here: private void solve() { int N = nextInt(); String res = ""; for (int i = 0; i < N; i++) { long idx = nextLong(); double f = Math.sqrt(8*idx - 7); if (f - (int)f == 0) { res += "1 "; } else { res += "0 "; } } out.print(res); } May i don't know some fast way to find if integer is perfect square? I know that on C++ is all right, but want to understand how to make it in java. I see you have quite a lot of accepted problems in java, so you're not novice. My advice is: generate a big test, then run some kind of profiler or just comment some lines of your code and see when you'll get biggest boost in execution time. After you find problematic line in your code it should become obvious how to fix it. Tnx for advice) I agree it's the best way... I've just tried to find the fastest one in other people experience :) ---------- found the problem) string concatination is very expensive) for future generations - this works fine: private void solve() throws IOException { int N = nextInt();
byte[] outArr = new byte[N]; for (int i = 0; i < N; i++) { long idx = nextInt(); double f = Math.sqrt(8 * idx - 7); if (f - (int) f == 0) { outArr[i] = 1; } else { outArr[i] = 0; } }
for (int i = 0; i < outArr.length; i++) { out.print(outArr[i]); out.print(' '); } } Edited by author 21.02.2012 12:16 Edited by author 21.02.2012 12:17 I'm glad it helped. For future: there is a StringBuilder class in Java, it's in fact a mutable string(contrary to immutable String class). It supports appending characters and strings to itself in linear time, so you could use it in this problem for example. It has other features of course, use Javadocs to find out more! |
Why??? WA on test 1 | adminsever | 1209. 1, 10, 100, 1000... | 25 янв 2012 19:20 | 5 |
test ID: 4088875 Edited by author 23.01.2012 20:49 #include <iostream> #include <Cmath> void main() { int n, i; long nArray; static int q[65535]; scanf("%d", &n); for(i = 0; i < n; i++) { scanf("%l", &nArray); if (floor((sqrtf(1 + 8 * (nArray - 1)) - 1) / 2) == ((sqrtf(1 + 8 * (nArray - 1)) - 1) / 2)) q[i] = 1; else q[i] = 0; } for (i = 0; i < n; i++) { printf("%d ", q[i]); } } Hi, Some observations: - you read a long with %l instead of %ld, which gives then WA3. The %l is not a valid scanf format specifier. On GCC the function doesn't even work (no value read) and on VS2010 the function works but returns junk. - the multiplication 8 * (nArray - 1) overflows the float type as also the long type (nArray can be at most 2^31 - 1). You should convert the multiplication to something bigger, for example the double type. Change also the sqrtf to sqrt. You'll get AC Thank you! I used type Double and %lf to the read. And get AC. P.S. Sorry for my bad English :( |