头像

TK




在线 


活动打卡代码 AcWing 1503. 乒乓球

TK
4天前

非常NB的题目

#include <bits/stdc++.h>

using namespace std;

#define e(a) exit(a)   // 4
#define rep(i, a, n) for(int i=a;i<n;++i)
#define repe(i, a, n) for(int i=a;i<=n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define pere(i, a, n) for (int i=n;i>=a;--i)
#define trav(a, x) for(auto& a:x)
#define travc(a, x) for(auto a:x)
#define mcpy(a, b) memcpy(a,b,sizeof b)
#define mone(x) memset(x,-1,sizeof x)
#define mmax(x) memset(x,0x3f,sizeof x)
#define mmin(x) memset(x,-0x3f,sizeof x)
#define mzero(x) memset(x,0,sizeof x)
#define bg begin()
#define ed end()
#define ft front()
#define bk back()
#define all(x) x.bg,x.ed
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define p(x) cout<<(x)<<endl
#define pp(x) cout<<x.fi<<' '<<x.se<<endl
#define in() freopen("in.txt", "r", stdin)
#define out() freopen("out.txt", "w", stdout)
#define gtime() cout << "time:" << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl
#define gspace(x) cout << 1.0 * sizeof x / 1024 / 1024 << endl  // 29

typedef long long ll;  //31
typedef unsigned long long ull;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;
typedef unordered_set<int> usi;  //38

ll mod(ll a, ll b) { return (a % b + b) % b; }   // 40
int lb(int x) { return x & -x; }

const int INF = 0x3f3f3f3f;  // 52
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};   //53
/////////////////////////////

const int N = 1e4 + 10, M = 110;

struct R {
    int comeTime, playTime, serveTime, leaveTime;
    bool isVip;

    R() : comeTime(0), playTime(0), serveTime(0), leaveTime(0), isVip(false) {}  // 初始值

    bool operator<(const R &w) const {
        return comeTime < w.comeTime;
    }

} p[N];

queue<int> q1, q2;  // q1是普通队,q2是VIP队

struct T {
    int count, serve;
    bool isVip;

    T() : count(0), serve(-1), isVip(false) {} // 初始值
} t[M];

void print(int t) {
    printf("%02d:%02d:%02d ", t / 3600, t / 60 % 60, t % 60);
}

bool cmp(R a, R b) {
    if (a.serveTime != b.serveTime) return a.serveTime < b.serveTime;
    return a.comeTime < b.comeTime;
}

int main() {
    // in();
    int n, k, m;
    cin >> n;
    rep(i, 0, n) {
        int hh, mm, ss, playTime;
        scanf("%d:%d:%d %d %d", &hh, &mm, &ss, &playTime, &p[i].isVip);
        p[i].comeTime = hh * 3600 + mm * 60 + ss;

        if (playTime > 120) playTime = 120;
        playTime *= 60;
        p[i].playTime = playTime;
    }
    cin >> k >> m;
    while (m--) {
        int x;
        cin >> x;
        t[x].isVip = true;
    }

    sort(p, p + n);

    vector<R> res;  

    int cur = 0;
    rep(T, 28800, 75600) {
        repe(i, 1, k) {  
            if (t[i].serve == -1) continue;  
            int j = t[i].serve;
            if (p[j].leaveTime == T) t[i].serve = -1;
        }

        while (cur < n && p[cur].comeTime <= T) { 
            q1.push(cur);    // 当没有空的vip桌时,vip球员也是普通球员
            if (p[cur].isVip) q2.push(cur);
            cur++;
        }




        while (sz(q2) && p[q2.ft].serveTime) q2.pop();
        repe(i, 1, k) {
            if (!t[i].isVip) continue;  
            if (t[i].serve != -1)continue;  
            if (sz(q2)) {
                int j = q2.ft;
                t[i].serve = j;
                t[i].count++;
                p[j].serveTime = T;  
                p[j].leaveTime = T + p[j].playTime;
                res.pb(p[j]);
                while (sz(q2) && p[q2.ft].serveTime) q2.pop();    // todo
            }
        }



        while (sz(q1) && p[q1.ft].serveTime) q1.pop();
        repe(i, 1, k) {
            if (t[i].serve != -1)continue;  
            if (sz(q1)) {
                int j = q1.ft;
                t[i].serve = j;
                t[i].count++;
                p[j].serveTime = T;  
                p[j].leaveTime = T + p[j].playTime;
                res.pb(p[j]);
                while (sz(q1) && p[q1.ft].serveTime) q1.pop();    // todo
            }

        }

    }

    sort(all(res), cmp);

    trav(i, res) {
        int t1 = i.comeTime, t2 = i.serveTime;
        print(t1), print(t2);
        p((t2 - t1 + 30) / 60);
    }

    bool isFirst = true;
    repe(i, 1, k) {
        if (isFirst) isFirst = false;
        else cout << ' ';
        cout << t[i].count;
    }

}


