csp每日习题

欢迎加入:qq群号:1054587486

做题链接:https://csp.ccf.org.cn/csp/index.action?_access_code=1584494752035

点击模拟考试进入

1:201912-1      

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 int n;
 5 
 6 bool in(int x){
 7     while(x){
 8         int t = x % 10;
 9         x /= 10;
10         if(t == 7) return true;
11     }
12     return false;
13 }
14 
15 int main(){
16     cin >> n;
17     int a = 0, b = 0, c = 0, d = 0;
18     for(int i = 1;i <= n;++i){
19         int t = i / 7;
20         int m = i % 4;
21         bool flag = in(i);
22         if(t * 7 == i || flag){
23             ++n;
24             switch(m){
25                 case 0: {++d; break;}
26                 case 1: {++a; break;}
27                 case 2: {++b; break;}
28                 case 3: {++c; break;}
29                 default: break;        
30             }
31         }
32     }
33     cout << a << endl;
34     cout << b << endl;
35     cout << c << endl;
36     cout << d << endl;
37     return 0;
38 }
View Code

2:201912-2

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 const int N = 1e3+10;
 5 
 6 struct Node{
 7     int x, y;
 8     Node(int a, int b){
 9         x = a, y = b;
10     }
11 };
12 int n;
13 
14 struct HashFunc
15 {
16     std::size_t operator()(const Node &key) const 
17     {
18         using std::size_t;
19         using std::hash;
20 
21         return ((hash<int>()(key.x) ^ (hash<int>()(key.y) << 1)) >> 1);
22     }
23 };
24 
25 struct EqualKey
26 {
27     bool operator () (const Node &lhs, const Node &rhs) const
28     {
29         return lhs.x == rhs.x && lhs.y == rhs.y;
30     }
31 };
32 
33 int main(){
34     unordered_map<Node, bool, HashFunc, EqualKey> hash;
35     vector<Node> v;
36     cin >> n;
37     for(int i = 0;i < n;++i){
38         int x, y;
39         cin >> x >> y;
40         v.push_back({x, y});
41         hash[v[i]] = true;
42     }
43     int res[5] = {0};
44     for(auto t : v){
45         int x = t.x, y = t.y;
46         if(hash[Node(x-1, y)] && hash[Node(x+1, y)] && hash[Node(x, y+1)] && hash[Node(x, y-1)]){
47             int ans = 0;
48             if(hash[Node(x-1, y-1)]) ++ans;
49             if(hash[Node(x+1, y-1)]) ++ans;
50             if(hash[Node(x-1, y+1)]) ++ans;
51             if(hash[Node(x+1, y+1)]) ++ans;
52             res[ans] ++;
53         }
54     }
55     for(int i = 0;i < 5;++i)cout << res[i] << endl;
56     return 0;
57 }
View Code

持续更新中...

原文地址:https://www.cnblogs.com/sxq-study/p/12517095.html