Bài đăng

Cách đọc file input và write file input - Java

Tạo file input.txt. Sau khi chạy xong code nó sẽ tự động sinh ra file output 5 1 2 2 3 3 4 4 5 5 6 Và dưới đây là code: import java . io . FileWriter ; import java . io . File ; import java . util . Scanner ; import java . math . BigInteger ; public class nhap { public static void main ( String [] args ){ try { /* Input*/ File myObj = new File ( "input.txt" ); Scanner myReader = new Scanner ( myObj ); Integer testcase = myReader . nextInt (); /*Output */ FileWriter myobj_out = new FileWriter ( "output1.txt" ); // Integer ans = 5; // Integer ans1 = 6; // myobj_out.write(ans.toString()); // myobj_out.write('\n'); // myobj_out.write(ans1.toString()); /*Solve */ for ( Integer i = 0 ; i < testcase ; i ++) { // String data = myReader.nextLine();

Cách đa năng hoá toán tử < , và những lợi ích của nó trong set,map.

 Đề bài: https://codeforces.com/problemset/problem/608/A Code: #include < bits / stdc ++. h > using namespace std ; #define ll long long struct cap { ll tang , tg ; }; // bool tmp(cap a, cap b){ // if(a.tang==b.tang) return a.tg<b.tg; // else return a.tang>b.tang; // } bool operator < ( const cap & a , const cap & b ){ if ( a . tang == b . tang ) return a . tg < b . tg ; return a . tang > b . tang ; } int main (){ // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); ll n , s ; set <cap> ss ; cin >> n >> s ; cap arr [ n ]; ll i ; for ( i = 0 ; i < n ; i ++){ cin >> arr [ i ]. tang >> arr [ i ]. tg ; ss . insert ( arr [ i ]); } // for(auto pp: ss){ // cout<<pp.tang<<" "<<pp.tg<<'\n'; // } sort ( arr , arr + n );

Priority Queue - Xuoi - Nguoc

 Nguồn: https://codeforces.com/problemset/problem/218/B Solve: //priority_queue <int> ; less //priority_queue <int,vector<int>,greater<int> > ; greater #include < bits / stdc ++. h > using namespace std ; #define ll long long priority_queue <ll> q_max ; priority_queue < ll , vector <ll> , greater <ll> > q_min ; int main (){ ll n , m ; cin >> n >> m ; ll i ; ll a [ m ]; for ( i = 0 ; i < m ; i ++){ cin >> a [ i ]; q_max . push ( a [ i ]); q_min . push ( a [ i ]); } ll res_max = 0 , res_min = 0 ; for ( i = 0 ; i < n ; i ++){ ll q ; ll p ; q = q_max . top (); p = q_min . top (); q_max . pop (); q_min . pop (); if ( q > 0 && p > 0 ){ res_max = res_max + q ; res_min = res_min + p ; q --; p --; if ( q > 0 ) q_max . push ( q ); if ( p > 0 ) q_min . push ( p );

Tài liệu machine learning

 1)  https://drive.google.com/file/d/1lNjzISABdoc7SRq8tg-xkCRRZRABPCKi/view?fbclid=IwAR0VR3Ewkf_4OY7G5m41RYztwlvmeJfJuDBa_Z25gNBXJKJy1kheVD3t6Dk

Check nguyên tố bằng Java

import java.util.*;  import java.math.*;     class Main  {      //Function to check and return prime numbers      static boolean checkPrime(String n)      {          // Converting long to BigInteger          BigInteger b = new BigInteger(n);             return b.isProbablePrime(1);      }         // Driver method      public static void main (String[] args)                           throws java.lang.Exception      {         String n = "1000000000000000000";         System.out.println(checkPrime(n));      }  } Link: https://www.onlinegdb.com/

Cách tính a*b mod m , a^b mod m , a^(-1) mod m với m không phải là số nguyên tố (inversion có nghĩa khi (a,m)=1)

#include <bits/stdc++.h> using namespace std ; #define ll long long #define MOD (ll)(1000000000000000009) ll inv ( ll a , ll mod ){ ll r = mod ; ll nr = a ; ll t = 0 ; ll nt = 1 ; ll tmp ; while ( nr != 0 ){ ll q = r / nr ; tmp = nt ; nt = t - q * nt ; t = tmp ; tmp = nr ; nr = r - q * nr ; r = tmp ; } if ( r > 1 ) return - 1 ; // no inverse if ( t < 0 ) t += mod ; return t ; } ll f ( ll a , ll n , ll mod ){ ll res = a , ans = 0 ; while ( n ){ if ( n % 2 ) ans = ( ans + res ) % mod ; res = ( res + res ) % mod ; n /= 2 ; } return ans ; } ll po ( ll a , ll n , ll mod ){ ll res = a , ans = 1 ; while ( n ){ if ( n % 2 ) ans = f ( ans , res , mod ); res = f ( res , res , mod ); n /= 2 ; } return ans ; } int main (){ ll x , y , z , m , dem = 0 , res1 , res2 , res , tmp

DUT - Train

https://docs.google.com/spreadsheets/d/154ndCLFTvT_dS5o_Dh2ikAJwd4fMo8xC9roMc9q_RAU/edit?usp=sharing