第十一届蓝桥杯省赛B组

 

 

这道题是一道填空题,然后我们可以通过观察找规律来得出答案
通过观察发现:
第一行第一列 : 1 1^2 + (1-1)^2 = 1
第二行第二列: 5 2^2 + (2-1)^2 = 5
第三行第三列: 13 3^2 + (3-1)^2 = 13
第四行第四列: 25 4^2 + (4-1)^2 = 25
第五行第五列: 41 5^2 + (5-1)^2 = 41

所以通过找规律发现:第n行第n列 = n^2 + (n-1)^2
第二十行第二十列 : 20*2 + (20-1)^2 = 761


答案:761

接下来两个日期题:

 

 

解题思路:

1.用 0 ~ 6 来代表 周一 至 周日;
2.用 sum 来代表 2000年1月1日 至 某年某月某日 所经过的天数;
3.由于 2000年1月1日 是周六,那么用 (sum + 5) % 7 就能表示 某年某月某日 是星期几;
4.因为 2020年10月1日 未处理,所以最后 ans += 2

 1 #include <iostream>
 2 #include <cstring>
 3 #include <string>
 4 #include <algorithm>
 5 #include <queue>
 6 
 7 using namespace std;
 8 
 9 typedef long long LL;
10 typedef pair<int, int>PII;
11 
12 int days[] = { 0 , 31 , 28 , 31 ,30 ,31 , 30 , 31 ,31 , 30 , 31 , 30 , 31 };
13 
14 bool leap(int year)
15 {
16     if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return true;
17     return false;
18 }
19 
20 int getday(int year, int month)
21 {
22     if (month == 2) return 28 + leap(year);
23     return days[month];
24 }
25 
26 int main()
27 {
28     int sum = 0, ans = 0;
29     for (int i = 2000; i <= 2019; i++)
30         for (int j = 1; j <= 12; j++)
31             for (int k = 1; k <= getday(i, j); k++)//这个月第几天,看是不是月初
32             {
33                 int weekday = (sum + 5) % 7;
34                 if (k == 1 || weekday == 0) ans += 2;
35                 else ans++;
36 
37                 sum++;
38             }
39 
40     //单独处理2020年
41     for (int j = 1; j <= 9; j++)
42         for (int k = 1; k <= getday(2020, j); k++)
43         {
44             int weekday = (sum + 5) % 7;
45             if (k == 1 || weekday == 0) ans += 2;
46             else ans++;
47 
48             sum++;
49         }
50 
51     cout << ans + 2 << endl;
52     return 0;
53 }

 

 

 

 

解题思路:

直接枚举年份 a,将其翻转得到 b,那么 a + b 就是一个回文数;
用 substr 分离出月份和天数,再判断月份和天数是否合法;


实用函数:

stoi(x):将字符串转换成数字;
to_string(x):将数字转换成字符串;
substr(u, len):从第 u 位开始,截取一段长度为 len 的字符串;

写的前三个有关日期天数的函数还是很好用的

 1 #include <iostream>
 2 #include <cstring>
 3 #include <string>
 4 #include <algorithm>
 5 #include <queue>
 6 
 7 using namespace std;
 8 
 9 typedef long long LL;
10 typedef pair<int, int>PII;
11 
12 int days[] = { 0 , 31 , 28 , 31 ,30 ,31 , 30 , 31 ,31 , 30 , 31 , 30 , 31 };
13 
14 bool leap(int year)
15 {
16     if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return true;
17     return false;
18 }
19 
20 int getday(int year, int month)
21 {
22     if (month == 2) return 28 + leap(year);
23     return days[month];
24 }
25 
26 int main()
27 {
28     string  res1 , res2;
29     int n;
30     cin >> n;
31 
32     bool flag1 = false, flag2 = false;
33     for (int i = n / 10000; i <= 9999; i++)
34     {
35         string a;
36         a = to_string(i);
37         string b;
38         b = a;
39 
40         reverse(b.begin(), b.end());
41         if (stoi(a + b) == n) continue;
42 
43         int month = stoi(b.substr(0, 2));
44         int day = stoi(b.substr(2, 2));
45 
46         if (month < 1 || month > 12) continue;
47         if (day < 1 || day > getday(i, month)) continue;
48 
49         //ABAB型为月份和日期相同
50         string s1 = a.substr(0, 2);//月份
51         string s2 = a.substr(2, 2);//天数
52 
53         if (!flag1)//回文
54         {
55             res1 = a + b;
56             flag1 = true;
57         }
58         if (!flag2 && s1 == s2 && s1[0] != s1[1])//ABAB型  A!=B
59         {
60             res2 = a + b;
61             flag2 = true;
62         }
63 
64         if (flag1 && flag2) break;
65     }
66 
67     cout << res1 << endl << res2 << endl;
68 
69     return 0;
70 }

 

 

 

 

用set

在同一个平面内,如果添加的每一条直线互不相交,则每添加一条直线,就会增加一个平面;当添加一条直线时,这条直线与当前平面内已有直线每产生一个不同位置的交点时,这条直线对平面总数量的贡献会额外增多一个, 记为Si,值Si的值为经过该直线的点+1,1为直线自身贡献的平面 , 结果为每一条直线的贡献加上最开始的一个平面,既:S1到Sk的和(k为所有不重合直线的数量)再加上1。
所以我们可以在每添加一条直线时设置一个空的set,将直线与当前平面内其他直线的交点的xy坐标存入set中,如果这一条直线不是重边,则这条直线的贡献为set.size()+1,即ans为所有直线的贡献加上原来的一个平面。

#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

typedef long long LL;
typedef pair<int, int>PII;

double L[1010][2];
bool st[1010];

pair<double, double>p;
set<pair<double, double>>points;

int main()
{
    int n;
    cin >> n;
    LL res = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> L[i][0] >> L[i][1];
        for (int j = 0; j < i; j++)//依次比较 查找重边
        {
            if (st[j]) continue;//直线是重边

            if (L[i][0] == L[j][0])//斜率相等,判断平行还是重合
            {
                if (L[i][1] == L[j][1])
                {
                    st[i] = true;
                    break;
                }
                else continue;//平行,不需要计算交点
            }

            p.first = (L[j][1] - L[i][1]) / (L[i][0] - L[j][0]);//交点x的坐标
            p.second = L[i][0] * p.first + L[i][1];//交点y的坐标
            points.insert(p);
        }

        if (!st[i]) res += points.size() + 1;//若当前点不是重边,更新答案
    }
    
    cout << res + 1 << endl;

    return 0;
}

 

posted @ 2021-04-13 15:28  彦辰kkkkk  阅读(396)  评论(0)    收藏  举报