Common Boardwhat is 11 test? I think I checked everything possible variants? can you help me? It was replied to before. 75501. used dijkstra and update the probability (distance in normal dijkstra) of node v for v like below: dis[father[v]]=dis[father[v]] + edge(father[v],v).value - dis[father[v]]*edge(father[v],v).value is there any problem?! I'm not good enough in probability theory... Edited by author 15.08.2015 22:01 dijkstra doesn't do the job the problem asks for the <<shortest path>> even if it isn't the minimum of all ( but of course it should be minimal among all shortest path) tnx! I wasn't so careful in reading the problem! 1)3 111 111 111 yes 2)3 111 101 111 no 3)5 11100 10000 00011 11000 00000 no 4)5 11111 00011 01111 00001 00111 yes I am getting wrong answer. But output is identical in my computer. Here is my code - #include <stdio.h> #include <math.h> #define ARRSIZE 32768 int main(){ unsigned long int n, a[ARRSIZE]; int i = -1; while(!feof(stdin)){ i++; scanf("%lu", &n); a[i] = n; } i--; for(; i >=0; i--){ printf("%0.4lf\n", sqrt(a[i])); } return 0; } 1 2 3 4 1 3 4 2 1 4 2 3 2 4 3 1 2 3 1 4 2 1 4 3 3 2 4 1 3 4 1 2 3 1 2 4 4 2 1 3 4 1 3 2 4 3 2 1 Edited by author 14.08.2015 23:03 111 211 3 10 the answer is 0 or 1... why? thanks you.. Hello, here is my code using System; public class Program { public static void Main(String[] args) { var a = Convert.ToInt32(Console.ReadLine()); var b = Convert.ToInt32(Console.ReadLine()); var ans = (b-a + 1) / 2; if (b % 2 > 0) ans++; Console.WriteLine(ans); } } I can not find out the problem :( Here is a special case test: Input: 2 4 1 2 3 4 Possible output: 49 1 2 50 49 Thanks for test! Your test help me to understand the problem Create an unordered map <int, set <int> > and for each number in the input insert it's index to the corresponding position in the map, then for each query use manipulations with upper_bound in the set. Looks like O(nlogn + qlogn). Edited by author 13.08.2015 20:29 well the way i thought is simply calculate the number and see but before using numbers i used long's and calculated it %10000 and that was enough i used the writing in binar of the number n to calculate it in logn yes...no need for crazy calculations...just check out the answers for some numbers and u'll see how easy this problem is.. I found the period. I don't think it is eas to find the period. display the situation of n: 1- 100 ? 1 - 30 is enough actually Any idea? I got Wa in 54,either have you figure out that. Edited by author 13.08.2015 15:09 I found the problem . I do this using DP,dp[i][0] dp[i][j] represent the ways to put '0' and '1' and the answer to too big for long long . So for this problem (only ask for ok or not ok)just set a max range ,when dp[i][j]>max just let dp[i][j]=max. Hope help. if {(1^n + 2^n + 3^n + 4^n) % 10} is equal to 0, then we find 1 zero. if {(1^n + 2^n + 3^n + 4^n) % 100} is equal to 0, then we find 2 zeros. and so on.... now, how to calculate {(1^n + 2^n + 3^n + 4^n) % 10}: Look, {(1^n + 2^n + 3^n + 4^n) % 10} =((1^n % 10) + (2^n % 10) + (3^n % 10) + (4^n % 10)) % 10 [simple modulo equivalencies] now, (4^n % 10) = ((((((4%10)*4)%10)*4)%10)*4)%10 . . . . . . . (n times) [(4%10), then multiply by 4, then mod 10, loop for n times] similarly for (2^n % 10) and (3^n % 10). No need for 1, because (1^n % 10) is always 1. In this way, calculate the rusult of {(1^n + 2^n + 3^n + 4^n) % m} for m = 10, 100, ans so on... and count zeros... :) ** to know more about modulo equivalencies, http://en.wikipedia.org/wiki/Modulo_operation ** solution C++: (don't see the solution before trying, at first try yourself) http://github.com/shahed-shd/Online-Judge-Solutions/blob/master/Timus-Online-Judge/1295.%20Crazy%20Notions.cpp Edited by author 13.08.2015 15:51 Edited by author 13.08.2015 23:02Deleted. Edited by author 24.01.2010 03:44 Give me some tests. Here is some useful tests (after passing all of it I got AC): 14 1 1 3 3 0 2 2 2 2 0 2 2 6 1 -1 1 5 6 5 0 2 2 0 3 -1 1 5 6 5 0 2 2 -4 0 -1 1 5 6 5 0 2 2 6 7 -1 1 5 6 5 0 2 2 5 7 -1 1 4 6 5 0 1 1 6 6 2 2 3 3 4 4 1 1 6 6 2 4 3 3 4 2 1 1 2 2 -1 -1 -1 -2 -2 -1 1 1 3 3 4 6 2 2 6 4 1 1 3 3 4 6 1 2 6 4 1 1 3 3 4 6 1 2 7 4 1 1 2 2 1 3 3 3 3 1 1 1 1 5 0 8 1 2 3 2 Answer: 4.576491 5.019765 5.398346 6.324555 10.676619 10.605551 7.071068 7.634414 1.414214 8.993230 8.993230 9.162278 1.414214 5.841619 Good Luck :) some more: 2 2 2 4 2 2 1 3 6 4 1 4 2 2 2 2 1 3 6 4 1 4.000000 4.000000 THX A LOT! My WA4 passed all having tests, but it had problems with something like this 2 8 7 1 3 6 1 7 4 0 9 5 1 2 2 2 1 4 1 8 9 11,709720 4,000000 Yet tests: 5 5 2 3 5 -1 2 4 5 6 3 4 1 5 5 2 3 6 4 5 2 1 1 7 5 2 3 6 4 5 2 1 1 3 3 2 4 2 2 4 2 6 1 6 4 0 5 7 2 6 5 answers: 5.242641 5.064495 7.621233 4.576491 5.576491 And don't use float! When I use float system reply WA#4, after s/float/double/ I get AC. Edited by author 18.01.2011 00:00 Spoiler alert!!! I've been struggling a lot with make_heap(), pop_heap() and push_heap(), but I decided to make my own heap structure and got Accepted Here's the structure (not the solution) : http://pastie.org/10344200check the test where answer is 1 I divided given graph into biconnected components, and then worked with created DAG. This solution is O(N^2) and runs in 0.203 seconds. But there are solutions with better time. Is there faster algo for this problem? P.S. sorry for bad english(( The input in this problem requires O(N^2) time, so the better complexity cannot be achieved :) Your solution O(N^2*log(N)) in worst case, because the input in this problem requires O(N^2*log(N)) time, so the better complexity than it cannot be achieved. How to divide graph into connected components in O(N^2)? You can use Tarjan's algorithm to find strongly connected components //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.StringTokenizer; public class p1423 { static char[] t; static char[] p; static int[] pi; static int N; public static void main(String[] args) throws FileNotFoundException { InputStream is = System.in; FastScanner sc = new FastScanner(new InputStreamReader(is)); N = sc.nextInt(); String tt = sc.next(); tt += tt; t = tt.toCharArray(); p = sc.next().toCharArray(); pi = new int[N]; System.out.println(KMPMatcher()); } static int KMPMatcher() { computePrefixFunction(); int equals = 0; for (int i = 0; i < N + N; i++) { while (equals > 0 && p[equals] != t[i]) equals = pi[equals - 1]; if (p[equals] == t[i]) equals++; if (equals == N) { if (i == N - 1) { return 0; } else { return N + N - (i + 1); } } } return -1; } static void computePrefixFunction() { int k = 0; for (int q = 1; q < N; q++) { while (k > 0 && p[k] != p[q]) k = pi[k - 1]; if (p[k] == p[q]) k++; pi[q] = k; } } 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()); } } } "floor space one million square kilometers", so maximum number of slabs damaged by the fire is 1e12, but brute force solution (TL17) with ad-don "if(res>1e12)res=1e12" has WA14 Statement is fixed, thank you. #include <iostream> #include <math.h> using namespace std; int main(){ double x; int i; cin >> x; x = fmod (x, 7.0); printf("%.0f",x); system("pause"); return 0; } Edited by author 18.08.2014 21:49 it's ovbious that a number of 50 digits won't fit in a double. Such number wouldn't even fit in long long. You need other method... You don't need to calculate the topological order. If you first calculate the topological order, and then try to "verify" the study order, will complicate a simple problem. |
|