#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
freopen("INPUT.TXT", "r", stdin);
freopen("OUTPUT.TXT", "w", stdout);
int x;
cin >> x;
cout << x;
return 0;
}
Chủ Nhật, 14 tháng 4, 2019
Đọc và xuất file trong C++
Thứ Bảy, 13 tháng 4, 2019
He so cua x^m trong ...
https://math.stackexchange.com/questions/1868044/the-number-of-n-tuples-of-nonnegative-integers-x-1-ldots-x-n-satisfying-t?rq=1
Điều chỉnh motor bằng biến trở (2a)
/*
ReadAnalogVoltage
Reads an analog input on pin 0, converts it to voltage, and prints the result to the Serial Monitor.
Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/ReadAnalogVoltage
*/
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(A0,OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
Serial.println(voltage);
}
ReadAnalogVoltage
Reads an analog input on pin 0, converts it to voltage, and prints the result to the Serial Monitor.
Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/ReadAnalogVoltage
*/
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(A0,OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
Serial.println(voltage);
}
đo nhiệt độ - độ ẩm
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
double temp = 0.0f;
double hum = 0.0f;
const int DHTPIN = 2;
const int DHTTYPE = DHT11;
DHT dht(DHTPIN, DHTTYPE);
byte degree[8] = {
0B01110,
0B01010,
0B01110,
0B00000,
0B00000,
0B00000,
0B00000,
0B00000
};
void setup() {
lcd.init();
lcd.backlight();
Serial.begin(115200);
lcd.print("Nhiet do: ");
lcd.setCursor(0,1);
lcd.print("Do am: ");
lcd.createChar(1, degree);
dht.begin(); delay(500);
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(t) || isnan(h)) { // Ki?m tra xem th? vi?c d?c giá tr? có b? th?t b?i hay không. Hàm isnan b?n xem t?i dây http://arduino.vn/reference/isnan
}
else {
lcd.setCursor(10,0);
lcd.print(round(t));
lcd.print(" ");
lcd.write(1);
lcd.print("C");
lcd.setCursor(10,1);
lcd.print(round(h));
lcd.print(" %");
}
}
/*
Hãy print ra xem th? b?n nh?n du?c gì! VÀ hãy th? khám phá t?ng dòng code m?i trong này nhé ;)
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
double temp = 0.0f;
double hum = 0.0f;
const int DHTPIN = 2;
const int DHTTYPE = DHT11;
DHT dht(DHTPIN, DHTTYPE);
byte degree[8] = {
0B01110,
0B01010,
0B01110,
0B00000,
0B00000,
0B00000,
0B00000,
0B00000
};
void setup() {
lcd.init();
lcd.backlight();
Serial.begin(115200);
lcd.print("Nhiet do: ");
lcd.setCursor(0,1);
lcd.print("Do am: ");
lcd.createChar(1, degree);
dht.begin(); delay(500);
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(t) || isnan(h)) { // Ki?m tra xem th? vi?c d?c giá tr? có b? th?t b?i hay không. Hàm isnan b?n xem t?i dây http://arduino.vn/reference/isnan
}
else {
lcd.setCursor(10,0);
lcd.print(round(t));
lcd.print(" ");
lcd.write(1);
lcd.print("C");
lcd.setCursor(10,1);
lcd.print(round(h));
lcd.print(" %");
}
}
/*
Hãy print ra xem th? b?n nh?n du?c gì! VÀ hãy th? khám phá t?ng dòng code m?i trong này nhé ;)
*/
LCD+volume+I2C
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
//0x27 là d?a ch? màn hình trong bus I2C. Ph?n này chúng ta không c?n ph?i quá b?n tâm vì h?u h?t màn hình (20x4,...) d?u nhu th? này!
//16 là s? c?t c?a màn hình (n?u dùng lo?i màn hình 20x4) thì thay b?ng 20
//2 là s? dòng c?a màn hình (n?u dùng lo?i màn hình 20x4) thì thay b?ng 4
void setup() {
lcd.init(); //Kh?i d?ng màn hình. B?t d?u cho phép Arduino s? d?ng màn hình, cung gi?ng nhu dht.begin() trong chuong trình trên
lcd.backlight(); //B?t dèn n?n
lcd.print("Hello world"); //Xu?t ra ch? Hello world, m?c d?nh sau khi init thì con tr? t?i c?t 0 hàng 0 (trong C, khác v?i quy u?c c?a ti?ng Vi?t, m?i ch? s? d?u b?t d?u b?ng s? 0, vì v?y b?n c?n hi?u r?ng, n?u ta k? m?t b?ng có 2 hàng và 16 c?t thì ô góc trên cùng bên trái là ô (0,0) tuong t? v?i các ô khác, ta c? tang d?n giá tr? lên!
lcd.setCursor(0,1); //Ðua con tr? t?i hàng 1, c?t 0
lcd.print("I love Arduino !");// B?n th?y trên màn hình r?i ch??
}
void loop() {
}
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
//0x27 là d?a ch? màn hình trong bus I2C. Ph?n này chúng ta không c?n ph?i quá b?n tâm vì h?u h?t màn hình (20x4,...) d?u nhu th? này!
//16 là s? c?t c?a màn hình (n?u dùng lo?i màn hình 20x4) thì thay b?ng 20
//2 là s? dòng c?a màn hình (n?u dùng lo?i màn hình 20x4) thì thay b?ng 4
void setup() {
lcd.init(); //Kh?i d?ng màn hình. B?t d?u cho phép Arduino s? d?ng màn hình, cung gi?ng nhu dht.begin() trong chuong trình trên
lcd.backlight(); //B?t dèn n?n
lcd.print("Hello world"); //Xu?t ra ch? Hello world, m?c d?nh sau khi init thì con tr? t?i c?t 0 hàng 0 (trong C, khác v?i quy u?c c?a ti?ng Vi?t, m?i ch? s? d?u b?t d?u b?ng s? 0, vì v?y b?n c?n hi?u r?ng, n?u ta k? m?t b?ng có 2 hàng và 16 c?t thì ô góc trên cùng bên trái là ô (0,0) tuong t? v?i các ô khác, ta c? tang d?n giá tr? lên!
lcd.setCursor(0,1); //Ðua con tr? t?i hàng 1, c?t 0
lcd.print("I love Arduino !");// B?n th?y trên màn hình r?i ch??
}
void loop() {
}
Giả lập arduino
https://www.tinkercad.com/
toongs.minh.dduwsc
pass: 1e4483e833025ac10e6184e75cb2d19d
toongs.minh.dduwsc
pass: 1e4483e833025ac10e6184e75cb2d19d
Thứ Sáu, 12 tháng 4, 2019
Tinh phi
void tinhphi() {
phi[1] = 1;
for (int i=2; i<MAXN; i++){
if (!phi[i]){
phi[i] = i-1;
for (int j = (i<<1); j<MAXN; j+=i){
if (!phi[j])
phi[j] = j;
phi[j] = (phi[j]/i)*(i-1);
}
}
}
}
// MAXN=1e6+5
phi[1] = 1;
for (int i=2; i<MAXN; i++){
if (!phi[i]){
phi[i] = i-1;
for (int j = (i<<1); j<MAXN; j+=i){
if (!phi[j])
phi[j] = j;
phi[j] = (phi[j]/i)*(i-1);
}
}
}
}
// MAXN=1e6+5
Đăng ký:
Bài đăng (Atom)
Bài G - Educatioal Round 62
Đề bài: Bạn được cho 1 đồ thị vô hướng đặc biệt. Nó bao gồm $2n$ đỉnh được đánh số từ 1 đến 2n. Dưới đây là một số đặc tính của đồ thị: + ...
-
Hamiltonian Path is a path in a directed or undirected graph that visits each vertex exactly once. The problem to check whether a graph (di...
-
GCDFIB - Ước chung lớn nhất của dãy fibonacci Dữ liệu vào: standard input Dữ liệu ra: standard output Giới hạn thời gian: 1.0 giây ...
-
SMINROAD - Đường đi trọng số nhỏ nhất Dữ liệu vào: standard input Dữ liệu ra: standard output Giới hạn thời gian: 2.0 giây Giới h...