蓝桥杯

2015年

[蓝桥杯2015初赛]

方程整数解

时间限制: 1 Sec  内存限制: 256 MB

题目描述

方程: a^2 + b^2 + c^2 = 1000
这个方程有正整数解吗?有:a,b,c=6,8,30 就是一组解。
求出 a^2 + b^2 + c^2 = n(1<=n<=10000)的所有解,解要保证c>=b>=a>=1。

输入

存在多组测试数据,每组测试数据一行包含一个正整数n(1<=n<=10000)

输出

如果无解则输出”No Solution”。
如果存在多解,每组解输出1行,输出格式:a b c,以一个空格分隔
按照a从小到大的顺序输出,如果a相同则按照b从小到大的顺序输出,如果a,b都相同则按照c从小到大的顺序输出。

样例输入

4
1000

样例输出

No Solution
6 8 30
10 18 24

提示

题目已改编。

#include<iostream>
#include<cmath>

using namespace std;

int main()
{
  int x;
  while (cin >> x)
  {
    int m = 0;
    for (int i = 1; i <= sqrt(x - 2); i++)
      for (int j = 1; j <= sqrt(x - 2); j++)
        for (int k = 1; k <= sqrt(x - 2); k++)
        {
      if (i*i + j*j + k*k == x && (i <= j&&j <= k))
      {
        m = 1;
        cout << i << " " << j << " " << k << endl;
      }
        }
    if (!m)cout << "No Solution" << endl;
  }
  return 0;
}

 

[蓝桥杯2015初赛]

星系炸弹

时间限制: 1 Sec  内存限制: 256 MB

题目描述

在X星系的广袤空间中漂浮着许多X星人造“炸弹”,用来作为宇宙中的路标。
每个炸弹都可以设定多少天之后爆炸。
比如:阿尔法炸弹2015年1月1日放置,定时为15天,则它在2015年1月16日爆炸。
有一个贝塔炸弹,a年b月c日放置,定时为n天,请你计算它爆炸的准确日期。

输入

输入存在多组数据,每组数据输入一行,每一行输入四个正整数a,b,c,n
输入保证日期在1000-01-01到2020-01-01之间,且日期合法。
n不超过1000

输出

请填写该日期,格式为 yyyy-mm-dd  即4位年份2位月份2位日期。比如:2015-02-19
请严格按照格式书写。不能出现其它文字或符号。

样例输入

2015 1 1 15
2014 11 9 1000

样例输出

2015-01-16
2017-08-05

提示

题目已改编。
#include<iostream>

using namespace std;
int isleapyear(int n);

