File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const input = require ( "fs" )
2+ . readFileSync (
3+ process . platform === "linux"
4+ ? "/dev/stdin"
5+ : require ( "path" ) . join ( __dirname , "input.txt" ) ,
6+ "utf8"
7+ )
8+ . toString ( )
9+ . trim ( )
10+ . split ( "\n" )
11+ . map ( ( line ) => line . split ( " " ) . map ( Number ) ) ;
12+
13+ function solution ( input ) {
14+ const N = input [ 0 ] [ 0 ] ;
15+ const G = input . slice ( 1 ) ;
16+
17+ for ( let k = 0 ; k < N ; k ++ )
18+ for ( let i = 0 ; i < N ; i ++ )
19+ for ( let j = 0 ; j < N ; j ++ ) if ( G [ i ] [ k ] && G [ k ] [ j ] ) G [ i ] [ j ] = 1 ;
20+
21+ return G . map ( ( row ) => row . join ( " " ) ) . join ( "\n" ) ;
22+ }
23+
24+ console . log ( solution ( input ) ) ;
Original file line number Diff line number Diff line change 1+ const fs = require ( "fs" ) ;
2+ const path = require ( "path" ) ;
3+
4+ const filePath =
5+ process . platform === "linux"
6+ ? "/dev/stdin"
7+ : path . join ( __dirname , "input.txt" ) ;
8+
9+ const input = fs . readFileSync ( filePath , "utf8" ) . toString ( ) . trim ( ) ;
10+
11+ function solution ( input ) {
12+ const sugar = input ;
13+ let [ bag3 , bag5 ] = [ 0 , 0 ] ;
14+ bag5 = Math . floor ( sugar / 5 ) ;
15+ bag3 = ( sugar - bag5 * 5 ) / 3 ;
16+
17+ while ( bag5 >= 0 ) {
18+ if ( bag3 === Math . floor ( bag3 ) ) return bag5 + bag3 ;
19+
20+ if ( bag3 % 3 !== 0 ) {
21+ -- bag5 ;
22+ bag3 = ( sugar - bag5 * 5 ) / 3 ;
23+ }
24+ }
25+ return - 1 ;
26+ }
27+
28+ console . log ( solution ( input ) ) ;
Original file line number Diff line number Diff line change 1+ function solution ( n ) {
2+ const dp = [ ] ;
3+ dp [ 0 ] = 0 ;
4+ dp [ 1 ] = 1 ;
5+ dp [ 2 ] = 2 ;
6+ // dp[3] = 3;
7+ // dp[4] = 5;
8+ // dp[5] = 8;
9+ // dp[6] = 13;
10+ for ( let i = 3 ; i <= n ; i ++ ) dp [ i ] = ( dp [ i - 1 ] + dp [ i - 2 ] ) % 1000000007 ;
11+
12+ return dp [ n ] ;
13+ }
14+
15+ console . log ( solution ( 6 ) ) ;
You can’t perform that action at this time.
0 commit comments