蓝桥杯练习(【思特奇杯·云上蓝桥-算法集训营】第1周)

这题直接用数学算的,答案为3880.

#include <iostream>
using namespace std;
int p[100];
int main()
{
	for (int i = 2;i <= 100; i ++) 
	{
		int n = i;
		for (int j = 2;j <= n / j;j++) {
			while (n % j == 0) {
				p[j]++;
				n /= j;
			}
		}
		if (n > 1)
			p[n]++;
	}
	long long ans = 1;
	for (int i = 2;i <= 100;i++) 
		if (p[i])
			ans *= (p[i] + 1);
		cout << ans << endl;
		return 0;
	
}

//答案:39001250856960000

#include <iostream>
using namespace std;

int main()
{
    long f[20] = { 0 }; //如果是f[16],vs2022会报错,数组下标溢出
    int i, j;
    f[0] = 1, f[1] = 1, f[2] = 2, f[3] = 5;
    for (i = 4;i <=16;i++) 
        f[i] = 0;
    for (i = 4;i <=16;i++) {
        for (int j = 0;j < i;j++) 
            f[i] += f[j] * f[i - 1 - j];//罪魁祸首:f[i],在这个for循环中,i取到了16,数组下标溢出
        
    }
    
    cout << f[16];
    return 0;
}

//答案:35357670

#include <iostream>
using namespace std;

bool isPrimeNumber(int num) {
	for (int i = 2;i * i <= num;i++)
		if (num % i == 0)
			return 0;
	return 1;
}

int main()
{
	int ans = 0, n = 10000;
	for (int i = 4; i <= n;i += 2) {
		for (int j = 2;j < i / 2;j++) {
			if (isPrimeNumber(j) && isPrimeNumber(i - j)) {
				if (j > ans)
					ans = j;
				break;
			}
		}
	}
	cout << ans << endl;
}

//答案:173

#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	
	int ans = 0 ,a[] = { 1,2,3,4,5,6,7,8,9,10 };
	do {
		if (abs(a[0] - a[1]) == 1 || abs(a[1] - a[2]) == 1 || abs(a[2] - a[3]) == 1 || abs(a[3] - a[4]) == 1 || abs(a[4] - a[5]) == 1 || abs(a[5] - a[6]) == 1 || abs(a[6] - a[7]) == 1 || abs(a[7] - a[8]) == 1 || abs(a[8] - a[9]) == 1)
			continue;
			ans ++;
	} while (next_permutation(a, a + 10));
	cout << ans << endl;
	return 0;
	//答案:479306
}

#include <iostream>
using namespace std;
//暴力求法
int main()
{
	int i;
	for (i = 21;;i++)
	{
		if (i % 5 == 1) {
			int i1 = (i - 1) * 4 / 5;
			if (i1 % 5 == 2) {
				int i2 = (i1 - 2) * 4 / 5;
				if (i2 % 5 == 3) {
					int i3 = (i2 - 3) * 4 / 5;
					if (i3 % 5 == 4) {
						int i4 = (i3 - 3) * 4 / 5;
						if (i4 % 5 == 0)
							break;
					}
				}
			}
		}
	}
	cout << i << endl;
	return 0;
}
//答案:3141

#include<iostream>
using namespace std;

int gcd(int a, int b)
{
    if (b == 0) return a;
    return gcd(b, a % b);
}
int main()
{
    // 这是屏幕上显示的那个分数 a/b
    int a = 7;
    int b = 13;

    int m, n;
    int max_a = 0;
    int max_b = 1;

    for (n = 100; n > 1; n--) {
        for (m = n - 1; m >= 1; m--) {
            if (m * b < a * n && gcd(m, n) == 1) {
                if (max_a * n < max_b * m) {  //填空
                    max_a = m;
                    max_b = n;
                    break;
                }
            }
        }
    }

    printf("%d/%d\n", max_a, max_b);
    return 0;
}

//填空处答案为max_a * n < max_b * m

#include <iostream>
#include <string>
using namespace std;

int main()
{
	int n;
	cin >> n;
	string str = "";
	while (n != 0) {
		if (n % 26 == 0) {
			str = char(26 + 64) + str;
			n -= 1;
		}
		else
			str = char(n % 26 + 64) + str;
		n /= 26;
	}
	cout << str << endl;
	return 0;
}

//例:342534
//答案:SLRJ

 

#include<iostream>
#include<string.h>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<set>
using namespace std;
bool istruedate(string syear,string smonth,string sday)
{
 int year,month,day;
    stringstream stream;
    stream<<syear;
 stream>>year;
 stream.clear();
 stream<<smonth;
 stream>>month;
 stream.clear();
 stream<<sday;
 stream>>day;
 stream.clear();
 if(year<1960||year>2059)
  return false;
 if(month>12||day>31||month<=0||day<=0) 
  return false;
 int maxday[12]={31,28,31,30,31,30,31,31,30,31,30,31};
 if((year%4==0&&year%100!=0)||year%400==0)
  maxday[1]++;
 if(maxday[month-1]>=day) 
  return true;
 else
  return false;
}
 
