Bài đăng

Đang hiển thị bài đăng từ Tháng 7, 2020

DUT - Train

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

Sàng nuyên tố - Vinoy

void sieve ( int N ) { bool isPrime [ N + 1 ]; for ( int i = 0 ; i <= N ; ++ i ) { isPrime [ i ] = true ; } isPrime [ 0 ] = false ; isPrime [ 1 ] = false ; for ( int i = 2 ; i * i <= N ; ++ i ) { if ( isPrime [ i ] == true ) { // Mark all the multiples of i as composite numbers for ( int j = i * i ; j <= N ; j += i ) isPrime [ j ] = false ; } } }

Python - Liệt kê tất các các chu trình trong đồ thị

graph = [[1, 2], [1, 3], [1, 4], [2, 3], [3, 4], [2, 6], [4, 6], [8, 7], [8, 9], [9, 7]] cycles = [] def main(): global graph global cycles for edge in graph: for node in edge: findNewCycles([node]) for cy in cycles: path = [str(node) for node in cy] s = ",".join(path) print(s) def findNewCycles(path): start_node = path[0] next_node= None sub = [] #visit each edge and each node of each edge for edge in graph: node1, node2 = edge if start_node in edge: if node1 == start_node: next_node = node2 else: next_node = node1 if not visited(next_node, path): # neighbor node not on path yet sub = [next_node] sub.extend(path) # explore extended path findNewCycles(sub); e

Cách đọc test đầu vào Python

Link Đề: https://codeforces.com/problemset/problem/1369/F Code: import itertools as it import collections as cc import heapq as hp import sys I = lambda : list ( map ( int , input (). split ())) import operator as op from functools import reduce n , m = I () w = I () de =[ 0 ]* n for i in range ( n ): de [ i ]=[ 0 ] pre =[ 0 ]* m visi =[ 0 ]* m for i in range ( m ): x , y = I () x -= 1 ; y -= 1 pre [ i ]=[ x , y ] de [ x ][ 0 ]+= 1 de [ y ][ 0 ]+= 1 de [ x ]. append ( i ) de [ y ]. append ( i )   an =[] te =[] ans =[] for i in range ( n ): if de [ i ][ 0 ]<= w [ i ]: te . append ( i )   while len ( te )> 0 : tem = te . pop () for i in range ( 1 , len ( de [ tem ])): fr = de [ tem ][ i ] if not visi [ fr ]: visi [ fr ]= 1 ans . append ( fr + 1 ) fo = pre [ fr ][ 0 ]+ pre [ fr ][ 1 ]- tem de [ fo ][ 0 ]-= 1 if de [ fo ][ 0 ]== w [ fo ]: te . append ( fo )       if len (

Sinh Test trong Python va code AC

P1: #file = "C:/New folder/aka/1.inp" #with open(file) as f: # a,b=[int(x) for x in next(f).split()] #print(a) #print(b) def gg(id): file= "C:/New folder/aka/" +id+ ".inp" with open (file) as f: a,b=[ int (x) for x in next (f).split()] products = set () for pair in [(x,y) for x in range ( 2 ,a+ 1 ) for y in range ( 2 ,b+ 1 )]: products.add(pair[ 0 ]**pair[ 1 ]) return len (products) x= range ( 1 , 101 ) for i in x: id= str (i) file1 = "C:/New folder/aka/" +id+ ".out" f= open (file1, "w" ) f.write( str (gg(id))) f.close() P2: a,b=[ int (x) for x in input ().split()] product = set () for pair in [(x,y) for x in range ( 2 ,a+ 1 ) for y in range ( 2 ,b+ 1 )]: product.add(pair[ 0 ]**pair[ 1 ]) print ( len (product))

Check nguyen to thong minh

ll check(ll n){ if(n<=1) return 0; if(n<=3) return 1; if(n%2==0||n%3==0) return 0; for(ll i=5;i*i<=n;i+=6) if(n%i==0||n%(i+2)==0) return 0; return 1; }

Viết checker (tong ami)

#include <bits/stdc++.h> using namespace std; int main(int argc, char** argv) {     ifstream inp(argv[1]);     ifstream out(argv[2]);     ifstream ans(argv[3]);     int n, a, b, c, d;       inp >> n;     out >> a >> b;     ans >> c >> d;     if (a + b == c + d) {         cout << a << " + " << b << " = " << c << " + " << d << endl;         return 0; // AC     }        else {         cout << "a + b = " << a + b << " != " << n << endl;         return 1; // WA     } } /***********************/ #include<bits/stdc++.h> using namespace std; #define ll long long #define maxn (ll)(105) ll pos1,length,pos2,i,n,dem,size_b; ll a[maxn],b[maxn],c[maxn]; int main(){     cin>>n;     for(i=1;i<=n;i++) a[i]=i;     cin>>pos1>>length>>pos2;     for(i=1;i<=n;i++){         if(

Sinh test (input và output đồng thời)

#include<bits/stdc++.h> using namespace std; long long Rand(long long l, long long h) { return l + ((long long)rand() * (RAND_MAX + 1) * (RAND_MAX + 1) * (RAND_MAX + 1) +             (long long)rand() * (RAND_MAX + 1) * (RAND_MAX + 1) +             (long long)rand() * (RAND_MAX + 1) +             rand()) % (h - l + 1); } void write(string t,string t1){    ofstream fileOutput(t);    ofstream fileOutput1(t1);    if(fileOutput.fail()){      cout<<"Cannot open file at "<<t<<'\n';    }    long long tmp=Rand(1,1000);    fileOutput<<tmp<<'\n';    if(tmp<=2) fileOutput1<<tmp+2<<'\n';    else fileOutput1<<tmp-2<<'\n'; } int main(){     srand(time(NULL));     int i;     string s="",s1="";     for(i=0;i<100;i++){        s="C:/New folder/aka/"+to_string(i+1)+".inp";        s1="C:/New folder/aka_1/"

Sinh Test

#include < bits / stdc ++. h > using namespace std ; long long Rand ( long long l , long long h ) { return l + (( long long ) rand () * ( RAND_MAX + 1 ) * ( RAND_MAX + 1 ) * ( RAND_MAX + 1 ) + ( long long ) rand () * ( RAND_MAX + 1 ) * ( RAND_MAX + 1 ) + ( long long ) rand () * ( RAND_MAX + 1 ) + rand ()) % ( h - l + 1 ); } void write ( string t ){ ofstream fileOutput ( t ); if ( fileOutput . fail ()){ cout << "Cannot open file at " << t << '\n' ; } fileOutput << Rand ( 1 , 1000 )<< '\n' ; } int main (){ srand ( time ( NULL )); int i ; string s = "" ; for ( i = 0 ; i < 100 ; i ++){ s = "C:/New folder/aka/" + to_string ( i + 1 )+ ".inp" ; write ( s ); } return 0 ; }

Những câu lệnh thường dùng trong latex

1. Đóng khung: $$ \alpha + \beta + \gamma =\fbox{$\pi$} $$ 2. Kẻ bảng thủ công: $$ \begin{tabular}{|l|c|r|} \hline Input& Output\\ \hline z& z\\ \hline \end{tabular}$$ 3. Chèn ảnh \includegraphics[scale=1]{13we.jpg}

Các trang luyện code hay !

[Lái xe]: http://hoclaixeoto.vn/thi-bang-lai-xe-b2-online/ 1. ProjectEuler:  https://projecteuler.net/progress 2.  https://cses.fi/problemset/task/1068 3.  https://www.youtube.com/watch?v=dZ_6MS14Mg4 4.  http://www.math.ust.hk/excalibur/v13_n4.pdf 5.  http://forum.mathscope.org/showthread.php?t=34722 6.  http://vnoi.info/wiki/algo/graph-theory/everything?fbclid=IwAR2tZnm_Hyh7CG5tR4th4vcDrl8JSq0iFNuA2prE6zf3vguvQrssFbnWUtg 7.  https://github.com/ngthanhtrung23/ACM_Notebook_new 8. https://github.com/acmicpc-vietnam/acmicpc-vietnam.github.io 9. http://vnoi.info/problems/list/?fbclid=IwAR1yLB21OgxY6sdNtJNe4D58J0GJ2parvWTzS7hlwmbyohYTDibAqcK_Mcc&tag=81&page=1 10. https://v0.vnoi.info/index.php?option=com_content&task=view&id=35&Itemid=82 11.  http://poj.org/problemlist?volume=12 12.  https://accu.org/index.php/journals/1506 13. https://math.stackexchange.com/questions/2228849/algorithm-of-tree-partition 14. https://github.com/Harmon758/Project-Euler 15. ht