首页 > 其他分享 >2023 Xian Jiaotong University Programming Contest

2023 Xian Jiaotong University Programming Contest

时间:2023-05-22 17:13:07浏览次数:66  
标签:__ const Contest int University Xian using include define

A.大水题

#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
#define fi first
#define se second
#define lc u << 1
#define rc u << 1 | 1
// #define int long long

// #define double long long
// #define int __int128_t
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e7 + 10;

// const int R = 999997;
const int Base = N / 2;
const int M = 1e6 + 10;

// const int P = 1 << 10;
const int INF = 2147483647;

typedef unsigned long long ULL;

const double eps = 1e-4;
const double PI = acos(-1);
const int mod = 1e9 + 7;
int n, k;
int d;
int m;
int Q;
int target;
// int p = INF;
// __int128_t a = 1;

// rope<int> r;
tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> treap;
int primes[N];
bool st[N];
int phi[N];
int cnt;
int T = 0;
LL s[N];

void init(int n)
{
    for (int i = 2; i <= n; i++)
    {
        if (!st[i])
        {
            st[i] = true;
            phi[i] = i - 1;
            primes[cnt++] = i;
        }
        for (int j = 0; primes[j] <= n / i; j++)
        {
            st[i * primes[j]] = true;
            if (i % primes[j])
            {
                phi[i * primes[j]] = phi[i] * phi[primes[j]];
            }
            else
            {
                phi[i * primes[j]] = phi[i] * primes[j];
                break;
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        s[i] = s[i - 1] + phi[i];
    }
}

void solve()
{
    scanf("%d",&n);
    if(n <= 6)
    {
        printf("water\n");
    }
    else
    {
        printf("dry\n");
    }
}

signed main()
{
    int t = 1;
    // str = "codeforces";
    // init();
    // cout << cnt << endl;
    // init();
    // scanf("%d", &t);
    // getchar();
    // int a = 1;
    // for (int i = 1; i <= 26; i++)
    // {
    //     a = (a << 1) + 1;
    // }
    // cout << a << endl;
    // float t = 134217727;
    // int cnt = 200;
    // printf("%.16lf", t);
    // while (cnt--)
    // {
    //     t = t * 2 + a;
    //     printf("%.16f\n", t);
    // }
    // getchar();
    // cout << (int)(log(4) / log(2)) << endl;
    while (t--)
    {
        //     cout << t << endl;
        //     // cout << (2563 % 11) << endl;
        //     // cout << t << endl;
        solve();
        //     // cout << (((float)1) << 63) << endl;
        //     // cout << '\0' << endl;
        //     // cout << f(4);
        //     // cout<<(25 >> 5)
        //     // cout << gcd(31415, 14142);//
        //     // cout << (28284 / 11) << endl;
    }
    return 0;
}

/*
 *                                                     __----~~~~~~~~~~~------___
 *                                    .  .   ~~//====......          __--~ ~~
 *                    -.            \_|//     |||\\  ~~~~~~::::... /~
 *                 ___-==_       _-~o~  \/    |||  \\            _/~~-
 *         __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
 *     _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
 *   .~       .~       |   \\ -_    /  /-   /   ||      \   /
 *  /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
 *  |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
 *           '         ~-|      /|    |-~\~~       __--~~
 *                       |-~~-_/ |    |   ~\_   _-~            /\
 *                            /  \     \__   \/~                \__
 *                        _--~ _/ | .-~~____--~-/                  ~~==.
 *                       ((->/~   '.|||' -_|    ~~-/ ,              . _||
 *                                  -_     ~\      ~~---l__i__i__i--~~_/
 *                                  _-~-__   ~)  \--______________--~~
 *                                //.-~~~-~_--~- |-------~~~~~~~~
 *                                       //.-~~~--\
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 *                               神兽保佑            永无BUG
 */

/**
 *  ┏┓   ┏┓+ +
 * ┏┛┻━━━┛┻┓ + +
 * ┃       ┃
 * ┃   ━   ┃ ++ + + +
 *  ████━████+
 *  ◥██◤ ◥██◤ +
 * ┃   ┻   ┃
 * ┃       ┃ + +
 * ┗━┓   ┏━┛
 *   ┃   ┃ + + + +Code is far away from  
 *   ┃   ┃ + bug with the animal protecting
 *   ┃    ┗━━━┓ 神兽保佑,代码无bug 
 *   ┃        ┣┓
 *    ┃        ┏┛
 *     ┗┓┓┏━┳┓┏┛ + + + +
 *    ┃┫┫ ┃┫┫
 *    ┗┻┛ ┗┻┛+ + + +
 */
View Code

B.原粥率

#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
#define fi first
#define se second
#define lc u << 1
#define rc u << 1 | 1
// #define int long long

// #define double long long
// #define int __int128_t
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e7 + 10;

// const int R = 999997;
const int Base = N / 2;
const int M = 1e6 + 10;

// const int P = 1 << 10;
const int INF = 2147483647;

typedef unsigned long long ULL;

const double eps = 1e-4;
const double PI = acos(-1);
const int mod = 1e9 + 7;
int n, k;
int d;
int m;
int Q;
int target;
// int p = INF;
// __int128_t a = 1;

// rope<int> r;
tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> treap;
int primes[N];
bool st[N];
int phi[N];
int cnt;
int T = 0;
LL s[N];

void init(int n)
{
    for (int i = 2; i <= n; i++)
    {
        if (!st[i])
        {
            st[i] = true;
            phi[i] = i - 1;
            primes[cnt++] = i;
        }
        for (int j = 0; primes[j] <= n / i; j++)
        {
            st[i * primes[j]] = true;
            if (i % primes[j])
            {
                phi[i * primes[j]] = phi[i] * phi[primes[j]];
            }
            else
            {
                phi[i * primes[j]] = phi[i] * primes[j];
                break;
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        s[i] = s[i - 1] + phi[i];
    }
}

void solve()
{
    double a, b;
    scanf("%lf %lf", &a, &b);
    printf("%.9lf\n", a / b);
}

signed main()
{
    int t = 1;
    // str = "codeforces";
    // init();
    // cout << cnt << endl;
    // init();
    // scanf("%d", &t);
    // getchar();
    // int a = 1;
    // for (int i = 1; i <= 26; i++)
    // {
    //     a = (a << 1) + 1;
    // }
    // cout << a << endl;
    // float t = 134217727;
    // int cnt = 200;
    // printf("%.16lf", t);
    // while (cnt--)
    // {
    //     t = t * 2 + a;
    //     printf("%.16f\n", t);
    // }
    // getchar();
    // cout << (int)(log(4) / log(2)) << endl;
    while (t--)
    {
        //     cout << t << endl;
        //     // cout << (2563 % 11) << endl;
        //     // cout << t << endl;
        solve();
        //     // cout << (((float)1) << 63) << endl;
        //     // cout << '\0' << endl;
        //     // cout << f(4);
        //     // cout<<(25 >> 5)
        //     // cout << gcd(31415, 14142);//
        //     // cout << (28284 / 11) << endl;
    }
    return 0;
}

/*
 *                                                     __----~~~~~~~~~~~------___
 *                                    .  .   ~~//====......          __--~ ~~
 *                    -.            \_|//     |||\\  ~~~~~~::::... /~
 *                 ___-==_       _-~o~  \/    |||  \\            _/~~-
 *         __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
 *     _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
 *   .~       .~       |   \\ -_    /  /-   /   ||      \   /
 *  /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
 *  |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
 *           '         ~-|      /|    |-~\~~       __--~~
 *                       |-~~-_/ |    |   ~\_   _-~            /\
 *                            /  \     \__   \/~                \__
 *                        _--~ _/ | .-~~____--~-/                  ~~==.
 *                       ((->/~   '.|||' -_|    ~~-/ ,              . _||
 *                                  -_     ~\      ~~---l__i__i__i--~~_/
 *                                  _-~-__   ~)  \--______________--~~
 *                                //.-~~~-~_--~- |-------~~~~~~~~
 *                                       //.-~~~--\
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 *                               神兽保佑            永无BUG
 */

/**
 *  ┏┓   ┏┓+ +
 * ┏┛┻━━━┛┻┓ + +
 * ┃       ┃
 * ┃   ━   ┃ ++ + + +
 *  ████━████+
 *  ◥██◤ ◥██◤ +
 * ┃   ┻   ┃
 * ┃       ┃ + +
 * ┗━┓   ┏━┛
 *   ┃   ┃ + + + +Code is far away from  
 *   ┃   ┃ + bug with the animal protecting
 *   ┃    ┗━━━┓ 神兽保佑,代码无bug 
 *   ┃        ┣┓
 *    ┃        ┏┛
 *     ┗┓┓┏━┳┓┏┛ + + + +
 *    ┃┫┫ ┃┫┫
 *    ┗┻┛ ┗┻┛+ + + +
 */
View Code

C.话剧

#include<bits/stdc++.h>
using namespace std;

double x,y,z;

signed main()
{
    cin>>x>>y>>z;
    printf("%.6lf",z/(x*y));
}
View Code

D.点集扩张

#include<bits/stdc++.h>
using namespace std;

const int N=110,M=410;
bool st[M][M];
int n,x,y;

signed main()
{
    cin>>n;
    
    int x1=-0x3f3f3f3f,x2=0x3f3f3f3f,y1=-0x3f3f3f3f,y2=0x3f3f3f3f;
    for(int i=1;i<=n;i++)
    {
        cin>>x>>y;
        st[x+N][y+N]=true;
        x1=max(x1,x),x2=min(x2,x),y1=max(y1,y),y2=min(y2,y);
    }
    
    if(x2<=0&&x1>=0&&y2<=0&&0<=y1)
    {
        bool flag=true;
        for(int i=x2+N;i<=x1+N;i++)
            for(int j=y2+N;j<=y1+N;j++)
                if(!st[i][j]) flag=false;
        
        if(flag) cout<<x1-x2+y1-y2;
        else cout<<-1; 
    }else cout<<-1;
}
View Code

E.全错

#include<bits/stdc++.h>
using namespace std;

#define x first
#define y second

typedef pair<double,int> PDI;
const double esp=1e-6;
const int N=210;
bool dist[N][N];
int t,n;
string s;
double b;

int cmp(double a,double b)
{
    if(fabs(a-b)<esp) return 0;
    else if(a<b) return -1;
    return 1;
}

double init()
{
    double a;
    if(s[0]=='+') sscanf(s.c_str(),"+%lf",&a);
    else if(s[0]=='-') sscanf(s.c_str(),"-%lf",&a),a=-a;
    else sscanf(s.c_str(),"%lf",&a);
    
    return a;
}

signed main()
{
    cin>>t;
    while(t--)
    {
        cin>>n>>s;
        b=init();
        
        memset(dist,false,sizeof dist);
        
        PDI p[n];
        for(int i=1;i<=n;i++)
        {
            int idx=0;
            for(int j=1;j<=n;j++)
            {
                cin>>s;
                if(i==j) continue;
                double a=init();
                p[idx++]={a,j};
            }
            sort(p,p+idx,greater<PDI>());
            if(cmp(p[0].x,b)>=0) dist[i][p[0].y]=true;
        }
        if(n==1)
        {
            cout<<"kono jinsei, imi ga nai!"<<endl;
            continue;
        }
        for(int k=1;k<=n;k++)
            for(int i=1;i<=n;i++)
                for(int j=1;j<=n;j++)
                {
                    dist[i][j]=dist[i][j];
                    if(dist[i][k]&&dist[k][j]) dist[i][j]=true;     
                }
        bool flag=true;
        for(int i=1;i<=n;i++)
            if(!dist[i][i]) flag=false;
        
        if(flag) cout<<"wish you the best in your search"<<endl;
        else cout<<"hbxql"<<endl;        
    }
}
View Code

F.渡渡鸟游乐场

#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
#define fi first
#define se second
#define lc u << 1
#define rc u << 1 | 1
// #define int long long

// #define double long long
// #define int __int128_t
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e7 + 10;

// const int R = 999997;
const int Base = N / 2;
const int M = 1e6 + 10;

// const int P = 1 << 10;
const int INF = 2147483647;

typedef unsigned long long ULL;

const double eps = 1e-4;
const double PI = acos(-1);
const int mod = 1e9 + 7;
int n, k;
int d;
int m;
int Q;
int target;
// int p = INF;
// __int128_t a = 1;

// rope<int> r;
tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> treap;
char s[1010];

void solve()
{
    scanf("%d", &n);
    m = 3 * n - 3;
    vector<vector<bool>> v(n + 1, vector<bool>(4));
    for (int i = 1; i <= m; i++)
    {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        v[a][b] = true;
        bool f = false;
        if (b == 2)
        {
            if (v[a][1] || v[a][3])
            {
                if (i & 1)
                {
                    printf("Nocriz");
                    break;
                }
                else
                {
                    printf("Sheauhaw");
                    break;
                }
            }
        }
        else
        {
            if (v[a][2])
            {
                if (i & 1)
                {
                    printf("Nocriz");
                    break;
                }
                else
                {
                    printf("Sheauhaw");
                    break;
                }
            }
        }
    }
}

signed main()
{
    int t = 1;
    // str = "codeforces";
    // init();
    // cout << cnt << endl;
    // init();
    // scanf("%d", &t);
    // getchar();
    // int a = 1;
    // for (int i = 1; i <= 26; i++)
    // {
    //     a = (a << 1) + 1;
    // }
    // cout << a << endl;
    // float t = 134217727;
    // int cnt = 200;
    // printf("%.16lf", t);
    // while (cnt--)
    // {
    //     t = t * 2 + a;
    //     printf("%.16f\n", t);
    // }
    // getchar();
    // cout << (int)(log(4) / log(2)) << endl;
    while (t--)
    {
        //     cout << t << endl;
        //     // cout << (2563 % 11) << endl;
        //     // cout << t << endl;
        solve();
        //     // cout << (((float)1) << 63) << endl;
        //     // cout << '\0' << endl;
        //     // cout << f(4);
        //     // cout<<(25 >> 5)
        //     // cout << gcd(31415, 14142);//
        //     // cout << (28284 / 11) << endl;
    }
    return 0;
}

/*
 *                                                     __----~~~~~~~~~~~------___
 *                                    .  .   ~~//====......          __--~ ~~
 *                    -.            \_|//     |||\\  ~~~~~~::::... /~
 *                 ___-==_       _-~o~  \/    |||  \\            _/~~-
 *         __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
 *     _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
 *   .~       .~       |   \\ -_    /  /-   /   ||      \   /
 *  /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
 *  |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
 *           '         ~-|      /|    |-~\~~       __--~~
 *                       |-~~-_/ |    |   ~\_   _-~            /\
 *                            /  \     \__   \/~                \__
 *                        _--~ _/ | .-~~____--~-/                  ~~==.
 *                       ((->/~   '.|||' -_|    ~~-/ ,              . _||
 *                                  -_     ~\      ~~---l__i__i__i--~~_/
 *                                  _-~-__   ~)  \--______________--~~
 *                                //.-~~~-~_--~- |-------~~~~~~~~
 *                                       //.-~~~--\
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 *                               神兽保佑            永无BUG
 */

/**
 *  ┏┓   ┏┓+ +
 * ┏┛┻━━━┛┻┓ + +
 * ┃       ┃
 * ┃   ━   ┃ ++ + + +
 *  ████━████+
 *  ◥██◤ ◥██◤ +
 * ┃   ┻   ┃
 * ┃       ┃ + +
 * ┗━┓   ┏━┛
 *   ┃   ┃ + + + +Code is far away from  
 *   ┃   ┃ + bug with the animal protecting
 *   ┃    ┗━━━┓ 神兽保佑,代码无bug 
 *   ┃        ┣┓
 *    ┃        ┏┛
 *     ┗┓┓┏━┳┓┏┛ + + + +
 *    ┃┫┫ ┃┫┫
 *    ┗┻┛ ┗┻┛+ + + +
 */
View Code

G.和而不同

#include<bits/stdc++.h>
using namespace std;
#define rg register
#define maxn 201005
#define mod 998244353
#define pi 3.141592653
#define P 131
#define inf 1e9
#define int long long
inline int read()
{
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-') f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        x=(x<<3)+(x<<1)+c-48;
        c=getchar();
    }
    return x*f;
}    
int dis[1200][1200],n;
map<int,int>vis;
signed main()
{
    n=read();
    int temp=1;
    for(rg int i=1;i<n;++i)
    {
        int now=i;
        int nxt=i+1;
        for(rg int j=now;j>=1;--j)
        {
            while(vis[temp+dis[j][now]]==1) 
            {
                ++temp; 
                j=now+1;
            }
        }
        dis[now][nxt]=dis[nxt][now]=temp;
        vis[temp]=1;
        for(rg int j=now;j>=1;--j)
        {
            dis[j][nxt]=dis[nxt][j]=dis[j][now]+dis[now][nxt];
            vis[dis[j][nxt]]=1;
        }
    }
    cout<<n-1<<endl;
    for(rg int i=1;i<n;++i)
    {
        cout<<i<<" "<<i+1<<" "<<dis[i][i+1]<<endl;
    }
}
View Code

H.字符游戏

#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
#define fi first
#define se second
#define lc u << 1
#define rc u << 1 | 1
// #define int long long

// #define double long long
// #define int __int128_t
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e7 + 10;

// const int R = 999997;
const int Base = N / 2;
const int M = 1e6 + 10;

// const int P = 1 << 10;
const int INF = 2147483647;

typedef unsigned long long ULL;

const double eps = 1e-4;
const double PI = acos(-1);
const int mod = 1e9 + 7;
int n, k;
int d;
int m;
int Q;
int target;
// int p = INF;
// __int128_t a = 1;

// rope<int> r;
tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> treap;
char s[1010];

void solve()
{
    scanf("%d", &n);
    vector<vector<int>> cnt(n + 1, vector<int>(27));
    for (int i = 1; i <= n; i++)
    {
        scanf("%s", s + 1);
        int len = strlen(s + 1);
        for (int j = 1; j <= len; j++)
        {
            cnt[i][s[j] - 'a']++;
        }
    }
    int ans = -1;
    for (int i = 0; i < 26; i++)
    {
        bool flag = true;
        unordered_map<int, bool> mp;
        for (int j = 1; j <= n; j++)
        {
            if (!mp.count(cnt[j][i]))
            {
                mp[cnt[j][i]] = true;
            }
            else
            {
                flag = false;
                break;
            }
        }
        if (flag)
        {
            ans = i;
            break;
        }
    }
    // cout << ans << endl;
    if (ans == -1)
    {
        puts("NO");
    }
    else
    {
        puts("YES");
        string str = "";
        for (int i = 0; i < 26; i++)
        {
            if (i != ans)
            {
                str += i + 'a';
            }
        }
        str += ans + 'a';
        cout << str << endl;
    }
}

signed main()
{
    int t = 1;
    // str = "codeforces";
    // init();
    // cout << cnt << endl;
    // init();
    // scanf("%d", &t);
    // getchar();
    // int a = 1;
    // for (int i = 1; i <= 26; i++)
    // {
    //     a = (a << 1) + 1;
    // }
    // cout << a << endl;
    // float t = 134217727;
    // int cnt = 200;
    // printf("%.16lf", t);
    // while (cnt--)
    // {
    //     t = t * 2 + a;
    //     printf("%.16f\n", t);
    // }
    // getchar();
    // cout << (int)(log(4) / log(2)) << endl;
    while (t--)
    {
        //     cout << t << endl;
        //     // cout << (2563 % 11) << endl;
        //     // cout << t << endl;
        solve();
        //     // cout << (((float)1) << 63) << endl;
        //     // cout << '\0' << endl;
        //     // cout << f(4);
        //     // cout<<(25 >> 5)
        //     // cout << gcd(31415, 14142);//
        //     // cout << (28284 / 11) << endl;
    }
    return 0;
}

/*
 *                                                     __----~~~~~~~~~~~------___
 *                                    .  .   ~~//====......          __--~ ~~
 *                    -.            \_|//     |||\\  ~~~~~~::::... /~
 *                 ___-==_       _-~o~  \/    |||  \\            _/~~-
 *         __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
 *     _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
 *   .~       .~       |   \\ -_    /  /-   /   ||      \   /
 *  /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
 *  |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
 *           '         ~-|      /|    |-~\~~       __--~~
 *                       |-~~-_/ |    |   ~\_   _-~            /\
 *                            /  \     \__   \/~                \__
 *                        _--~ _/ | .-~~____--~-/                  ~~==.
 *                       ((->/~   '.|||' -_|    ~~-/ ,              . _||
 *                                  -_     ~\      ~~---l__i__i__i--~~_/
 *                                  _-~-__   ~)  \--______________--~~
 *                                //.-~~~-~_--~- |-------~~~~~~~~
 *                                       //.-~~~--\
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 *                               神兽保佑            永无BUG
 */

/**
 *  ┏┓   ┏┓+ +
 * ┏┛┻━━━┛┻┓ + +
 * ┃       ┃
 * ┃   ━   ┃ ++ + + +
 *  ████━████+
 *  ◥██◤ ◥██◤ +
 * ┃   ┻   ┃
 * ┃       ┃ + +
 * ┗━┓   ┏━┛
 *   ┃   ┃ + + + +Code is far away from  
 *   ┃   ┃ + bug with the animal protecting
 *   ┃    ┗━━━┓ 神兽保佑,代码无bug 
 *   ┃        ┣┓
 *    ┃        ┏┛
 *     ┗┓┓┏━┳┓┏┛ + + + +
 *    ┃┫┫ ┃┫┫
 *    ┗┻┛ ┗┻┛+ + + +
 */
View Code

M.斑马子树

#include<bits/stdc++.h>
using namespace std;
#define rg register
#define maxn 201005
#define mod 998244353
#define pi 3.141592653
#define P 131
#define inf 1e9
inline int read()
{
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-') f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        x=(x<<3)+(x<<1)+c-48;
        c=getchar();
    }
    return x*f;
}    
int n;
struct node
{
    int v,nxt;
}s[maxn];
int head[maxn],tot;
inline void add(int x,int y)
{
    s[++tot].v=y;
    s[tot].nxt=head[x];
    head[x]=tot;
} 
int ce[maxn],t[maxn],ans[maxn];
inline pair<int,int> dfs(int now)
{
    int l=t[now],r=t[now];
    for(rg int i=head[now];i;i=s[i].nxt)
    {
        auto nxt=dfs(s[i].v);
        l=min(l,nxt.first);
        r=max(r,nxt.second);
    }
    ans[l]++;
    ans[r]--;
    return make_pair(l,r);
}
int S[maxn];
int main()
{
    n=read();
    for(rg int i=1;i<n;++i) add(read(),i+1);
    for(rg int i=1;i<=n;++i) 
    {
        ce[i]=read();
        t[ce[i]]=i;
    }
    dfs(1);
    for(rg int i=1;i<=n;++i)
    {
        S[i]=S[i-1]+ans[i];
        printf("%d ",S[i]);
    }
}
View Code

N.栈列

#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
#define fi first
#define se second
#define lc u << 1
#define rc u << 1 | 1
// #define int long long

// #define double long long
// #define int __int128_t
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e7 + 10;

// const int R = 999997;
const int Base = N / 2;
const int M = 1e6 + 10;

// const int P = 1 << 10;
const int INF = 2147483647;

typedef unsigned long long ULL;

const double eps = 1e-4;
const double PI = acos(-1);
const int mod = 1e9 + 7;
int n, k;
int d;
int m;
int Q;
int target;
// int p = INF;
// __int128_t a = 1;

// rope<int> r;
tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> treap;
char s[1010];

void solve()
{
    scanf("%d %d", &n, &m);
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    vector<int> v(n + 1);
    int mc = 0;
    int pos = 0;
    unordered_map<int, int> cnt;
    int num = 1;
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &v[i]);
        if (i > 1 && v[i] <= v[i - 1])
        {
            num++;
            pos = v[i];
        }
        cnt[v[i]]++;
        if (cnt[v[i]] > mc)
        {
            mc = cnt[v[i]];
            pos = v[i];
        }
        else if (cnt[v[i]] == mc && v[i] > pos)
        {
            pos = v[i];
        }
        else if (v[i] > pos)
        {
            pos = v[i];
        }
    }
    // cout << pos << endl;
    // cout << pos << endl;
    LL res = (LL)m * num - (m - pos - 1);
    // cout << res << endl;
    LL ans = (LL)a * res;
    // cout << ans << endl;
    ans += (LL)b * (res - n);
    for (int i = 2; i <= n; i++)
    {
        if (v[i] == 0)
        {
            if (v[i - 1] != m - 1)
            {
                ans += c;
                break;
            }
        }
        else
        {
            if (v[i - 1] != v[i] - 1)
            {
                ans += c;
                break;
            }
        }
    }

    printf("%lld\n", ans);
}