活动打卡代码 AcWing 1357. 优质牛肋骨

TK
11天前
#include <bits/stdc++.h>

using namespace std;

#define e(a) exit(a)
#define rep(i, a, n) for(int i=a;i<n;++i)
#define repe(i, a, n) for(int i=a;i<=n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define pere(i, a, n) for (int i=n;i>=a;--i)
#define trav(a, x) for(auto& a:x)
#define travc(a, x) for(auto a:x)
#define mcpy(a, b) memcpy(a,b,sizeof b)
#define mone(x) memset(x,-1,sizeof x)
#define mmax(x) memset(x,0x3f,sizeof x)
#define mmin(x) memset(x,-0x3f,sizeof x)
#define mzero(x) memset(x,0,sizeof x)
#define bg begin()
#define ed end()
#define ft front()
#define all(x) x.bg,x.ed
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define p(x) cout<<(x)<<endl
#define pp(x) cout<<x.fi<<' '<<x.se<<endl
#define in() freopen("in.txt", "r", stdin)
#define out() freopen("out.txt", "w", stdout)

typedef long long ll;  //31
typedef unsigned long long ull;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;
typedef unordered_set<int> usi;

ll mod(ll a, ll b) { return (a % b + b) % b; }

const int INF = 0x3f3f3f3f;
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};


int n;

bool isPrime(int x) {
    for (int i = 2; i <= x / i; i++)
        if (x % i == 0) return false;
    return true;
}

void dfs(int x, int k) { 
    if (!isPrime(x)) return;  
    if (k == n) {
        cout << x << endl;
        return;
    }

    int d[] = {1, 3, 7, 9};  
    trav(i, d) dfs(x * 10 + i, k + 1);  
}

int main() {
    cin >> n;

    dfs(2, 1), dfs(3, 1), dfs(5, 1), dfs(7, 1);
    return 0;
}



活动打卡代码 AcWing 1356. 回文质数

TK
11天前
#include <bits/stdc++.h>

using namespace std;

#define e(a) exit(a)
#define rep(i, a, n) for(int i=a;i<n;++i)
#define repe(i, a, n) for(int i=a;i<=n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define pere(i, a, n) for (int i=n;i>=a;--i)
#define trav(a, x) for(auto& a:x)
#define travc(a, x) for(auto a:x)
#define mcpy(a, b) memcpy(a,b,sizeof b)
#define mone(x) memset(x,-1,sizeof x)
#define mmax(x) memset(x,0x3f,sizeof x)
#define mmin(x) memset(x,-0x3f,sizeof x)
#define mzero(x) memset(x,0,sizeof x)
#define bg begin()
#define ed end()
#define ft front()
#define all(x) x.bg,x.ed
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define p(x) cout<<(x)<<endl
#define pp(x) cout<<x.fi<<' '<<x.se<<endl
#define in() freopen("in.txt", "r", stdin)
#define out() freopen("out.txt", "w", stdout)

typedef long long ll;  //31
typedef unsigned long long ull;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;
typedef unordered_set<int> usi;

ll mod(ll a, ll b) { return (a % b + b) % b; }

const int INF = 0x3f3f3f3f;
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
//////////////////////////////////////////

const int N = 1e7 + 10;

int p[N], cnt;
bool st[N];

