BoxerTC

Untitled

Nov 20th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.67 KB | None | 0 0
  1. ##########################  JAVA - BIGINTEGER #################################
  2. ////En implementacion
  3. Variables globales en java
  4. {
  5.     Examples:
  6.     static int phi[] = new int [MAXN + 1];
  7.     static BigInteger K[] = new BigInteger[ 605 ];
  8.     Obs
  9.     - no olvidar el static ya que esta sentencia permite el poder usar la variable desde otro lado del code
  10.     -para el primero como int es un dato primitivo no es necesario crear referencias por cada un de los int creados
  11.     pero para el segundo si es necesario para evitar excepciones
  12.     for( int i = 1 ; i < 604 ; ++i ){
  13.             K[ i ] = BigInteger.ONE;
  14.             K[ i ] = K[ i - 1 ].multiply( kk );
  15.     }
  16. }
  17. Constructores
  18. {
  19.     String s;
  20.     BigInteger num = BigInteger(s);
  21.     int k;
  22.     BigInteger num = BigInteger.valeOf(k);
  23. }
  24.  
  25. Operaciones aritmeticas
  26. {
  27.     BigInteger ans = BigInteger;
  28.     ans = num.subtract(den);
  29.     ans = num.multiply(den));
  30.     ans = num.add(den);
  31.     ans = num.divide(den);  
  32.     REVERSE_MULTIPLIER = BigInteger.valueOf(MULTIPLIER).modInverse(BigInteger.valueOf( mod )).longValue();// modInverse , longValue()
  33. }
  34. Operaciones con Bigdecimal
  35. {
  36.     System.out.printf(Locale.US,"%.10f\n", s);//Para que no se contraiga con la notacion cientifica ejm : 1.8E-10
  37.     .toPlainString();   //Returns a string representation of this BigDecimal without an exponent field.
  38.     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
  39. }
  40. String en Java
  41.     Acceso a elementos s.charAt(i);
  42.     Tamao s.length();
  43.     Substring en el intervalo [a-b> : s.substring(a, b);
  44.     Substring en el intervalo [a-oo> : s.substring(a);
  45.     //INVESTIGAR s.endsWith("ize") s.startsWith("post")
  46.     ///OJO INVESTIGAR (PARECE s.find )cad.indexOf('+')) != -1
  47. Scanner I/O en JAVA
  48.     Declaracion     Scanner cin = new Scanner(System.in);
  49.     String s = cin.nextLine();// next();
  50. Parsing
  51.     String s;
  52.     int t = Integer.parseInt( s );  
  53. Map en JAVA
  54.     Map< String , Integer >M = new HashMap<String, Integer>();
  55.        
  56.     if( !M.containsKey(temp) )
  57.        M.put(temp, 1 );
  58.     else M.put(temp, M.get(temp) + 1 );
  59.     for (Map.Entry<String, Integer> entry : M.entrySet())
  60.     {
  61.         max = entry.getValue();
  62.         ans = entry.getKey();
  63.     }
  64. Set en java // Array de Set
  65.     TreeSet< obj >[] set = new TreeSet [ ns + 1 ];
  66.     for( int i = 0 ; i <= ns ; ++i ) set[ i ] = new TreeSet< obj >();
  67. Objects en java
  68.     new // siempre usarlo al crear un nuevo objeto ya que a modo practico esta sentencia como que creara espacio fisico en la variable
  69.     Example : set[ 2*k ].add( new obj( H1.hash( i , i + k + 1 ) , i ) );
  70.     Objeto comparador
  71.     public static class obj implements Comparable< obj > {
  72.         long a ;
  73.         int b;
  74.  
  75.         obj(long a, int b) {
  76.             this.a = a;
  77.             this.b = b;
  78.         }
  79.         public int compareTo( obj o )
  80.         {
  81.             if( o.a != a )return (int)(a - o.a);
  82.             return (int)( cc.charAt( b ) - cc.charAt( o.b ) );
  83.         }
  84.     }
  85.     Tambien se puede hacer este truco //http://codeforces.com/contest/19/submission/86646
  86.     Integer o[] = new Integer[ sz ];
  87.     for( int i = 0 ; i < sz ; ++i ) o[ i ] = i;
  88.     Arrays.sort( o , new Comparator< Integer >() {
  89.         public int compare( Integer o1 , Integer o2 )
  90.         {
  91.             if( H1[ o1 ] != H1[ o2 ] ) return (int)( H1[ o2 ] - H1[ o1 ] );
  92.             return (int)( H2[ o2 ] - H2[ o1 ] );
  93.         }    
  94.     });
  95.     /*http://codeforces.com/contest/19/submission/86646
  96. Integer o[] = new Integer[ sz ];
  97. for( int i = 0 ; i < sz ; ++i ) o[ i ] = i;
  98. Arrays.sort( o , new Comparator< Integer >() {
  99.     public int compare( Integer o1 , Integer o2 )
  100.     {
  101.         if( H1[ o1 ] != H1[ o2 ] ) return (int)( H1[ o2 ] - H1[ o1 ] );
  102.         return (int)( H2[ o2 ] - H2[ o1 ] );
  103.     }    
  104. });
  105. */
  106. // StringHash taked of EgorK , http://codeforces.com/contest/113/submission/676303
  107. // Pendiente arraylist y otros coleccions
  108. // Sorting array  Arrays.sort( A , 0 , n - 1 ); creo xd
  109. // Freopen in java
  110. static private final String input = "derangements.in";
  111.     static private final String output = "derangements.out";
  112.  
  113.     public static void main(String[] args)throws FileNotFoundException {
  114.         Scanner cin = new Scanner(new File(input));
  115.         int n = cin.nextInt();
  116.         cin.close();
  117.         int ans = f( n );
  118.         PrintWriter s=new PrintWriter(output);
  119.         s.println( ans );
  120.         s.close();
  121.     }
  122. //
  123. public int compareTo(BigInteger val)
  124. Parameters
  125. val - BigInteger to which this BigInteger is to be compared
  126.  
  127. Return Value
  128. This method returns -1, 0 or 1 as this BigInteger is numerically less than, equal to, or greater than val.
  129.  
  130. //
  131. Nextpermutation in JAVA
  132. int[] nextperm(int[] vals) {
  133.    int i =  vals.length-1;
  134.    while (true) {
  135.       int ii =  i;
  136.       i--;
  137.       if (vals[i] < vals[ii]) {
  138.          int j = vals.length;
  139.          while (vals[i] >= vals[--j]);
  140.             int temp = vals[i];  //Swap
  141.             vals[i] = vals[j];
  142.             vals[j] = temp;
  143.          int begin = ii, end = vals.length-1;
  144.          while (end>begin) {
  145.                int stemp = vals[end];   //Swap
  146.                vals[end] = vals[begin];
  147.                vals[begin] = stemp;
  148.             end--; begin++;
  149.          }  
  150.          return vals;
  151.       } else if (vals[i] == vals[0]) {
  152.          int begin = 0, end = vals.length-1;
  153.          while (end>begin) {
  154.                int stemp = vals[end];   //Swap
  155.                vals[end] = vals[begin];
  156.                vals[begin] = stemp;
  157.             end--; begin++;
  158.          }  
  159.          return vals;
  160.       }
  161.    }
  162. }
Add Comment
Please, Sign In to add comment