signed main()
{
    int t = 1;
    // str = "codeforces";
    // init();
    // cout << cnt << endl;
    // init();
    // scanf("%d", &t);
    // getchar();
    // int a = 1;
    // for (int i = 1; i <= 26; i++)
    // {
    //     a = (a << 1) + 1;
    // }
    // cout << a << endl;
    // float t = 134217727;
    // int cnt = 200;
    // printf("%.16lf", t);
    // while (cnt--)
    // {
    //     t = t * 2 + a;
    //     printf("%.16f\n", t);
    // }
    // getchar();
    // cout << (int)(log(4) / log(2)) << endl;
    while (t--)
    {
        //     cout << t << endl;
        //     // cout << (2563 % 11) << endl;
        //     // cout << t << endl;
        solve();
        //     // cout << (((float)1) << 63) << endl;
        //     // cout << '\0' << endl;
        //     // cout << f(4);
        //     // cout<<(25 >> 5)
        //     // cout << gcd(31415, 14142);//
        //     // cout << (28284 / 11) << endl;
    }
    return 0;
}

/*
 *                                                     __----~~~~~~~~~~~------___
 *                                    .  .   ~~//====......          __--~ ~~
 *                    -.            \_|//     |||\\  ~~~~~~::::... /~
 *                 ___-==_       _-~o~  \/    |||  \\            _/~~-
 *         __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
 *     _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
 *   .~       .~       |   \\ -_    /  /-   /   ||      \   /
 *  /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
 *  |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
 *           '         ~-|      /|    |-~\~~       __--~~
 *                       |-~~-_/ |    |   ~\_   _-~            /\
 *                            /  \     \__   \/~                \__
 *                        _--~ _/ | .-~~____--~-/                  ~~==.
 *                       ((->/~   '.|||' -_|    ~~-/ ,              . _||
 *                                  -_     ~\      ~~---l__i__i__i--~~_/
 *                                  _-~-__   ~)  \--______________--~~
 *                                //.-~~~-~_--~- |-------~~~~~~~~
 *                                       //.-~~~--\
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 *                               神兽保佑            永无BUG
 */