void init(int n) {
    repe(i, 2, n) {
        if (!st[i]) p[cnt++] = i;
        for (int j = 0; p[j] <= n / i; j++) {
            st[p[j] * i] = true;
            if (i % p[j] == 0) break;
        }
    }
}

bool check(int x) {
    string s = to_string(x);
    for (int i = 0, j = sz(s) - 1; i < j; i++, j--)
        if (s[i] != s[j]) return false;
    return true;
}

int main() {
    init(N - 1);
    int a, b;
    scanf("%d%d", &a, &b);
    rep(i, 0, cnt) {
        int v = p[i];
        if (v >= a && v <= b && check(v)) printf("%d\n", v);
    }

    return 0;
}



活动打卡代码 AcWing 898. 数字三角形

TK
11天前
#include <bits/stdc++.h>
using namespace std;

#define e(a) exit(a)
#define rep(i,a,n) for(int i=a;i<n;++i)
#define repe(i,a,n) for(int i=a;i<=n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define pere(i,a,n) for(int i=n;i>=a;--i)
#define trav(a,x) for(auto&a:x)
#define travc(a,x) for(auto a:x)
#define mone(a) memset(a,-1,sizeof a)
#define mzero(a) memset(a,0,sizeof a)
#define mmax(a) memset(a,0x3f,sizeof a)
#define mcpy(a,b) memset(a,b,sizeof a)
#define fi first
#define se second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define sz(x) (int)x.size()
#define ft front()
#define mp make_pair
#define pb push_back
#define p(x) cout<<(x)<<endl
#define pp(x) cout<<x.fi<<' '<<x.se<<endl
#define gtime() cout<<1.0*clock()/CLOCKS_PER_SEC<<".s"<<endl
#define gspace(x) cout<<1.0*sizeof x/1024/1024<<endl
#define in() freopen("in.txt","r",stdin)
#define out() freopen("out.txt","w",stdout)

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;
typedef unordered_set<int> usi;
typedef pair<int, int> pii;

ll mod(ll a, ll b) {return (a % b + b) % b;}

ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}

ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}

int lb(int x) {return x & -x;}

ll qmi(ll a, ll k, ll p) {ll res = 1; a %= p; while(k) {if(k & 1)res = res * a % p; k >>= 1, a = a * a % p;} return res;}

ll qmul(ll a, ll b, ll p) {ll res = 0; a %= p; while(b) {if(b & 1)res = (res + a) % p; b >>= 1, a = (a + a) % p;} return res;}

const int INF = 0x3f3f3f3f;
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
//////////////////////////////////////


const int N = 510;

int f[N][N], a[N][N];

int main()
{
//  in();
  int n;
  cin>>n;
  repe(i,1,n)
  {
    repe(j,1,i)
    cin>>a[i][j];
  }

  repe(i,0,n)
  {
    repe(j,0,n)
    {
      f[i][j]=-INF;
    }
  }

  f[1][1]=a[1][1];
  repe(i,1,n)
  {
    repe(j,1,i)
    {
      if( i==1&&j==1) continue;
      f[i][j]=max(f[i-1][j],f[i-1][j-1])+a[i][j];
    }
  }

  int res = -INF;
  repe(i,1,n) res = max(res,f[n][i]);
  cout<<res<<endl;

  return 0;
}



活动打卡代码 AcWing 1355. 母亲的牛奶

TK
12天前
#include <bits/stdc++.h>

using namespace std;

#define e(a) exit(a)
#define rep(i, a, n) for(int i=a;i<n;++i)
#define repe(i, a, n) for(int i=a;i<=n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define pere(i, a, n) for (int i=n;i>=a;--i)
#define trav(a, x) for(auto& a:x)
#define travc(a, x) for(auto a:x)
#define mcpy(a, b) memcpy(a,b,sizeof b)
#define mone(x) memset(x,-1,sizeof x)
#define mmax(x) memset(x,0x3f,sizeof x)
#define mzero(x) memset(x,0,sizeof x)
#define bg begin()
#define ed end()
#define ft front()
#define all(x) x.bg,x.ed
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define p(x) cout<<(x)<<endl
#define pp(x) cout<<x.fi<<' '<<x.se<<endl
#define in() freopen("in.txt", "r", stdin)
#define out() freopen("out.txt", "w", stdout)