int main()
{
  int days[2][12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  int a, b, c, n;
  while (cin >> a >> b >> c >> n)
  {
    while (1)
    {
      if (b == 13){ a++; b = 1; }
      if (c + n > days[isleapyear(a)][b - 1])
      {
        n -= days[isleapyear(a)][b - 1] - c;
        b++;
        c = 0;
      }
      else { c += n; break; }
    }
    cout << a << "-";
    if (b < 10)cout << "0";
    cout << b << "-";
    if (c < 10)cout << "0";
    cout << c << endl;
  }
  return 0;
}

int isleapyear(int n)
{
  if ((n % 4 == 0 && n % 100 != 0) || n % 400 == 0)return 1;
  else return 0;
}

 

[蓝桥杯2015初赛]

奇妙的数字

时间限制: 1 Sec  内存限制: 256 MB

题目描述

小明发现了一个奇妙的数字。它的平方和立方正好把0~9的10个数字每个用且只用了一次。你能猜出这个数字是多少吗?

输出

请输出该数字,不要输出任何多余的内容。
#include<iostream>
#include<cmath>

using namespace std;
void divide(int n, int *a);

int main()
{
  for (int i = 47; i < 100; i++)//i在此范围内i^2和i^3的位数和为10
  {
    int n1 = (int)log10(i*i) + 1;
    int n2 = (int)log10(i*i*i) + 1;
    int *a1 = new int[n1];
    divide(i*i, a1);
    int *a2 = new int[n2];
    divide(i*i*i, a2);
    int *a = new int[10];//n1+n2=10
    for (int i = 0; i < 10; i++)
    {
      if (i < n1)a[i] = a1[i];
      else a[i] = a2[i - n1];
    }
    for (int i = 0; i < 10; i++)
      for (int j = 0; j < 10 - i - 1; j++)
        if (a[j]>a[j+1])swap(a[j], a[j+1]);
    int res = 1;
    for (int i = 0; i < 10; i++)
      if (a[i] != i)res = 0;
    if (res)cout << i;
  }
  return 0;
}

void divide(int n, int *a)
{
  int t = 0;
  a[t++] = n % 10;
  while (n / 10)
  {
    n /= 10;
    a[t++] = n % 10;
  }
}

 

[蓝桥杯2015初赛]

饮料换购

时间限制: 1 Sec  内存限制: 256 MB

题目描述

乐羊羊饮料厂正在举办一次促销优惠活动。
乐羊羊C型饮料,凭3个瓶盖可以再换一瓶C型饮料,并且可以一直循环下去(但不允许暂借或赊账)。
请你计算一下,如果小明不浪费瓶盖,尽量地参加活动。
那么,对于他初始买入的n瓶饮料,最后他一共能喝到多少瓶饮料。

输入

输入存在多组测试数据
每组测试数据输入一行包含一个正整数n(1<=n<=10000)

输出

对于每组数据输出一行,包含一个整数,表示实际得到的饮料数

样例输入

100
101

样例输出

149
151
#include<iostream>

using namespace std;

int main()
{
  int m;
  while (cin >> m)
  {
    int n = 0, num = m;
    while (m + n >= 3)
    {
      int temp_m = m; 
      m = (m + n) / 3;
      n = (temp_m + n) % 3;
      num += m;
    }
    cout << num << endl;
  }
  return 0;
}

 

奖券数目

时间限制: 1 Sec  内存限制: 256 MB

题目描述

有些人很迷信数字,比如带“4”的数字,认为和“死”谐音,就觉得不吉利。
虽然这些说法纯属无稽之谈,但有时还要迎合大众的需求。
某抽奖活动奖券号码是5位数(10000-99999),要求其中不要出现带“4”的号码。
主办单位请你计算一下,如果任何两张奖券不重号,最多可发出奖券多少张。

输出

请提交该数字(一个整数),不要写任何多余的内容或说明性文字。
#include<iostream>

using namespace std;
void divide(int n, int *a);

int main()
{
  int n = 0;
  for (int i = 10000; i <= 99999; i++)
  {
    int k = 1;
    int num[5];
    divide(i, num);
    for (int j = 0; j < 5; j++)
      if (num[j] == 4){ k = 0; break; }
    if (k)n++;
  }
  cout << n;
  return 0;
}

void divide(int n, int *a)
{
  int t = 0;
  a[t++] = n % 10;
  while (n / 10)
  {
    n /= 10;
    a[t++] = n % 10;
  }
}

 

[蓝桥杯2015初赛]

三羊献瑞

时间限制: 1 Sec  内存限制: 256 MB

题目描述

观察下面的加法算式:

其中,相同的汉字代表相同的数字,不同的汉字代表不同的数字。
请你填写“三羊献瑞”所代表的4位数字(答案唯一),不要填写任何多余内容。

输出

请你填写“三羊献瑞”所代表的4位数字(答案唯一),不要填写任何多余内容。
#include<iostream>
#define f(x) for(int x=0;x<=9;x++)
using namespace std;
void divide(int n, int *a);

int main()
{
  f (a)
    f (b)
      f (c)
        f (d)
          f (e)
            f (f)
              f (g)
              {
    if (a != b && a != c && a != d && a != e && a != f && a != g  && b != c && b != d && b != e && b != f && b != g &&  c != d && c != e && c != f && c != g &&  d != e && d != f && d != g && e != f && e != g &&  f != g)
    {
      int n = a * 1000 + b * 100 + c * 10 + d + e * 1000 + f * 100 + g * 10 + b;
      if (n < 10000)break;
      int num[5];
      divide(n, num);
      if (num[4] == e && num[3] == f && num[2] == c && num[1] == b && num[0] != a && num[0] != b && num[0] != c && num[0] != d && num[0] != e && num[0] != f && num[0] != g)cout << e * 1000 + f * 100 + g * 10 + b;
    }
              }
  return 0;
}


void divide(int n, int *a)
{
  int t = 0;
  a[t++] = n % 10;
  while (n / 10)
  {
    n /= 10;
    a[t++] = n % 10;
  }
}

 

[蓝桥杯2015初赛]

加法变乘法

时间限制: 1 Sec  内存限制: 256 MB

题目描述

我们都知道:1+2+3+ … + 49 = 1225
现在要求你把其中两个不相邻的加号变成乘号,使得结果为2015
比如:
1+2+3+…+10*11+12+…+27*28+29+…+49 = 2015 就是符合要求的答案。
请你寻找另外一个可能的答案,并把位置靠前的那个乘号左边的数字提交。
(对于示例,就是提交10)。

输出

注意:需要你提交的是一个整数,不要填写任何多余的内容。
#include<iostream>
using namespace std;
int main()
{
  for (int i = 1; i <= 46; i++)
    for (int j = i + 2; j <= 48; j++)
      if (1225 - i - (i + 1) - j - (j + 1) + i*(i + 1) + j*(j + 1) == 2015)
        if (i != 10)cout << i;
  return 0;
}

 

[蓝桥杯2015初赛]

移动距离

时间限制: 1 Sec  内存限制: 256 MB

题目描述

X星球居民小区的楼房全是一样的,并且按矩阵样式排列。
其楼房的编号为1,2,3… 当排满一行时,从下一行相邻的楼往反方向排号。
比如:当小区排号宽度为6时,开始情形如下:

1  2  3  4  5  6
12 11 10 9  8  7
13 14 15 …..

我们的问题是:已知了两个楼号m和n,需要求出它们之间的最短移动距离
(不能斜线方向移动)

输入

输入存在多组测试数据
输入为3个整数w m n,空格分开,都在1到10000范围内
w为排号宽度,m,n为待计算的楼号。

输出

要求输出一个整数,表示m n 两楼间最短移动距离。

样例输入

6 8 2
4 7 20

样例输出

4
5
#include<iostream>
#include<cmath>
using namespace std;
void judge(const int x, const int w, int &y, int &z);

int main()
{
  int w, m, n;
  while (cin >> w >> m >> n)
  {
    int a, b, c, d;
    judge(m, w, a, b);
    judge(n, w, c, d);
    cout << abs(a - c) + abs(b - d) << endl;
  }
  return 0;
}

void judge(const int x, const int w, int &y, int &z)
{
  y = x / w;
  z = x%w;
  if (y % 2 == 1)
  {
    if (z != 0)
    {
      y += 1;
      z = w - z + 1;
    }
    else
    {
      z = w;
    }
  }
  else
  {
    if (z != 0)
    {
      y += 1;
    }
    else
    {
      z += 1;
    }
  }
}

 

[蓝桥杯2015初赛] 

打印大X

时间限制: 1 Sec  内存限制: 256 MB

题目描述

小明希望用星号拼凑,打印出一个大X,他要求能够控制笔画的宽度和整个字的高度。
为了便于比对空格,所有的空白位置都以句点符来代替。
要求输入两个整数m n,表示笔的宽度,X的高度。

输入

输入存在多组数据
每组测试数据输入一行,包含两个整数,用空格分开
(0<m<n, 3<n<1000, 保证n是奇数)

输出

要求输出一个大X

样例输入

3 9
4 21

样例输出

***.....***
.***...***.
..***.***..
...*****...
....***....
...*****...
..***.***..
.***...***.
***.....***
****................****
.****..............****.
..****............****..
...****..........****...
....****........****....
.....****......****.....
......****....****......
.......****..****.......
........********........
.........******.........
..........****..........
.........******.........
........********........
.......****..****.......
......****....****......
.....****......****.....
....****........****....
...****..........****...
..****............****..
.****..............****.
****................****
#include<iostream>

using namespace std;

int main()
{
  int m, n;
  while (cin >> m >> n)
  {
    int w = m + n / 2 * 2;//宽度
    int i;
    for (i = 0; i < (n - m / 2 * 2 - 1) / 2; i++)
    {
      for (int j = 0; j < i; j++)
        cout << ".";
      for (int j = 0; j < m; j++)
        cout << "*";
      for (int j = 0; j < w - i * 2 - m * 2; j++)
        cout << ".";
      for (int j = 0; j < m; j++)
        cout << "*";
      for (int j = 0; j < i; j++)
        cout << ".";
      cout << endl;
    }
    for (int k = 0; k < m / 2 + 1; k++, i++)
    {
      for (int j = 0; j < i; j++)
        cout << ".";
      for (int j = 0; j < w - i * 2; j++)
        cout << "*";
      for (int j = 0; j < i; j++)
        cout << ".";
      cout << endl;
    }
    i -= 2;
    for (int k = 0; k < m / 2; k++, i--)
    {
      for (int j = 0; j < i; j++)
        cout << ".";
      for (int j = 0; j < w - i * 2; j++)
        cout << "*";
      for (int j = 0; j < i; j++)
        cout << ".";
      cout << endl;
    }
    for (i = (n - m / 2 * 2 - 1) / 2 - 1; i >= 0; i--)
    {
      for (int j = 0; j < i; j++)
        cout << ".";
      for (int j = 0; j < m; j++)
        cout << "*";
      for (int j = 0; j < w - i * 2 - m * 2; j++)
        cout << ".";
      for (int j = 0; j < m; j++)
        cout << "*";
      for (int j = 0; j < i; j++)
        cout << ".";
      cout << endl;
    }
  }
  return 0;
}
 

发表评论

邮箱地址不会被公开。 必填项已用*标注