Общий форум#include<stdio.h> #include<math.h> main() { float a,b,c,d; scanf("%f%f%f%f", &a,&b,&c,&d); printf("%6.4f\n%6.4f\n%6.4f\n%6.4f",sqrt(d), sqrt(c), sqrt(b), sqrt(a)); } Whats wrong? Edited by author 27.06.2016 15:47 Edited by author 27.06.2016 15:47 С чего ты взял что у тебя всего 4 числа? who tell u only 4 inputs? If you are using recursion function to calc the answer, then I suggest you to do it in one of some ways: 1) To write DP without using recursion. 2) To use array of memory and put there -1 if we calced the function of this parametres and 0 if not. 3) if you write in C++, inline may be will help you. If you have any questions, write. Edited by author 19.11.2010 01:08 :) Edited by author 19.11.2010 12:02 Well, give me your mail And me too - I want to see how to use recursion in this problem =))) goryinyich [dog] inbox [dot] ru Thank you!(otajanov_quvondiq@mail.ru.) scanf printf also helps Only for reading & outputting one integer? You can precalculate all the 81 values locally (it could take up 1 minute). Then use all the values to create static array: int ways[82] = { 0, 10, 45, 165, ..., 9, 1 }; int main() { int sum; cin >> sum; cout << ways[sum]; }
Edited by author 01.12.2016 23:44 I'm searching the farest node for each node via one dfs and then try to answer the query using this information: 1) if(query_dist > distance_to_farest_node_from_query_vertex) output 0 2) if query_vertex is ancestor of it's farest node then i return go_up_from(farest_node_from_query_vertex, dist_to_far_node - query_dist) 3) if dist to lca(query_vertex,farest_node_from_query_vertex) enough (d(lca)>=query_dist) just go up from query_vertex in query_dist steps. 4) if(dist to lca is not enough) then go_up_from( farest_node, farest_node_dist - query_dist) my programm passes my tricky tests,sample test and test from thread. Pls, somebody, give me more tricky tests! Edited by author 10.10.2010 22:43 ok, ac now - i count LOG2N variable as floor(log2n) but i should set it ceil(log2n); Thanks! I was wondering why I got WA until I saw your reasons. It gave me spirit,now I have got deeper realization of this problem. Edited by author 01.12.2016 19:04 Now, if you have time limit, use Buffered Reader + Hashset. It is really works. Если вы столкнулись с Ограничением по времени, попробуйте использовать связку из Buffered Reader + Hashset. Оно реально работает!!!! Java 1.8.0 I have AC at 0.14 sec, but I can see there are lot of faster solutions. So how did you optimize your solution so hard ?? hi, maybe the answer with powers from 2 to N+1 is always identical to given at this task(my AC is less than 0.14), also use some breaks like if (a[i][j] is already 1 then halt from cell computation etc.) send at night )) I don't know why I got TLE on test 3. I use bruteforce with Python. But in my PC, it runs so fast with n = 20 On test #22,we can extend two segments and get two valid circles,which circle do we choose ?? Maybe there are some error in my code... seems there can only be one circle.. Edited by author 30.11.2016 13:28 Spend one day for a typing error: alpha=atan2(y4-y3,x4-y3)+pi/2.; it's 作死 for Chinese Hi, My program pass all local tests but crashes after submit on test #3. Most probably I miss some boundary or weird pattern case. I use C++ and I took into account the fact that char's over 127 are converted to negative integers. Do you have any hint? UPD: My local test file: 31 '' like '%' '' like '' 'a' like 'a%' '·' like '·' 'f' like '[z-a]' 'a' like '[a-]' '·' like '[·a]' 'abcde' like 'a' 'abcde' like 'a%' 'abcde' like '%a' 'abcde' like 'b' 'abcde' like 'b%' 'abcde' like '%b' '25%' like '_5[%]' '_52' like '[_]5%' 'ab' like 'a[a-cdf]' 'ad' like 'a[a-cdf]' 'ab' like 'a[-acdf]' 'a-' like 'a[-acdf]' '[]' like '[[]]' '''''' like '_''' 'U' like '[^a-zA-Z0-9]' 'like' like 'like' ''' '' ' like ''' ''%' '[' like '[[]' '%' like '[%]' '_' like '[_]' ']' like ']' '^' like '^' 'like' like 'like' ''' '' ' like ''' ''%' 0.499 too close to comfort, i subitted first with GCC compiler got TLE than i submited with VC 2013 and got Accepted Edited by author 29.11.2016 18:01 Java Program: import java.io.PrintWriter; import java.util.Scanner; public class Sum { public static void main ( String [] args ) { /** * Initialize */ Scanner inputs = null; PrintWriter output = null; try { if ( args != null && args.length == 2 ) { /** * Read Inputs */ inputs = new Scanner ( System.in ); /** * For Printing Output */ output = new PrintWriter ( System.out ); Integer a = inputs.nextInt (); Integer b = inputs.nextInt (); output.println ( a + b ); } else { System.out.println ( "Only 2 Integer values are accepted as input" ); } } catch ( Exception e ) { System.out.println ( "There is an error while executing this program : " + e ); } finally { if ( inputs != null ) inputs.close (); if ( output != null ) { output.flush (); output.close (); } } } } You don't really need to check for amount of arguments, you just need to read what you're asked for. Attempt to do this simplier, without try-catch-finally construction. Try this: Test 1 input 1 ()) output 0 0 Test 2 input 1 () output 2 1 1 Test 3 input 2 () )( output 2 1 1 Test 4 input 2 () () output 4 2 1 2 Test 5 input 2 ((( ))))( output 0 0 I had WA 9 too, but now I have WA 11... I know, maybe you can try this. input (( )( )) output 6 3 1 2 3 I've WA #11 and my solution passes your tests. Maybe you know another interesting one? 6 )))((()(())(()()()())() )) (()(( (())( ()))(())( )))) Helped me to pass 9 Try following tests: 4 (( )( ) ))( 8 4 1 2 4 3 6 ((( ( )(( ))( )))(( ()) 14 4 1 5 4 6 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ll n, k, op, a[11][11], ans; string s; vector < pair < string, string > > alr; vector < pair < string, string > > lg; vector < string > out; int main(){ cin >> n; for(ll i = 1; i <= n; i++){ cin >> s; k = 0; if(s == "register"){ string lo, pa; cin >> lo >> pa; for(ll i = 0; i < lg.size(); i++){ if(lo == lg[i].first){ cout << "fail: user already exists" << "\n"; k = 3; break; } } if(k != 3){ lg.pb(mp(lo, pa)); cout << "success: new user added" << "\n"; } } k = 0; if(s == "login"){ string acc, par; cin >> acc >> par; for(ll i = 0; i < alr.size(); i++){ if(acc == alr[i].first){ if(par == alr[i].second){ cout << "fail: already logged in"; k = 2; break; } } } for(ll i = 0; i < lg.size(); i++){ if(acc == lg[i].first && k != 2){ ans++; if(par == lg[i].second){ cout << "success: user logged in"; alr.pb(mp(acc, par)); out.pb(acc); k = 1; break; } } } if(!k && ans == 0) cout << "fail: no such user"; if(!k && ans > 0) cout << "fail: incorrect password"; cout << "\n"; } ans = 0; k = 0; if(s == "logout"){ string avt; ll o; cin >> avt; for(ll i = 0; i < out.size(); i++){ if(avt == out[i]){ out[i] = "````````21"; k = 4; break; } } op = 0; for(ll i = 0; i < lg.size(); i++){ if(avt == lg[i].first){ op = 1; break; } } if(k != 4 && op){ cout << "fail: already logged out"; } else if(op) cout << "success: user logged out"; if(!op) cout << "fail: no such user"; cout << "\n"; } op = 0; k = 0; } } what is wrong??? This is my code import java.util.*; public class Task_2010 { static void kingStep(int n, int x, int y){ long countKing = 0; if((x - 1) > 0) countKing++; if((x - 1) > 0 && y + 1 <= n) countKing++; if((y + 1) <= n) countKing++; if((x + 1) <= n && (y + 1) <= n) countKing++; if((x + 1) <= n) countKing++; if((x + 1) <= n && (y - 1) > 0) countKing++; if((y - 1) > 0) countKing++; if((x - 1) > 0 && (y - 1) > 0) countKing++; System.out.println("King: " + countKing); } static void knightStep(int n, int x, int y){ long countKnight = 0; if((x - 2) > 0 && (y + 1) <= n) countKnight++; if((x - 2) > 0 && (y - 1) > 0) countKnight++; if((y + 2) <= n && (x - 1) > 0) countKnight++; if((y + 2) <= n && (x + 1) <= n) countKnight++; if((x + 2) <= n && (x + 1) <= n) countKnight++; if((x + 2) <= n && (y - 1) > 0) countKnight++; if((y - 2) > 0 && (x + 1) <= n) countKnight++; if((y - 2) > 0 && (x - 1) > 0) countKnight++; System.out.println("Knight: " + countKnight); } static long bishopStep(int n, int x, int y) { long countBishop = 0; int left = x - 1; int right = n - x; if(y + left <= n){ countBishop += left; } else countBishop += n - y; if(y + right <= n){ countBishop += right; } else countBishop += n - y; if(y - left > 0){ countBishop += left; } else countBishop += y - 1; if(y - right > 0){ countBishop += right; } else countBishop += y - 1; System.out.println("Bishop: " + countBishop); return countBishop; } static long rookStep(int n, int x, int y){ long countRook = (x - 1) + (n - x) + (y - 1) + (n - y); System.out.println("Rook: " + countRook); return countRook;
} public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int x = sc.nextInt(); int y = sc.nextInt();
kingStep(n,x,y); knightStep(n,x,y); long queen = (bishopStep(n,x,y) + rookStep(n,x,y)); System.out.println("Queen: " + queen);
} } In this task, use StreamTokenizer instead Scanner, otherwise will be TLE Thank you for this tip. It helped me a lot. I also didn't manage to implement bubble sort (as suggested in the problem tip), because I was getting TLE on test #12. I used a map with solved problem count as keys and team id lists as values instead. Thanks for the tip. Seems unfair we have to jump through hoops with java/scala as they are slower on a single run. Mine is O(m*logn*logn)and got AC in 0.75s,958 KB. I used a BST,a Hash table and Binary Search. I think my algorithm is not good enough and I'm interested in how you solve this. EM:tczw@sina.com Mine is O(mlogm) and got AC in 0.109s, 474kb I used balance binary search tree. What is your mlogm algorithm? How did you use it ? O(mlogn), lazy segment tree, 0.078. Edited by author 16.03.2014 14:27 Mine is simple tree O(mlog(m)) and accepted time is 0.015 Mine is (mlogn), implicit segment tree use while (v < 0.01) use while (v < 0.01) Thank u so much... ^_^ Use geometric series. 1 + 1/k + 1/k^2 + ... = 1 / (1 - 1/k) I always AC with long code, I want to short my code, anyone has ideas with short code? |
|