蓝桥12

B:

#include <bits/stdc++.h>
using namespace std;

int a[10];
int main(){
    for(int i = 0; i < 10; i++) {
        a[i] = 2021;
    }
    int ans = 1;
    while(true){
        int x =  ans;
        while(x){
            if(a[x % 10]) a[x % 10]--;
            else{
                cout << ans - 1 << endl;
                return 0;
            }
            x /= 10;
        }
        ans++;
    }
    return 0;
}

  

C:

#include <bits/stdc++.h>
using namespace std;

int x = 20, y = 21;
double k[400005], b[400005]; 
int main(){
	int ans = 20;
	int t = 0;

	for(int i = 0; i < x; i++){
		for(int j = 0; j < y; j++){
			for(int I = 0; I < x; I++){
				for(int J = 0; J < y; J++){
					if(i == I)continue;
					if(i == I && j == J)continue;
					double kk = double(j - J) / double(i - I);
					double bb = double(j) - kk * double(i);
					int flag = 1;
					for(int tt = 0; tt < t; tt++){
						if(fabs(k[tt] - kk) <= 1e-8 && fabs(b[tt] - bb) <= 1e-8){
							flag = 0;
							break;
						}
					}
					if(flag){
						k[t] = kk;
						b[t] = bb;
						t++;
					}
				}
			}
		}
	}

	cout << t + y - 1	 << endl;
	
	return 0;
} 

  

D:

两种思路,暴力剪枝:

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
int main(){
	LL n = 2021041820210418;
	int ans = 0;
	for(LL i = 1; i * i * i <= n; i++){
	    if(n % i !=0)   continue;
		for(LL j = i; i * j * j <= n; j++){
			if(n % (i * j) == 0){
				LL k = n / (i * j);
				if(i == j && j == k) 	ans++;
				else if(i != j && j != k) ans += 6;
				else					ans += 3;
			}
		}
	}
	cout << ans << endl;
	return 0;
} 

先求所有约数,能分成的组合数必定是这些约数相乘。

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
int main(){
	LL n = 2021041820210418;
	vector<LL> a;
	for(LL i = 1; i * i <= n; i++){
		if(n % i != 0)continue;
		a.push_back(i);
		if(i != n / i)	a.push_back(n / i); 
	}
	int ans = 0;
	for(auto i : a){
		for(auto j : a){
			for(auto k : a){
				if(i * j * k == n){
					ans ++;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

  

E:

经典DP

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL gcd(int a, int b){
	return b ? gcd(b, a % b) : a;
}
LL a[2022];
int main(){
	memset(a, -1, sizeof a);
	a[1] = 0;
	for(int i = 2; i <= 2021; i++){
		for(int j = 1; j <= 21; j++){
			if(i - j < 1)continue;
			LL t = a[i - j] + (i - j) * i / gcd(i - j, i);

			if(a[i] == -1){
				a[i] = t;
			}
			a[i] = min(a[i], t);
		}
	}
	cout << a[2021] << endl;
	return 0; 
} 

  

F:

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
LL n;
int main(){
    cin >> n;
    int hh, mm, ss;
    n /= 1000;
    n = n % (60 * 60 * 24);
    hh = n / 3600;
    mm = (n % 3600) / 60;
    ss = (n % 60) ;
    if(hh < 10)printf("0");
    printf("%d:",hh);
    if(mm < 10)printf("0");
    printf("%d:",mm);
    if(ss < 10)printf("0");
    printf("%d",ss);

    return 0;
}

G:

思维一定要缜密才行啊!

#include <bits/stdc++.h>
using namespace std;

vector<int> a[105];
int n;
bool book[100005];
int main(){
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        a[i].push_back(x);

    }
    for(int i = 0; i < n; i++){
        int xx = a[i][0];
        if(!book[xx]){
            book[xx] = 1;
            ans++;
        }
        for(int j = 0; j < i; j++){
            for(int k = 0; k < a[j].size(); k++){
                int x;
                x = a[j][k] + a[i][0];
                if(!book[x]){
                    book[x] = 1;
                    a[i].push_back(x);
                    ans++;
                }
                x = abs(a[j][k] - a[i][0]);
                if(!book[x]){
                    book[x] = 1;
                    a[i].push_back(x);
                    ans++;
                }
            }
        }
    }
    if(book[0])ans--;
    cout << ans << endl;
    return 0;
}

  

posted @ 2022-03-02 15:36  荣荣荣荣荣荣  阅读(34)  评论(0)    收藏  举报