Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ########################## JAVA - BIGINTEGER #################################
- ////En implementacion
- Variables globales en java
- {
- Examples:
- static int phi[] = new int [MAXN + 1];
- static BigInteger K[] = new BigInteger[ 605 ];
- Obs
- - no olvidar el static ya que esta sentencia permite el poder usar la variable desde otro lado del code
- -para el primero como int es un dato primitivo no es necesario crear referencias por cada un de los int creados
- pero para el segundo si es necesario para evitar excepciones
- for( int i = 1 ; i < 604 ; ++i ){
- K[ i ] = BigInteger.ONE;
- K[ i ] = K[ i - 1 ].multiply( kk );
- }
- }
- Constructores
- {
- String s;
- BigInteger num = BigInteger(s);
- int k;
- BigInteger num = BigInteger.valeOf(k);
- }
- Operaciones aritmeticas
- {
- BigInteger ans = BigInteger;
- ans = num.subtract(den);
- ans = num.multiply(den));
- ans = num.add(den);
- ans = num.divide(den);
- REVERSE_MULTIPLIER = BigInteger.valueOf(MULTIPLIER).modInverse(BigInteger.valueOf( mod )).longValue();// modInverse , longValue()
- }
- Operaciones con Bigdecimal
- {
- System.out.printf(Locale.US,"%.10f\n", s);//Para que no se contraiga con la notacion cientifica ejm : 1.8E-10
- .toPlainString(); //Returns a string representation of this BigDecimal without an exponent field.
- stripTrailingZeros() // Returns a BigDecimal which is numerically equal to this one but with any trailing zeros removed from the representation. ejm 5^2 == 25.00 > 25
- }
- String en Java
- Acceso a elementos s.charAt(i);
- Tamao s.length();
- Substring en el intervalo [a-b> : s.substring(a, b);
- Substring en el intervalo [a-oo> : s.substring(a);
- //INVESTIGAR s.endsWith("ize") s.startsWith("post")
- ///OJO INVESTIGAR (PARECE s.find )cad.indexOf('+')) != -1
- Scanner I/O en JAVA
- Declaracion Scanner cin = new Scanner(System.in);
- String s = cin.nextLine();// next();
- Parsing
- String s;
- int t = Integer.parseInt( s );
- Map en JAVA
- Map< String , Integer >M = new HashMap<String, Integer>();
- if( !M.containsKey(temp) )
- M.put(temp, 1 );
- else M.put(temp, M.get(temp) + 1 );
- for (Map.Entry<String, Integer> entry : M.entrySet())
- {
- max = entry.getValue();
- ans = entry.getKey();
- }
- Set en java // Array de Set
- TreeSet< obj >[] set = new TreeSet [ ns + 1 ];
- for( int i = 0 ; i <= ns ; ++i ) set[ i ] = new TreeSet< obj >();
- Objects en java
- new // siempre usarlo al crear un nuevo objeto ya que a modo practico esta sentencia como que creara espacio fisico en la variable
- Example : set[ 2*k ].add( new obj( H1.hash( i , i + k + 1 ) , i ) );
- Objeto comparador
- public static class obj implements Comparable< obj > {
- long a ;
- int b;
- obj(long a, int b) {
- this.a = a;
- this.b = b;
- }
- public int compareTo( obj o )
- {
- if( o.a != a )return (int)(a - o.a);
- return (int)( cc.charAt( b ) - cc.charAt( o.b ) );
- }
- }
- Tambien se puede hacer este truco //http://codeforces.com/contest/19/submission/86646
- Integer o[] = new Integer[ sz ];
- for( int i = 0 ; i < sz ; ++i ) o[ i ] = i;
- Arrays.sort( o , new Comparator< Integer >() {
- public int compare( Integer o1 , Integer o2 )
- {
- if( H1[ o1 ] != H1[ o2 ] ) return (int)( H1[ o2 ] - H1[ o1 ] );
- return (int)( H2[ o2 ] - H2[ o1 ] );
- }
- });
- /*http://codeforces.com/contest/19/submission/86646
- Integer o[] = new Integer[ sz ];
- for( int i = 0 ; i < sz ; ++i ) o[ i ] = i;
- Arrays.sort( o , new Comparator< Integer >() {
- public int compare( Integer o1 , Integer o2 )
- {
- if( H1[ o1 ] != H1[ o2 ] ) return (int)( H1[ o2 ] - H1[ o1 ] );
- return (int)( H2[ o2 ] - H2[ o1 ] );
- }
- });
- */
- // StringHash taked of EgorK , http://codeforces.com/contest/113/submission/676303
- // Pendiente arraylist y otros coleccions
- // Sorting array Arrays.sort( A , 0 , n - 1 ); creo xd
- // Freopen in java
- static private final String input = "derangements.in";
- static private final String output = "derangements.out";
- public static void main(String[] args)throws FileNotFoundException {
- Scanner cin = new Scanner(new File(input));
- int n = cin.nextInt();
- cin.close();
- int ans = f( n );
- PrintWriter s=new PrintWriter(output);
- s.println( ans );
- s.close();
- }
- //
- public int compareTo(BigInteger val)
- Parameters
- val - BigInteger to which this BigInteger is to be compared
- Return Value
- This method returns -1, 0 or 1 as this BigInteger is numerically less than, equal to, or greater than val.
- //
- Nextpermutation in JAVA
- int[] nextperm(int[] vals) {
- int i = vals.length-1;
- while (true) {
- int ii = i;
- i--;
- if (vals[i] < vals[ii]) {
- int j = vals.length;
- while (vals[i] >= vals[--j]);
- int temp = vals[i]; //Swap
- vals[i] = vals[j];
- vals[j] = temp;
- int begin = ii, end = vals.length-1;
- while (end>begin) {
- int stemp = vals[end]; //Swap
- vals[end] = vals[begin];
- vals[begin] = stemp;
- end--; begin++;
- }
- return vals;
- } else if (vals[i] == vals[0]) {
- int begin = 0, end = vals.length-1;
- while (end>begin) {
- int stemp = vals[end]; //Swap
- vals[end] = vals[begin];
- vals[begin] = stemp;
- end--; begin++;
- }
- return vals;
- }
- }
- }
Add Comment
Please, Sign In to add comment