int main()
{
    string strdate;
    cin>>strdate;
    string datearry[3];
    datearry[0]=strdate.substr(0,2);
    datearry[1]=strdate.substr(3,2);
 datearry[2]=strdate.substr(6,2);
   set<string> dite;
    if(istruedate("19"+datearry[0],datearry[1],datearry[2]))
       dite.insert("19"+datearry[0]+"-"+datearry[1]+"-"+datearry[2]);
    if(istruedate("19"+datearry[0],datearry[2],datearry[1]))
     dite.insert("19"+datearry[0]+"-"+datearry[2]+"-"+datearry[1]);
    if(istruedate("19"+datearry[1],datearry[0],datearry[2]))
     dite.insert("19"+datearry[1]+"-"+datearry[0]+"-"+datearry[2]);
    if(istruedate("19"+datearry[1],datearry[2],datearry[0]))
     dite.insert("19"+datearry[1]+"-"+datearry[2]+"-"+datearry[0]);
    if(istruedate("19"+datearry[2],datearry[0],datearry[1]))
       dite.insert("19"+datearry[2]+"-"+datearry[0]+"-"+datearry[1]);
    if(istruedate("19"+datearry[2],datearry[1],datearry[0]))
       dite.insert("19"+datearry[2]+"-"+datearry[1]+"-"+datearry[0]);
 if(istruedate("20"+datearry[0],datearry[1],datearry[2]))
       dite.insert("20"+datearry[0]+"-"+datearry[1]+"-"+datearry[2]);
    if(istruedate("20"+datearry[0],datearry[2],datearry[1]))
     dite.insert("20"+datearry[0]+"-"+datearry[2]+"-"+datearry[1]);
    if(istruedate("20"+datearry[1],datearry[0],datearry[2]))
     dite.insert("20"+datearry[1]+"-"+datearry[0]+"-"+datearry[2]);
    if(istruedate("20"+datearry[1],datearry[2],datearry[0]))
     dite.insert("20"+datearry[1]+"-"+datearry[2]+"-"+datearry[0]);
    if(istruedate("20"+datearry[2],datearry[0],datearry[1]))
       dite.insert("20"+datearry[2]+"-"+datearry[0]+"-"+datearry[1]);
    if(istruedate("20"+datearry[2],datearry[1],datearry[0]))
       dite.insert("20"+datearry[2]+"-"+datearry[1]+"-"+datearry[0]);
    set<string>::iterator itestr=dite.begin();
   while(itestr!=dite.end())
   {
    cout<<*itestr<<'\n';
    itestr++;
   }
 return 0;
}

 

#include<iostream>
using namespace std;

const int M = 10005;
int min(int x, int y) { return x < y ? x : y; }

int dp(int n, int m) {
	if (m <= 1)return 1;
	int sum = 0;
	for (int i = 1;i < m;i++) {
		sum += dp(n - i, min(n - 1, i));
	}
	return sum;
}
int main() {
	int n;
	cin >> n;
	cout << dp(n, n);
	return 0;
}

#include <iostream>
using namespace std;

int main()
{
    long f[20] = { 0 }; //如果是f[16],vs2022会报错,数组下标溢出
    int i, j;
    f[0] = 1, f[1] = 1, f[2] = 2, f[3] = 5;
    for (i = 4;i <=16;i++) 
        f[i] = 0;
    for (i = 4;i <=16;i++) {
        for (int j = 0;j < i;j++) 
            f[i] += f[j] * f[i - 1 - j];//罪魁祸首:f[i],在这个for循环中,i取到了16,数组下标溢出
        
    }
    
    cout << f[16];
    return 0;
}

//答案:35357670

 

#include<iostream>
#include<bitset>
#include<cmath>
using namespace std;
int n, m;
int nbit(int num) 
{
    int ans = 0;
    while(num)
 {
        num = (num-1) & num;
        ans++;
    }
    return ans;
}
bool check(int now, int floor) 
{
    int num_a=0, num_b=0;
    for(int i=floor;i>=1;i--)   
 { 
        int count1 = nbit(now);  
        num_b += count1;
        num_a += i - count1;  
        now ^= now >> 1;   
        now &= (1 << (i - 1)) - 1;  
        if (num_a > m || num_b > n) 
   return false;  
    }
    return num_a==m &&num_b==n;
}
 
int main() 
{
    cin >> m >> n;
    int floor = sqrt((n + m) * 2);
    int ans = 0;
    for (int i = 0; i < (1 << floor); i++) 
 {
        if (check(i, floor))
            ans++;
    }
    cout << ans << endl;
}

#include <iostream>
#include <algorithm>
using namespace std;

int a[20] = { 1,2,3,4,5,7,8,9,10,12,13 };
int main()
{
	
	
		do {
			int x1 = a[0] + a[1] + a[2] + a[3];
			int x2 = a[0] + a[4] + a[6] + a[9];
			int x3 = 6 + a[1] + a[4] + 14;
			int x4 = 6 + a[2] + a[5] + 11;
			int x5 = a[3] + a[5] + a[7] + a[10];
			int x6 = 14 + a[6] + a[8] + a[10];
			int x7 = a[9] + a[8] + a[7] + 11;
			if (x1 == x2 && x1 == x3 && x1 == x4 && x1 == x5 && x1 == x6 && x1 == x7)
			{
				for (int i = 0;i < 11;i++)
					cout << "a[" << i << "]=" << a[i] << " ";
				cout << endl;
			}
		} while (next_permutation(a, a + 10));
		return 0;
}

//答案:a[0]=10 a[1]=3 a[2]=9 a[3]=8 a[4]=7 a[5]=4 a[6]=1 a[7]=5 a[8]=2 a[9]=12 a[10]=13

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值