题目链接

按难度顺序

C.面积

题意:



题解:



AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//const int mod=1e9+7;
const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};


int main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int _;
    cin>>_;
    while(_--){
        double x;cin>>x;
        double ans=(2*(x/2)*(x/2)*3.14)+x*x;
        printf("%.2f\n",ans);
    }

    return 0;
}

E.赛马

题意:



题解:




AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//const int mod=1e9+7;
const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};

int a[maxn],b[maxn];

int main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int _;
    cin>>_;
    while(_--){
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)cin>>a[i];
        for(int i=1;i<=n;i++)cin>>b[i];
        sort(a+1,a+1+n);sort(b+1,b+1+n);
        int ans=0,x=1;
        for(int i=1;i<=n;i++){
            while(a[x]<=b[i]&&x<=n)x++;
            if(x==n+1) break;
            x++;ans++;    
        }
        cout<<ans<<endl;
    }

    return 0;
}

H.直线

题意:

题解:



AC代码

t=int(input())
for i in range(t):
    n=int(input())
    print(n*(n-1)//2)

B. 减成一

题意:


题解:





AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod=1e9+7;
//const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};

int a[maxn];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int _;
    cin>>_;
    while(_--){
        int n;cin>>n;
        for(int i=1;i<=n;i++)cin>>a[i];
        a[0]=1;
        int ans=0;
        for(int i=1;i<=n;i++)
            if(a[i]-a[i-1]>0)ans+=a[i]-a[i-1];
        cout<<ans<<endl;
    }
    return 0;
}

J.最大值

题意:



题解:






AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//const int mod=1e9+7;
const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};

string pa,str;
int nx[maxn],ans;
inline void GetNext()
{
    int i = 0, j = -1, len = pa.length();
    nx[i] = j;
    while(i < len){
        while( j != -1 && pa[i] != pa[j]) j = nx[j];
        nx[++i] = ++j;
    }
}
int Kmp()
{
    GetNext();
    int i =0, j = 0, lens=str.length(),lenp=pa.length();
    while(i < lens && j < lenp){
        while( j != -1 && str[i] != pa[j]) j = nx[j];
        i++, j++;
        ans=max(ans,j);
    }
    if(j == lenp) return i - lenp;///返回模式串在主串中首次出现的下标 +1是位置
    else return -1;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int _;
    cin>>_;
    while(_--){
        cin>>pa;ans=0;
        str=pa;str[0]='.';
        Kmp();cout<<ans<<endl;
    }

    return 0;
}

D.扔硬币

题意:


题解:













AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod=1e9+7;
//const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};