typedef long long ll;  //31
typedef unsigned long long ull;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;
typedef unordered_set<int> usi;

ll mod(ll a, ll b) { return (a % b + b) % b; }

const int INF = 0x3f3f3f3f;
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};


const int N = 21;

int A, B, C;
bool st[N][N][N];
struct Node {
    int a, b, c;
} q[N * N * N];

int hh, tt = -1;

void insert(int a, int b, int c) {
    if (!st[a][b][c]) {
        q[++tt] = {a, b, c};
        st[a][b][c] = true;
    }
}

void bfs() {
    q[++tt] = {0, 0, C};
    st[0][0][C] = true;
    while (hh <= tt) {
        auto t = q[hh++];
        int a = t.a, b = t.b, c = t.c;

        insert(a - min(a, B - b), min(a + b, B), c);


        insert(a - min(a, C - c), b, min(a + c, C));
        insert(min(a + b, A), b - min(b, A - a), c);
        insert(a, b - min(b, C - c), min(b + c, C));
        insert(min(a + c, A), b, c - min(A - a, c));
        insert(a, min(b + c, B), c - min(B - b, c));
    }
}

int main() {
    // in();
    cin >> A >> B >> C;
    bfs();


    for (int c = 0; c <= C; c++)
        for (int b = 0; b <= B; b++)
            if (st[0][b][c]) cout << c << ' ';

    return 0;
}



活动打卡代码 AcWing 1354. 等差数列

TK
13天前
#include <bits/stdc++.h>

using namespace std;

#define e(a) exit(a)
#define rep(i, a, n) for(int i=a;i<n;++i)
#define repe(i, a, n) for(int i=a;i<=n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define pere(i, a, n) for (int i=n;i>=a;--i)
#define trav(a, x) for(auto& a:x)
#define travc(a, x) for(auto a:x)
#define mcpy(a, b) memcpy(a,b,sizeof b)
#define mone(x) memset(x,-1,sizeof x)
#define mmax(x) memset(x,0x3f,sizeof x)
#define mzero(x) memset(x,0,sizeof x)
#define bg begin()
#define ed end()
#define ft front()
#define all(x) x.bg,x.ed
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define p(x) cout<<(x)<<endl
#define pp(x) cout<<x.fi<<' '<<x.se<<endl
#define in() freopen("in.txt", "r", stdin)
#define out() freopen("out.txt", "w", stdout)

typedef long long ll;  //31
typedef unsigned long long ull;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;
typedef unordered_set<int> usi;

ll mod(ll a, ll b) { return (a % b + b) % b; }

const int INF = 0x3f3f3f3f;
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};


const int N = 250 * 250 * 2 + 10, M = 10000;



int n, m;
bool st[N];

struct seq {
    int a, b;


    bool operator<(const seq &t) const {
        if (b != t.b) return b < t.b;
        return a < t.a;
    }
} seq[M];

int main() {
    cin >> n >> m;
    repe(p, 0, m) {   
        repe(q, p, m) {
            st[p * p + q * q] = true;  
        }
    }

    int cnt = 0, s = m * m * 2;  
    repe(i, 0, s) {  
        if (st[i])  
            repe(j, i + 1, s) {  
                if (st[j]) {    
                    int d = j - i, last = i + d * (n - 1);   
                    if (last > s) break;  

                    bool flag = true;  
                    for (int k = j + d; k <= last; k += d)
                        if (!st[k]) {  
                            flag = false;
                            break;
                        }
                    if (flag) seq[cnt++] = {i, d};  
                }
            }
    }

    if (!cnt) puts("NONE");  
    else {
        sort(seq, seq + cnt);
        rep(i, 0, cnt) cout << seq[i].a << ' ' << seq[i].b << endl;
    }

    return 0;
}


活动打卡代码 AcWing 1353. 滑雪场设计

TK
13天前
#include <bits/stdc++.h>

using namespace std;

