20191201

#include "iostream"
using namespace std;
bool is_seven(int n){
if(n%7==0) return 1;
while(n){
if(n%10==7) return 1;
n/=10;
}
return 0;
}
int main(int argc, char* argv[])
{
int n;
cin>>n;
int now = 1;
int num_a=0,num_b=0,num_c=0,num_d=0;
int num = 1;
while(n){
switch(now){
case 1:
if(is_seven(num)){
num_a++;
}else{
n--;
}
break;
case 2:
if(is_seven(num)){
num_b++;
}else{
n--;
}
break;
case 3:
if(is_seven(num)){
num_c++;
}else{
n--;
}
break;
case 4:
if(is_seven(num)){
num_d++;
}else{
n--;
}
break;
}
now++;
num++;
if(now == 5) now =1;
}
cout<<num_a<<endl<<num_b<<endl<<num_c<<endl<<num_d;
return 0;
}
20191202


参考了https://blog.csdn.net/richenyunqi/article/details/103988931
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
// 由于unordered_map是采用哈希实现的,对于系统的类型int, string等,都已经定义好了hash函数,
// 所以如果我们引入新的自定义类型的话,系统并不知道如何去计算我们引入的自定义类型的hash值,
// 所以我们就需要自己定义hash函数,告诉系统用这种方式去计算我们引入的自定义类型的hash值
struct arrayHash
{
//我试过return 0,也AC了,是不是用例中没产生冲突呢?
LL operator()(const array<LL, 2> &p) const { return p[0] * 1e9 + p[1]; }
};
int main()
{
/*
用map存储整个棋盘的所有棋子
@array<LL,2> 用一个二维数组表示棋子横纵坐标
@array<LL,2> 用一个二维数组表示棋子以下信息:
@@LL 表示该棋子上下左右相邻点个数
@@LL 表示该棋子对角线相邻点个数
@array_hash 数组做为key的哈希函数
*/
unordered_map<array<LL, 2>, array<LL, 2>, arrayHash> um;
LL n;
cin >> n;
while (n--)
{
array<LL, 2> p;
cin >> p[0] >> p[1];
um.insert({p, {0, 0}}); //存储当前棋子
for (auto &elemnent : um)
{
auto &q = elemnent.first; //q是每个元素的别名
if ((q[0] == p[0] and abs(q[1] - p[1]) == 1) or (q[1] == p[1] and abs(q[0] - p[0]) == 1))
{
um[p][0]++;
um[q][0]++;
//上下左右的棋子数目加一
}
else if (abs(q[0] - p[0]) == 1 and abs(q[1] - p[1]) == 1)
{
um[p][1]++;
um[q][1]++;
//斜对角棋子数目加一
}
}
}
array<LL, 5> ans{};
for (auto &element : um)
{
auto &nums = element.second;
if (nums[0] == 4)
{
ans[nums[1]]++;
}
}
for (auto nums : ans)
{
cout << nums << endl;
}
return 0;
}
来源:CSDN
作者:古航
链接:https://blog.csdn.net/Protocols7/article/details/104105459