/**
 *  ┏┓   ┏┓+ +
 * ┏┛┻━━━┛┻┓ + +
 * ┃       ┃
 * ┃   ━   ┃ ++ + + +
 *  ████━████+
 *  ◥██◤ ◥██◤ +
 * ┃   ┻   ┃
 * ┃       ┃ + +
 * ┗━┓   ┏━┛
 *   ┃   ┃ + + + +Code is far away from  
 *   ┃   ┃ + bug with the animal protecting
 *   ┃    ┗━━━┓ 神兽保佑,代码无bug 
 *   ┃        ┣┓
 *    ┃        ┏┛
 *     ┗┓┓┏━┳┓┏┛ + + + +
 *    ┃┫┫ ┃┫┫
 *    ┗┻┛ ┗┻┛+ + + +
 */
View Code

O.打则

#include<bits/stdc++.h>
using namespace std;
#define rg register
#define maxn 4200000
#define inf 1e15
#define mod 19961
#define int long long
inline int read()
{
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-') f=-1;
        c=getchar();
    }
    while(c<='9'&&c>='0')
    {
        x=(x<<1)+(x<<3)+c-48;
        c=getchar(); 
    }
    return x*f;
}
int n,m,k,s;
bool vis[maxn];
int ans=1;
signed main()
{
    n=read();
    m=read();
    for(rg int i=1;i<=m;++i)
    {
        k=read();
        for(rg int j=1;j<=k;++j) s=read();
    }
    for(rg int i=1;i<=n;++i) ans=1*ans*i%mod;
    cout<<ans;
}
View Code

 