#define e(a) exit(a)
#define rep(i, a, n) for(int i=a;i<n;++i)
#define repe(i, a, n) for(int i=a;i<=n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define pere(i, a, n) for (int i=n;i>=a;--i)
#define trav(a, x) for(auto& a:x)
#define travc(a, x) for(auto a:x)
#define mcpy(a, b) memcpy(a,b,sizeof b)
#define mone(x) memset(x,-1,sizeof x)
#define mmax(x) memset(x,0x3f,sizeof x)
#define mzero(x) memset(x,0,sizeof x)
#define bg begin()
#define ed end()
#define ft front()
#define all(x) x.bg,x.ed
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define p(x) cout<<(x)<<endl
#define pp(x) cout<<x.fi<<' '<<x.se<<endl
#define in() freopen("in.txt", "r", stdin)
#define out() freopen("out.txt", "w", stdout)

typedef long long ll;  //31
typedef unsigned long long ull;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;
typedef unordered_set<int> usi;

ll mod(ll a, ll b) { return (a % b + b) % b; }

const int INF = 0x3f3f3f3f;
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};


const int N = 1010;

int n, h[N];

int main() {
    // in();
    cin >> n;
    rep(i, 0, n) cin >> h[i];

    int res = INF;  


    repe(i, 0, 83) {
        int j = i + 17, cost = 0;  
        rep(k, 0, n) {   
            if (h[k] > j) cost += pow(h[k] - j, 2);
            else if (h[k] < i) cost += pow(i - h[k], 2);
        }
        res = min(res, cost);
    }

    cout << res << endl;

    return 0;
}



活动打卡代码 AcWing 1352. 虫洞

TK
13天前
#include <bits/stdc++.h>

using namespace std;

#define e(a) exit(a)
#define rep(i, a, n) for(int i=a;i<n;++i)
#define repe(i, a, n) for(int i=a;i<=n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define pere(i, a, n) for (int i=n;i>=a;--i)
#define trav(a, x) for(auto& a:x)
#define travc(a, x) for(auto a:x)
#define mcpy(a, b) memcpy(a,b,sizeof b)
#define mone(x) memset(x,-1,sizeof x)
#define mmax(x) memset(x,0x3f,sizeof x)
#define mzero(x) memset(x,0,sizeof x)
#define bg begin()
#define ed end()
#define ft front()
#define all(x) x.bg,x.ed
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define p(x) cout<<(x)<<endl
#define pp(x) cout<<x.fi<<' '<<x.se<<endl
#define in() freopen("in.txt", "r", stdin)
#define out() freopen("out.txt", "w", stdout)

typedef long long ll;  
typedef unsigned long long ull;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;
typedef unordered_set<int> usi;

ll mod(ll a, ll b) { return (a % b + b) % b; }


const int N = 12;

int n;
int to1[N], to2[N];  
bool st[N], used[N][2], cur[N][2];





struct Point {
    int x, y;

    bool operator<(const Point &t) const {  
        if (y != t.y) return y < t.y;  
        return x < t.x;
    }
} q[N];     

int ans;  

bool dfs_c(int a, int b) {   
    if (cur[a][b]) return true;  
    if (used[a][b]) return false;  

    cur[a][b] = used[a][b] = true;



    bool res = false;  

    if (!b) {   
        if (dfs_c(to2[a], 1)) res = true;  
    } else {   
        if (to1[a] != -1 && dfs_c(to1[a], 0)) res = true;


    }



    cur[a][b] = false;  
    return res;
}

bool check() {  
    mzero(used), mzero(cur);

    rep(i, 0, n) { 
        rep(j, 0, 2) {   
            if (!used[i][j])  
                if (dfs_c(i, j)) return true;  
        }
    }
    return false;
}

void dfs(int u) {
    if (u == n 
        if (check()) ans++;  
        return;
    }


    rep(i, 0, n) {
        if (!st[i]) {  
            rep(j, i + 1, n) {
                if (!st[j]) {   

                    st[i] = st[j] = true;
                    to2[i] = j, to2[j] = i;

                    dfs(u + 1);  


                    to2[i] = to2[j] = -1;
                    st[i] = st[j] = false;
                }
            }
            break;  
        }
    }

}

int main() {

    cin >> n;
    rep(i, 0, n) cin >> q[i].x >> q[i].y;  
    sort(q, q + n);  

    mone(to1), mone(to2);  

    rep(i, 1, n) {  
        if (q[i].y == q[i - 1].y) to1[i - 1] = i;  

    }

    dfs(0);  
    cout << ans << endl;

    return 0;
}