ll fact[maxn],inv1[maxn],a[maxn];
ll Pow(ll a, ll b){
    ll ans = 1;
    while(b > 0){
        if(b & 1){
            ans = ans * a % mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
//逆元
ll inv(ll b){
    return Pow(b,mod-2)%mod;
}



ll C(ll n,ll m){
    if(m>n||n<0||m<0)return 0;
    if(m==0||m==n) return 1;
    ll res=(fact[n]*inv1[m]%mod*inv1[n-m])%mod;
    return res;
}

void init() {
    fact[0] = 1;
    for (int i = 1; i < maxn; i++) {
        fact[i] = fact[i - 1] * i %mod;
    }
    inv1[maxn - 1] = Pow(fact[maxn - 1], mod - 2);
    for (int i = maxn - 2; i >= 0; i--) {
        inv1[i] = inv1[i + 1] * (i + 1) %mod;
    }
}




int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int _;
    cin>>_;
    a[0]=1;
    init();
    for(int i=1;i<=100000;i++)a[i]=a[i-1]*inv(2)%mod;
    while(_--){
        ll n,m,k;cin>>n>>m>>k;
        if(n-m<k)cout<<0<<endl;
        else{
            ll y=0;
            for(int i=0;i<m;i++)
                y=(y+C(n,i)*a[n])%mod;
            y=(mod+1-y)%mod;
            ll x=C(n,k)*a[n]%mod;
            cout<<x*inv(y)%mod<<endl;
        }
    }

    return 0;
}

A.点对最大值

题意:



题解:










AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod=1e9+7;
//const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};

vector<pii> g[maxn];
ll val[maxn],dp[maxn],ans;
void dfs(int u,int fa){
    dp[u]=2*val[u];
    for(auto i:g[u]){
        int v=i.fi,w=i.se;
        if(v==fa)continue;
        dfs(v,u);
        ans=max(ans,dp[u]-val[u]+dp[v]-val[v]+w);
        dp[u]=max(dp[u],val[u]+dp[v]-val[v]+w);
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int _;
    cin>>_;
    while(_--){
        int n;cin>>n;
        for(int i=1;i<=n;i++)g[i].clear();
        for(int i=2;i<=n;i++){
            int v,w;
            cin>>v>>w;
            g[i].pb(mp(v,w));
            g[v].pb(mp(i,w));
        }
        for(int i=1;i<=n;i++)cin>>val[i];
        ans=-8e18;
        dfs(1,0);
        cout<<ans<<endl;
    }
    return 0;
}

G.养花

题意:







题解:










AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod=1e9+7;
//const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};

//dinic
int n,m,s,t,N;
struct edge{
    int v,nx;
    int f;
}e[200010];
int head[maxn],cnt,cur[maxn],dep[maxn];
void init(){
    cnt=0;
    for(int i=0;i<=N;i++)
        head[i]=-1;
}
void add(int u,int v,int w){
    e[cnt]={v,head[u],w};
    head[u]=cnt++;
    e[cnt]={u,head[v],0};
    head[v]=cnt++;
}
bool bfs(){
    for(int i=0;i<=N;i++)cur[i]=head[i],dep[i]=0;
    queue<int> q;
    q.push(s);dep[s]=1;
    while(!q.empty()){
        int u=q.front();
        q.pop();
        for(int i=head[u];i!=-1;i=e[i].nx){
            int v=e[i].v;
            if(e[i].f&&!dep[v]){
                dep[v]=dep[u]+1;
                if(v==t)return 1;
                q.push(v);
            }
        }
    }
    return 0;
}
int dfs(int u,int lim){
    if(u==t)return lim;
    int ans=0,v,tmp;
    for(int i=cur[u];i!=-1;i=e[i].nx){
        cur[u]=i;
        v=e[i].v;
        if(dep[v]==dep[u]+1&&e[i].f){
            tmp=dfs(v,min(lim,e[i].f));
            e[i].f-=tmp;
            e[i^1].f+=tmp;
            ans+=tmp;
            lim-=tmp;
            if(!lim)break;
        }
    }
    if(!ans||lim)dep[u]=0;
    return ans;
}
int dinic(){
    int ans=0;
    while(bfs())ans+=dfs(s,inf);
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int _;
    cin>>_;
    while(_--){
        int n,m,k;
        cin>>n>>m>>k;
        s=0,N=k+2*m+1,t=k;
        init();
        for(int i=1,x;i<=n;i++){
            cin>>x;
            add(s,x,1);
        }
        for(int i=1;i<=m;i++){
            int op,c;
            cin>>op>>c;
            if(op==1){
                int a,b;
                cin>>a>>b;
                add(a,b,c);
            }
            if(op==2){
                int a1,a2,b;
                cin>>a1>>a2>>b;
                for(int j=a1;j<=a2;j++)
                    add(j,k+i,c);
                add(k+i,b,c);
            }
            if(op==3){
                int a,b1,b2;
                cin>>a>>b1>>b2;
                for(int j=b1;j<=b2;j++)
                    add(k+i,j,c);
                add(a,k+i,c);
            }
            if(op==4){
                int a1,a2,b1,b2;
                cin>>a1>>a2>>b1>>b2;
                for(int j=a1;j<=a2;j++)
                    add(j,k+i,c);
                add(k+i,k+i+m,c);
                for(int j=b1;j<=b2;j++)
                    add(k+i+m,j,c);
            }
        }
        cout<<dinic()<<endl;
    }
    return 0;
}

I.字典序

题意:




题解:













AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod=1e9+7;
//const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};

int l[maxn],r[maxn],a[maxn];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int _;
    cin>>_;
    while(_--){
        int n;cin>>n;
        for(int i=1;i<=n;i++)cin>>a[i];
        int cnt=0;
        for(int i=1;i<=n;i++){
            int j=i;
            while(a[j+1]==a[j]&&j+1<=n)j++;
            a[++cnt]=a[i],l[cnt]=i,r[cnt]=j;
            i=j;
        }
        a[cnt+1]=0;deque<int> q;
        for(int i=cnt;i;i--)
            if(a[i]>a[i+1])q.push_front(i);
            else q.pb(i);
        for(auto i:q)
            for(int j=l[i];j<=r[i];j++)
                cout<<j<<' ';
        cout<<endl;
    }
    return 0;
}