欧某上分之路——笔记走起,又收获一个!
狐狸说:今天这是第一次,记得下次再来哦!
点击下面链接直达:
题目描述:
代码:
法1:
#include <bits/stdc++.h>
using namespace std;
int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
set<int> res;
void check(int m, int d) {
if (m < 1 || m > 12 || d < 1 || d > days[m]) return;
res.insert(m * 100 + d);
}
int main () {
int num[]={15,6,8,6,9,1,6,1,2,4,9,1,9,8,2,3,6,4,7,7,5,9
,5,0,3,8,7,5,8,1,5,8,6,1,8,3,0,3,7,9,2,7,0,5,8,8,5,7,0,9,9,
1,9,4,4,6,8,6,3,3,8,5,1,6,3,4,6,7,0,7,8,2,7,6,8,9,5,6,5,6,1,4,0,1,0,0,9,4,8,0,9,1,2,8,5,0,2,5,3,3};
for (int a = 0; a < 100; a ++) {
if (num[a] != 2) continue;
for (int b = a + 1; b < 100; b ++) {
if (num[b] != 0) continue;
for (int c = b + 1; c < 100; c ++) {
if (num[c] != 2) continue;
for (int d = c + 1; d < 100; d ++) {
if (num[d] != 3) continue;
for (int i = d + 1; i < 100; i ++)
for (int j = i + 1; j < 100; j ++)
for (int k = j + 1; k < 100; k ++)
for (int l = k + 1; l < 100; l ++)
check(num[i] * 10 + num[j], num[k] * 10 + num[l]);
}
}
}
}
cout << res.size() << endl;
return 0;
}
思路:
- 八个变量——前面四个找到2023(很简单)——后面四个用函数验证是否成立
- 成立就插入,重复的就不会插入!
- 最后.size()计算!
总结:
这道题目不会写,网上看的——但仔细想想感觉也不难!就是多了个容器,还有循环八个感觉太多此一举,然而这很有必要暴力!
set<int> res;
res.insert()——如果添加重复的数据,就不会添加进去!
res.size()——计算里面添加的数据!