活动打卡代码 AcWing 1351. 密码锁

TK
19天前
#include <bits/stdc++.h>

using namespace std;

#define e(a) exit(a)
#define rep(i, a, n) for(int i=a;i<n;++i)
#define repe(i, a, n) for(int i=a;i<=n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define pere(i, a, n) for (int i=n;i>=a;--i)
#define trav(a, x) for(auto& a:x)
#define travc(a, x) for(auto a:x)
#define mcpy(a, b) memcpy(a,b,sizeof b)
#define mone(x) memset(x,-1,sizeof x)
#define mmax(x) memset(x,0x3f,sizeof x)
#define mzero(x) memset(x,0,sizeof x)
#define bg begin()
#define ed end()
#define ft front()
#define all(x) x.bg,x.ed
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define p(x) cout<<(x)<<endl
#define pp(x) cout<<x.fi<<' '<<x.se<<endl
#define in() freopen("in.txt", "r", stdin)
#define out() freopen("out.txt", "w", stdout)

typedef long long ll;  31
typedef unsigned long long ull;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;
typedef unordered_set<int> usi;

ll mod(ll a, ll b) { return (a % b + b) % b; }


const int N = 5;

int n, a[N], b[N];

bool check(int a[], int b[]) {
    rep(i, 0, 3) {
        if (abs(a[i] - b[i]) > 2 && n - abs(a[i] - b[i]) > 2)  
            return false;  
    }
    return true;
}

int main() {
     in();
    cin >> n;

    rep(i, 0, 3) cin >> a[i];
    rep(i, 0, 3)cin >> b[i];

    int res = 0;
    repe(i, 1, n) {
        repe(j, 1, n) {
            repe(k, 1, n) {
                int v[] = {i, j, k};
                if (check(v, a) || check(v, b)) res++;
            }
        }
    }
    cout << res << endl;
    return 0;
}



活动打卡代码 AcWing 1350. 密码运算

TK
19天前
#include <bits/stdc++.h>

using namespace std;

#define e(a) exit(a)
#define rep(i, a, n) for(int i=a;i<n;++i)
#define repe(i, a, n) for(int i=a;i<=n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define pere(i, a, n) for (int i=n;i>=a;--i)
#define trav(a, x) for(auto& a:x)
#define travc(a, x) for(auto a:x)
#define mcpy(a, b) memcpy(a,b,sizeof b)
#define mone(x) memset(x,-1,sizeof x)
#define mmax(x) memset(x,0x3f,sizeof x)
#define mzero(x) memset(x,0,sizeof x)
#define bg begin()
#define ed end()
#define ft front()
#define all(x) x.bg,x.ed
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define p(x) cout<<(x)<<endl
#define pp(x) cout<<x.fi<<' '<<x.se<<endl
#define in() freopen("in.txt", "r", stdin)
#define out() freopen("out.txt", "w", stdout)

typedef long long ll;  31
typedef unsigned long long ull;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;
typedef unordered_set<int> usi;

ll mod(ll a, ll b) { return (a % b + b) % b; }


const int N = 15;

int n;
bool st[N];

bool check_in(int a) {
    while (a) {
        if (!st[a % 10]) return false;
        a /= 10;
    }
    return true;
}

bool check_len(int a, int k) {
    return sz(to_string(a)) == k;
}

bool check(int a, int b) {
    int c = a * (b % 10), d = a * (b / 10), e = a * b;


    if (!check_in(a) || !check_in(b) || !check_in(c) || !check_in(d) || !check_in(e)) return false;


    if (!check_len(c, 3) || !check_len(d, 3) || !check_len(e, 4)) return false;

    return true;
}

int main() {
     in();
    cin >> n;
    rep(i, 0, n) {
        int x;
        cin >> x;
        st[x] = true;
    }

    int res = 0;  
    for (int a = 100; a <= 999; a++)
        for (int b = 10; b <= 99; b++)
            if (check(a, b)) res++;  

    cout << res << endl;

    return 0;
}