| Show all threads Hide all threads Show all messages Hide all messages |
| Please, help! | Shaft | 1327. Fuses | 15 Jul 2015 20:05 | 1 |
I can't understand what's wrong in my code, it write 51 instead of 50 #include <iostream> using namespace std; int main() { unsigned short a, b, c; cin >> a >> b; c = (b - a) + 1; if(c % 2 == 0) cout << c / 2; else cout << (c / 2) + 1; /// 1! 2 3! 4 5! 6 7! 8 9! 10 11! 12 13! 14 15! return 0; } |
| THis is supposed to work. What is wrong? | Luigi Brito | 1001. Reverse Root | 15 Jul 2015 11:29 | 3 |
#include <stdio.h> #include <math.h> main() { int a=0; float b=0; while (!feof(stdin)) { scanf("%d", &a); b=sqrt(a); if (feof(stdin)) printf("%.4f\n",b); } } It works fine at my PC. But it keeps saying wrong answer? #include <stdio.h> #include <math.h> main() { int a=0; float b=0; while (!feof(stdin)) { scanf("%d", &a); b=sqrt(a); printf("%.4f\n",b); } } You should use a long long data type, because the int type supports only 2^32 as max. Please, read the contraints of the problem. There says that the number could be as big as 10^18 (a lot bigger than 2^32). Try with long long. Hope it be useful for you. |
| Подводные камни "1001.Обратного корня" | Yegor | 1001. Reverse Root | 15 Jul 2015 02:35 | 2 |
//if 'double s[130196]' before 'int main()' - all is OK!! //but if 'double s[130196]' in 'int main()' then Runtime error (stack overflow)!!!!!!! //------------------------------------------------- //AND MAGIC №2: //any number after 130196 (for example 130196,130197...) in 'double s[130196]' - all is OK!! //BUT numbers before 130196, for example 130195, 130194... then Runtime error (access violation)!!! //------------ //on the internet people use 'double s[131072]' - it is 2^17, why???? if i can use 130196 //------------------ #include <iostream> #include <iomanip> #include <cmath> using namespace std; double s[130196];// if 130195 or < then Runtime error (access violation)!!! int main() { //double s[130196]; - if in 'int main()' then Runtime error (stack overflow) int t = 0; while (cin>>s[t]){t++;} while(t>0){cout<<fixed<<setprecision(4)<<sqrt((double)s[--t])<<endl;} return 0; } //why why why ??)) Edited by author 14.07.2015 17:12 Array from main function is kept in stack memory, and this memory is limited. You should declare it as global, or increase stack size. |
| Runtime error in Java 1.7 test 2 help me please | Axmadjon | 1370. Magician | 14 Jul 2015 22:30 | 2 |
import java.util.Scanner; public class _1370 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int digitos = in.nextInt(); int cliques = in.nextInt(); String saida = ""; String parte2 = ""; for (int i = 1; i <= cliques; i++){ saida += in.nextInt(); } for (int i = cliques+1; i <= digitos; i ++){ parte2 += in.nextInt(); } parte2 += saida; System.out.println( parte2.substring(0,10) ); } } you are using in.nextInt() to get the input from the user for a String. That is used for integers. You should be using in.next() or in.nextLine() for String. |
| WA 5 | Ivan | 1242. Werewolf | 14 Jul 2015 21:46 | 1 |
WA 5 Ivan 14 Jul 2015 21:46 Can anybody send me the fifth test of this problem? My program always crushes on it. I think it's something wrong when input my data int size; struct point{ int number; bool pr; }; vector<point> matrix[1000]; int main(){ int name1, name2; point c; char hg='0'; vector<int> victims; cin >> size; while (hg != 'B'){ cin >> hg; if (hg != 'B'){ cin >> name2; name1 = atoi(&hg); c.pr = true; c.number = name2 - 1; matrix[name1 - 1].push_back(c); c.pr = false; c.number = name1 - 1; matrix[name2 - 1].push_back(c); } } for (int i = 0; i < 4; i++) cin >> hg; while (std::cin >> name1) victims.push_back(name1 - 1); |
| Tests | Felix_Mate | 1465. Pawn Game | 14 Jul 2015 15:22 | 1 |
Tests Felix_Mate 14 Jul 2015 15:22 987654321 => white 123456789 => white 666 => black 999 => white 8 => black 13 => white 19 => white 5 => white Edited by author 26.12.2015 22:50 |
| No subject | MD MOINUL HOSSAIN | 1585. Penguins | 14 Jul 2015 02:07 | 1 |
|
| WA 1!!! HEEEEEEEELP!!! | Felix_Mate | 1684. Jack's Last Word | 13 Jul 2015 18:59 | 1 |
I can't find any error. My program solve all tests,my I got WA1!!! My code: var Z:array[1..151000] of longint; A,C:array[1..151000] of char; N,L,R,i,j,k,ind,M,t:longint; ch:char; find:boolean;
function Min(x,y:longint):longint; begin if(x>y) then x:=y; Min:=x; end;
BEGIN N:=0;
ch:='a'; while(ord(ch)>50) do begin read(ch); if(ord(ch)>50) then begin inc(N); A[N]:=ch; end; end;
A[N+1]:='+'; ind:=N+1; inc(N); readln;
ch:='a'; while(ord(ch)>50) do begin read(ch); if(ord(ch)>50) then begin inc(N); A[N]:=ch; end; end;
Z[1]:=N; R:=0; L:=0;
for i:=2 to N do begin if(i<=r) then Z[i]:=min(R-i+1,Z[i-L+1]) else Z[i]:=0; while(i+z[i]<=N)and(A[i+z[i]]=A[z[i]+1]) do inc(z[i]); if(i+z[i]-1>r) then begin L:=i; R:=i+z[i]-1; end; end;
find:=true; i:=N; while(i>=ind+1) do begin k:=i; while(i>=ind+1)and(Z[i]<k-i+1) do dec(i); if(i<ind+1) then find:=false; dec(i); end;
if(find) then begin writeln('No '); i:=N; M:=1; while(i>=ind+1) do begin k:=i; while(i>=ind+1)and(Z[i]<k-i+1) do dec(i); t:=M; for j:=k downto i do begin C[t]:=A[j]; inc(t); end; C[t+1]:=' '; M:=t+2; dec(i); end;
for i:=M-2 downto 1 do begin write(C[i]); end; end else begin write('Yes'); end; END.
|
| I use DFS, how to solve it by DP? | hliu20 | 1437. Gasoline Station | 13 Jul 2015 10:21 | 2 |
DFS, record the state, if come into a state appeared before , ignore it. DFS is very slow, can anybody give some hints to DP? Это и есть ДП. Ведь ты переходишь по сути в известные состояния(т.е.уже просмотренные) и новые,для которых рассматриваешь переходы.Просто у нас не совсем стандартные размерности "подзадачи". ДП-это не только реккурентные соотношения. |
| How to make this code faster?? Please, help | Najmaddin Akhundov | 1073. Square Country | 12 Jul 2015 10:39 | 4 |
#include <iostream> #include <cmath> #include <algorithm> using namespace std; int function(int n) { if (n == 1) return 1; else if (n == 0) return 0; else{
int k = 999999999; for (int i = 1; i <= sqrt(n); i++) { int a = function(n - i*i); if (a < k ) k = min(k, a); } return function(k) + 1;
}
} int main() { int n; cin >> n; cout << function(n) << endl; } Thank you Noob, I got an AC with your help. One optimization No need to start loop from always from 1 , sqrt(N)/2 is enough ;) thing why?. :) |
| java AC 1st place | esbybb | 1167. Bicolored Horses | 12 Jul 2015 09:59 | 1 |
package timus; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.util.Arrays; import java.util.StringTokenizer; public class p1167 { static int a[], totals[]; static int h, s; static int min = Integer.MAX_VALUE; public static void main(String[] args) throws FileNotFoundException { InputStream is = System.in; // is = new FileInputStream(new File("A.txt")); FastScanner sc = new FastScanner(new InputStreamReader(is)); h = sc.nextInt(); s = sc.nextInt(); int k[] = new int[h]; for (int i=0; i<h; i++) { k[i] = sc.nextInt(); } totals = new int[h+1]; totals[1] = k[0]; for (int i=2; i<h+1; i++) { totals[i]=totals[i-1]+k[i-1]; } int maxcap = h-s+1; int unhappines[][] = new int[h+1][h+1]; for (int i=1; i<=/*maxcap*/h; i++) { int up = Math.min(h, maxcap+i); for (int j=i; j<=up; j++) { int len = j-i+1; int ones = totals[j]-totals[i-1]; unhappines[i][j] = (len-ones)*ones; } } int a[][] = new int[h+1][s+1]; for (int i=1; i<=h; i++) { Arrays.fill(a[i], Integer.MAX_VALUE); } int maxes[] = new int[s+1]; for (int i=1; i<=s; i++) { maxes[i] = maxcap+i-1; } for (int i=1; i<=maxcap; i++) { a[i][1] = unhappines[1][i]; } for (int stable=2; stable<=s; stable++) { for (int i=stable; i<=maxes[stable]; i++) { for (int j=i; j<=maxes[stable]; j++) { int prev = a[i-1][stable-1]; a[j][stable] = Math.min(a[j][stable], unhappines[i][j]+prev ); } } } System.out.println(a[h][s]); } static class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(Reader in) { br = new BufferedReader(in); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } } } |
| TLE on first test | SergeiEgorov | 1102. Strange Dialog | 12 Jul 2015 03:29 | 1 |
I don't know why my O(N) solution is crashing on 1st test. Code on C++11: http://ideone.com/BZIoKv Maybe I don't know some disadvantages of C++? Or it's my algorithm error? |
| For WA#9 | Prime | 1748. The Most Complex Number | 11 Jul 2015 16:09 | 2 |
Use cin cout for c++ Edited by author 29.10.2013 13:59 thx for your help or I will be insane. |
| Output limit exceeded | Wroclaw Smurfs | 2058. 100500 palidnromes | 11 Jul 2015 15:09 | 1 |
Are you sure the limit is properly set? (test 16, possibly 6*10^5 integers at output) |
| What is the role of K? | Algorist | 1194. Handshakes | 10 Jul 2015 20:24 | 7 |
Does it matte how many couples there exist? And, eventually, when a group of 10 hobbits remains unsplit, do I have to split it? I mean, it's possible for some hobbits o remain unsplitted..... what should I do with them? i just read it and nothing else -_- > i just read it and nothing else -_- The role is that: you can give answer only reading n and k. =) =) Here is a small test case: 12 0 1 3 2 5 3 5 4 2 2 5 5 1 6 1 7 1 8 1 9 1 3 2 10 2 11 3 4 2 12 1 13 1 10 2 14 1 15 1 11 2 16 1 17 2 17 2 18 1 19 1 The answer is 66. It is given to understand when to stop reading cases, I guess. If you use EOF checking and there will be anything else in the input, your solution will fail. |
| Who can help? | Felix_Mate | 1339. Babies | 10 Jul 2015 13:50 | 1 |
Edited by author 23.08.2015 14:38 |
| Data | xuesu | 1557. Network Attack | 10 Jul 2015 13:42 | 2 |
Data xuesu 17 Feb 2015 20:53 18 32 5 11 9 2 17 16 16 7 2 12 13 2 16 4 5 17 4 13 14 17 17 17 11 3 11 15 9 3 13 10 3 8 16 13 7 16 10 11 11 13 14 8 7 4 16 10 1 11 15 2 2 12 13 12 1 14 3 14 8 6 14 1 18 1 ans:65 Re: Data zhengjinke2123 10 Jul 2015 13:42 5 7 4 5 1 2 2 3 3 4 3 4 3 4 1 5 ans : 6 |
| be carefull ... | arrammis | 1153. Supercomputer | 9 Jul 2015 18:13 | 1 |
If you use newton's method to find a square root make sure that your division algorithm for 2 big integers is fast enough to handle quickly a lot of divisions that requires newtons method, otherwise you will get TL ... even with O(n*log(BASE)) time complexity division algorithm your going to get TL. Faster division at O(n) is described in Knuth's The Art of Computer Sience 2 edition, page 298 or 299... So in case if yo get TL with newton's method (which has got actually better time complexity than binary search root finding) just use binary search algo for root with BASE = 10^9 for you big integers, it needs only division by 2, *, +, and - operations needed for big integer. If input contains 600 digits you will only need 600 / 9 array elements to store that number ... and with less divisions you will get AC! take care ... Edited by author 09.07.2015 18:17 |
| Why am I getting WA1 even though it is giving correct answer when I run in my terminal? | bluestar | 1149. Sinus Dances | 9 Jul 2015 01:09 | 1 |
Found the mistake :) Edited by author 09.07.2015 01:22 |
| Idea | Felix_Mate | 1078. Segments | 8 Jul 2015 12:21 | 1 |
Idea Felix_Mate 8 Jul 2015 12:21 I solved the problem by using a topological sorting.The vertices are segments.The arcs of the graph characterize nesting |