Общий форум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? try to reproduce the out in sample I read the solution from the Codeforces post mentioned in some previous topic http://codeforces.ru/blog/entry/1797#comment-34342Here I restate it more clearly. In the graph G, there are n vertices V1, V2, ..., Vn. Create another graph H which has 2n vertices U1, U2, ..., Un, Un+1, Un+2, ..., Un+n. There are edges (Ui, Uj+n) and (Uj, Ui+n) in H iff there is an edge (Vi, Vj) in G. H is a bipartite graph with L = {U1, U2, ..., Un} and R = {Un+1, Un+2, ..., Un+n}. Find a minimum vertex cover C in H. For 1 <= i <= n, if Ui and Ui+n are both in C, assign k to Vi; if only one of Ui and Ui+n is in C, assign k/2 to Vi; otherwise, assign 0 to Vi. Now Vi for 1 <= i <= n are all assigned a value. They are the final answer. Can someone provide a proof? I don't understand why this solution works at all. Edited by author 25.11.2016 21:29the statement says "You should help him determine the expected value of prize in case of his victory" but I believe it should be the case of anyone's victory. can someone who solved the problem please clarify this? thanks Edit: I got accepted assuming the original statement is wrong Edited by author 25.11.2016 17:53 test 7 I output leading zeroes but not give WA verdict,just WA on test 9 Can somebody give me the whole explanation to this problem. Thanks beforehand! If you have two different sets A = {a1, a2, a3} and B = {b1, b2, b3, b4} then we have |A| * |B| = 3 * 4 = 12 ways to choose a pair (a[i], b[j]). i\j b[1] b[2] b[3] b[4] a[1] [1,1] [1,2] [1,3] [1,4] a[2] [2,1] [2,2] [2,3] [2,4] a[3] [3,1] [3,2] [3,3] [3,4] Modern language solution looks like that: map<string, int> cnt; for (auto color : {"Blue", "Red", "Yellow"}) cin >> cnt[color]; int colors; cin >> colors; int ways = 1; for (int i = 0; i < colors; i++) { string color; cin >> color; ways *= cnt[color]; } cout << ways; Edited by author 24.11.2016 16:04 Edited by author 24.11.2016 16:07 Why number of digits of b is less than number of digits of a1 or a2, and answer is not Impossible, I output Impossible but WA. can we output leading zeroes?? oops seems you can remove all matches... what's the result of test 4: 12+4456=579 4 anyone help? I know 123+456=579, it is a reading comprehension problem.... My English is poor, but I read it by a large time and I understood. N=2,K=10 ==>it's a "2 digits 10-base" 10,11,...98,99... in Chinese "2位的十进制数字" if k equal to 30 and n equal to 2 , numbers are 30 , 31 , 32 , 33 , .......,99 is it true? Edited by author 10.10.2012 23:50 Edited by author 10.10.2012 23:50 10 based notation of 10 is 10 but 2 based notation of 10 is 1010 I understand if k equal to 30 and n equal to 2 , numbers are 30 , 31 , 32 , 33 , .......,99 is it true? Edited by author 10.10.2012 23:50 Edited by author 10.10.2012 23:50 I don't understand. How can k equal to 30... In statement there is limit 2 ≤ K ≤ 10; N位数长,K进制,的所有数字中,不包含两个连续0的所有数字的个数。 oh my god!i like your answer! Help me WA4? #include <iostream> #include <string> #include <string.h> #include <algorithm> using namespace std; string S, ss, s; int k, l, r, mid; int main(){ cin >> S; int n = S.size(); if(n == 1){ cout << S; return 0; } for (int i = n - 1; i >= 0; i --){ k = n - i; if(i - k >= 0){ ss = S.substr(i, k); s = S.substr(i - k, k); reverse(s.begin(), s.end()); //cout << ss << ' ' << s << endl; if(ss == s){ l = i - k; mid = i; r = i + k; continue; } } k --; if(i - k >= 0){ ss = S.substr(i + 1, k); s = S.substr(i - k, k); reverse(s.begin(), s.end()); //cout << ss << ' ' << s << endl; if(ss == s){ l = i - k; mid = i; r = i + k; } } } //cout << l << ' ' << r << endl; if(!l && !r || (l == 0 && r == n - 1)){ s = S.substr(0, n - 1); cout << S; reverse(s.begin(), s.end()); cout << s; } else{ s = S.substr(0, l); reverse(s.begin(), s.end()); cout << S << s; } return 0; } problem description said dragon will not use breath two times, but test 21 there is at least three breath in the input file... hope admin can fix it.. oops I misunderstood "in a row" is "in a row" means cosecutive?? I think we must use O(2^20*10) dynamic programming ,because there maybe two breath in a row brute_force will definitely got TLE Don't know, what else to test ... Any ideas? I think many people can not solve this problem because they do not have enough knowledge. You should know "Problem LCA" and "Segment Tree" that to solve the problem. My algo is O(n*sqrt(n)+m*log(n)), but i can solve for O(n+m*log(n)) (LCA can be solved for O(1) with preprocess or sqrt(n) without preprocess). P.S. What is the optimal asymptotic behavior? Edited by author 20.11.2016 23:27 Edited by author 20.11.2016 23:27 Edited by author 20.11.2016 23:28 Well, there were quite a lot of LCA + segment tree problems by now, so by now people mostly should know what that is :) As for me, i just took my solution to http://acm.timus.ru/problem.aspx?space=1&num=1471 and only had to modify it very slightly. Just, in there you had to operate with only minimums, and here you need to find a minimum in a certain range of your array of minimums, so there's that additional layer of minimums. |
|