计算机中存储单位
位(bit)<其次字节(byte)<KB<MB<GB<TB
1B(byte,字节)= 8 (bit,位);
1KB=1024B(字节)
1MB=1024KB
1GB=1024MB
1TB=1024GB
注意:
位是最小的单位
字节是最基本单位
一个英文字所需要1B,而一个汉字需要2B
int main(){
long long a =256*1024*1024/32*8;
cout << a;67108864
return 0;
}
#include<iostream>
using namespace std;
int a[10];
bool isTrue(long long s){//判断剩余的卡片是否可以拼成数字s
do{
if(a[s%10]!=0) a[s%10]--;
else return false;
}while(s = s/10);
return true;
}
int main(){
int count;
cin>> count;
for(int i=0;i<10;i++ ){
a[i] = count;
}
long long s = 1;
while(isTrue(s)) s++;
cout<<s-1;//3081
}
#include<bits/stdc++.h>
using namespace std;
set<pair<double,double> > line_set;
int main()
{
int x1,y1,x2,y2;
for(x1=0;x1<20;x1++){
for(y1=0;y1<21;y1++){
for(x2=0;x2<20;x2++){
for(y2=0;y2<21;y2++){
if(x1!=x2&&y1!=y2){
double k=(y2-y1)*1.0/(x2-x1);
double b=(y2*(x2-x1)-(y2-y1)*x2)*1.0/(x2-x1);
//重点!这么写可以规避掉double炸精度问题
pair<double ,double> newline;
newline.first=k;
newline.second=b;
line_set.insert(newline);
}
}
}
}
}
cout<<line_set.size()+20+21;
return 0;
}
//40257
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int count = 0;
ll N = 2021041820210418;
ll n = sqrt(N);
for(ll a = 1 ;a<n;a++){
if(N%a==0){
ll bc = N/a;
for(ll b = a;b<n;b++){
if(bc%b==0){
ll c = bc/b;
if(a<=b&&b<=c){
set<ll> s;
s.insert(a);
s.insert(b);
s.insert(c);
int tem = s.size();
if(tem ==3 ) count+=6;
else if(tem == 2 ) count += 3;
else tem+=1;
}
}
}
}
}
cout<<count;//2430
return 0;
}
Dijkstra 算法
#include<iostream>
#include<algorithm>
#include<cstring>
#include<stack>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {
return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
return a / gcd(a, b) * b;
}
int min(int a , int b){
return a>b?b:a;
}
int max(int a,int b){
return a>b?a:b;
}
typedef long long ll;
const int maxn = 2022;
const int INF = 1 << 30;
int n = 2022;
int map[maxn][maxn];//邻接矩阵存图
int v[maxn];//v[i] = 1表示已加入集合S
int dist[maxn];//dist[i]表示距离源点的最短距离
int paths[maxn];//记录路径
void dijkstra(int u0){
for(int i = 1;i<n;i++) dist[i] = (i == u0? 0 : INF);
for(int i = 1;i<n;i++){
int min = INF,path = 0;
for(int j = 1;j<n;j++) if(!v[j]&&dist[j]<=min) min = dist[path = j];
for(int j = 1;j<n;j++){
if(dist[j]>dist[path]+map[path][j]){
dist[j] = dist[path]+map[path][j];
paths[j] = path;
}
}
v[path] = 1;
}
}
int main() {
for (int i = 1; i <= 2021; i++) {
for (int j = 1; j <= 2021; j++) {
if (i == j)map[i][j] = map[j][i] = 0;
else if (abs(i - j) > 21) map[i][j] = map[j][i] = INF;
else map[i][j] = map[j][i] = lcm(i, j);
}
}
dijkstra(1);
cout<<dist[2021];//10266837
return 0;
}
Floyd 算法
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 999999999
int gcd(int a,int b){
if(b==0)return a;
else return gcd(b,a%b);
}
int n = 2022;
int M[2022][2022];
int main(){
for(int i=1;i<=2021;i++){
for(int j=1;j<=2021;j++){
if(i==j)M[i][j]=M[j][i]=0;
else if(abs(i-j)>21)M[i][j]=M[j][i]=INF;
else M[i][j]=M[j][i]=i*j/gcd(i,j);
}
}
/* for(int i = 1;i<2022;i++){
for(int j = 1;j<2022;j++){
for(int k = 1;k<2022;k++){
if(M[i][k]!=INF&&M[k][j]!=INF&&(M[i][j]>M[i][k]+M[k][j]))
M[i][j] = M[i][k]+M[k][j];
}
}
}*/ //15秒左右
for(int i=1;i<=2021;i++){
for(int j=i+1;j<=2021;j++){
for(int k=i;k<=j;k++){
if(M[i][k]!=INF&&M[k][j]!=INF&&(M[i][j]>M[i][k]+M[k][j])){
M[i][j]=M[j][i]=M[i][k]+M[k][j];
}
}
}
}//5秒左右
printf("%lld",M[1][2021]);
return 0;
}
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
ll t = 0;
cin>>t;
int hh = t/3600000%24;
int ff = t%3600000/60000%60;
int ss = t%3600000/1000%60;
printf("%02d:%02d:%02d",hh,ff,ss);
return 0;
}