标签:__,const,Contest,int,University,Xian,using,include,define
From: https://www.cnblogs.com/sakuya726/p/17421106.html

相关文章

  • AtCoder Beginner Contest 302 Ex Ball Collector
    洛谷传送门AtCoder传送门考虑如果只询问一次怎么做。连边\((a_i,b_i)\),对于每个连通块分别考虑。这是ARC111B,如果一个连通块是树,肯定有一个点不能被选;否则有环,一定能构造一种方案,使得每个点都被选。那么现在对于每个点都要求,考虑dfs时合并当前的\((a_u,b_u)\),并且使用......
  • AtCoder Regular Contest 130 E Increasing Minimum
    这题太神仙了吧!感觉还不是很懂,但是尽力理一下思路。设\(t_x\)为最大的\(j\)使得\(i_j=x\),不存在则\(t_x=0\)。设\(1\simn\)的数按照\(t\)从小到大排序后是\(p_1,p_2,...,p_n\),设\(q_i\)为\(i\)在\(p\)中的排名,即\(q_{p_i}=i\)。发现正着不好考虑,......
  • AtCoder Beginner Contest 302
    A-Attack(abc302a)题目大意给定怪物的血量\(a\)和你每次攻击扣除的血量\(b\),问打多少次怪物才会死。解题思路答案即为\(\lceil\frac{a}{b}\rceil=\lfloor\frac{a+b-1}{b}\rfloor\)神奇的代码#include<bits/stdc++.h>usingnamespacestd;usingLL=long......
  • AtCoder Regular Contest 130 C Digit Sum Minimization
    洛谷传送门AtCoder传送门分类讨论,但是写起来挺答辩的。首先发现我们要使进位尽量多。特判怎么重排都没有进位的情况(\(a_i+b_i<10\))。然后枚举个位选的两个数字,并且要求它们和\(\ge10\)。如果当前位两个位都有数字,那么从小到大枚举数位的和\(\in[9,18]\);如果有数字......
  • 2023 Hubei Provincial Collegiate Programming Contest
    C.DarknessI首先根据短边放一条对角线,然后往后每隔一列只放一个即可。#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongint32_tmain(){ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);intn,m;cin>>n>>m......
  • 2023 CCPC Henan Provincial Collegiate Programming Contest
    A.小水獭游河南a的长度小于26,所以直接暴力枚举暴力判断。#include<bits/stdc++.h>usingnamespacestd;voidsolve(){strings;cin>>s;if(s.size()==1){cout<<"NaN\n";return;}map<char,int>cnt;......
  • AtCoder Regular Contest 133 E Cyclic Medians
    洛谷传送门AtCoder传送门其实是套路题,但是为什么做不出来啊第一步就是经典套路。枚举\(k\),统计中位数\(>k\)的方案数,加起来就是中位数的总和。那么现在\(x_{1\simn},y_{1\simm}\)就变成了\(0/1\)序列,考虑一次操作,如果\((x,y)=(0,0)\),那么\(a\)会变成\(0\)......
  • 微服务网关限流&鉴权-wei-fu-wu-wang-guan-xian-liu--jian-quan
    title:微服务网关限流&鉴权date:2022-01-0614:40:45.047updated:2022-01-0614:40:45.047url:https://www.yby6.com/archives/wei-fu-wu-wang-guan-xian-liu--jian-quancategories:tags:-微服务-鉴权掌握微服务网关Gateway的系统搭建掌握网关限流的实现能够......
  • AtCoder Regular Contest 124 F Chance Meeting
    洛谷传送门AtCoder传送门感觉挺高妙的……为了方便,不妨把横纵坐标都整体减\(1\)。如果单独考虑上下移动,方案数是\(\binom{2n}{n}\)。发现两个人上下总共移动\(n\)次后一定会在同一行,设这行编号为\(x\),那么最后带个\(\binom{n}{x}^2\)的系数,并且除掉上下移动后方案本质......
  • AtCoder Beginner Contest 212 F Greedy Takahashi
    洛谷传送门AtCoder传送门考虑每条边,因为是静态的,所以可以预处理出\(f_{i,j},g_{i,j}\)表示从第\(i\)条边,往后跳\(2^j\)条边,跳到边的编号和目前的时间(如果不存在就当作跳到第\(0\)条边)。直接倍增处理即可。询问就是找到从\(u\)开始的出边,能跳尽量跳。注意一些细节......