|
|
Common Boardwhy i always got wrong 3 ? me help this test: 4 0 1 0 2 0 3 0 4 right ans is: 1 1 1 1 Because you Ben!___Don't mind!I ever got WA for many times.- - Edited by author 03.10.2013 14:18 You can solve that with algo Djikstra. We have 6!*8*8 vertex (hash of cube and point) . And all vertexs have <=4 edges. P.s. sry for English ) Edited by author 09.08.2014 16:51 import java.util.List; import java.util.ArrayList; import java.util.Scanner; public class Spion { public static void main(String[] args) { Scanner in = new Scanner(System.in); List<String>shifr = new ArrayList(); String word = in.next();
shifr.add(""+word.charAt(0));
for(int i =1;i<word.length();i++){ String s =""+word.charAt(i); shifr.add(s);
if(shifr.get(shifr.lastIndexOf(s)).equals(shifr.get(shifr.indexOf(s))) && shifr.lastIndexOf(s)==shifr.indexOf(s)+1) { shifr.remove(shifr.get(shifr.lastIndexOf(s))); shifr.remove(shifr.get(shifr.indexOf(s)));
};
}
for(String n: shifr){
System.out.print(n); }
} } what's wrong? Can you please give me some tests? Тест №2 противоречит условию задачи , это тест такой : 1 1 0 (подобрал с помощью бинпоиска) import java.util.Scanner; public class AcmTimusRu { public static void main(String[] args) { Scanner s = new Scanner(System.in); int a = s.nextInt(); int b = s.nextInt(); if (39 + 2 * a > a + 2 * b) { System.out.println(2*a+39); } else { System.out.println(2*b+40); } } } Not a + 2 * b. You must use 40 + 2 * b. import java.text.DecimalFormat; import java.util.Scanner;
public class prob {
public static void main(String[] args) { Scanner c = new Scanner(System.in); DecimalFormat twoDecimals = new DecimalFormat("0.00%"); int n = c.nextInt(); int counter = 0; double m = c.nextInt(); int []a = new int [c.nextInt()]; for(int i = 0; i < a.length; i++){ a[i]= c.nextInt(); } for(int j = 1; j<=n; j++){ int z = j; for (int i = 0; i < a.length; i++){ if(a[i] == z) counter++; } System.out.println(counter*100 / m); } } } parsing in just one line XD from string import * from functools import * [[a1,b1],[a2,b2],[a3,b3]] = map(partial(map,int),map(split,map(raw_input, [""]*3))) & in py3k: from functools import * [[a1,b1],[a2,b2],[a3,b3]] = map(partial(map,int),map(lambda x:x.split(),map(input, [""]*3))) Edited by author 05.04.2014 04:37 a1, b1 = [int(num) for num in input().split()] a2, b2 = [int(num) for num in input().split()] a3, b3 = [int(num) for num in input().split()] print(a1 - a3, b1 - b2) I can't understand why my program work slow, I don't know any algorithm that can solvе this problem in beter time. My program solve it in 0.125s, when others in 0.031. Why ? Please help me :) :D моя ещё не знает, что я программно жарю котлеты :D 9 15 1 2 3 1 1 5 4 2 6 2 3 4 3 6 4 5 6 5 5 7 6 7 6 8 8 7 7 9 8 9 1 9 Ans: 0 Many AC codes input the n=100, output have many zero before the radix point, the relative error is not enough very much! Why did they accept? input 5 4 4 2 2 1 1 3 3 4 I think output should "1" but most of my colleagues' accepted programs print "0". Do I misunderstand the problem ? This is not valid input because the graph has to have an even number of edges. Edited by author 10.02.2014 00:44 Use the FFTW (such fast wow) for AC. Thanks, I already got AC with usual FFT (heavily optimized). Could you give some link to FFTW? #include<iostream> #include<conio.h> #include<Math.h> using namespace std; int main() { long long int a[ 100000 ]; int i = 0; do { cin>>a[ i ]; i ++; }while( a[ i - 1 ] != EOF ); for( int j = i - 1; j > -1; j -- ) { if( a[ j ] >= 0 ) cout<<sqrt((double)a[ j ])<<endl; } } I don't know what is the fastest way to solve this, but I think mine is more complicated than it can be. I've keeped a vector for each remainder i mod k and i*i mod k, to quickly find the numbers which give remainder r. Then you can add edge by edge in graph and use union-find algo to check for cycles. Maybe there is a faster math solution? Yep, graph is very sparse. Almost always (without several trivial cases) you can consider only range [0..2*k]. To avoid any kinds of checking simply get n = max(10, 2*k). For each number in [1..n] try to find cycle with previous ones. Use e.g. disjoint sets for simplicity. Note, that solution always exists! Almost always (without several trivial cases) you can consider only range [0..2*k]. To avoid any kinds of checking simply get n = max(10, 2*k). Is there any mathematical proof for this? if k=1 =>ans is 3 if k=2 =>ans is 5 if k>2 => you can take numbers 1, k-1, 2*k-1, and it will be a cycle 3 2 11110001 11110001 11110000 11110000 11110000 If you alter one bit, it will become 11110000 11110000 11110001 So how the answer is 1 2? Shouldn't it be 1 1? Or we have to alter only the first byte? What you suggest changes 2 bits and you want the replacement with minimal number of bits ("And if it is, find the minimum number of bits to alter."). Edited by author 26.10.2013 17:33 Edited by author 26.10.2013 17:36 |
|
|