SDUT 2021 Spring Team Contest--- 20 (Gym 103107)题解

48 篇文章 0 订阅
34 篇文章 0 订阅

D - Doin’ Time

题目链接

答案

#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define x first
#define y second
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 1e6 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;

ll a[305];
ll dp[305][305];
ll mp[305][305];
ll m=1000003;

void solve(){
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++) cin>>a[i];
    for(ll i=1;i<=n;i++){
        dp[i][i-1]=1;
        for(ll j=i;j<=n;j++){
            dp[i][j]=(dp[i][j-1]*a[j])%m;
        }
    }
    for(ll r=1;r<=n;r++){
        for(ll l=r+1;l>=1;l--){
            for(ll k=l;k<r;k++){
                ll w=dp[l][k]-dp[k+1][r];
                w*=w;
                mp[l][r]=max(mp[l][r],mp[l][k]+mp[k+1][r]+w);
                //cout<<l<<" "<<r<<" "<<mp[l][r]<<endl;
            }
        }
    }
    cout<<mp[1][n]<<endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

F - Function

题目链接

答案

#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i) 
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define x first
#define y second
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 1e7 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;

//int euler[N];

ll quick_pow(ll a,ll i){
    if(!i) return 1;
    ll t=quick_pow(a,i>>1);
    t*=t;
    if(i&1) t*=a;
    return t;
}

// void geteuler(){
//     euler[1]=1;
//     for(int i=2;i<=1e7;i++){
//         if(!euler[i]){
//             for(int j=i;j<=1e7;j+=i){
//                 if(!euler[j]) euler[j]=j;
//                 euler[j]=euler[j]/i*(i-1);
//             }
//         }
//     }
// }

ll pla[N];
vector<ll>pri;

void judge(){
    for(int i=2;i<=1e7;i++){
        if(!pla[i]){
            pla[i]=i;
            pri.emplace_back(i);
            for(int j=i;j<=1e7;j+=i){
                if(!pla[j]) pla[j]=i;
            }
        }
    }
}

ll f(ll x){
    ll tot=0;
    ll res;
    ll pos;
    while(x>1){
        pos=pla[x];
        //cout<<pos<<endl;
        while(x&&!(x%pos)){
            tot++;
            x/=pos;
        }
        break;
    }
    tot/=2;
    res=x*quick_pow(pos,tot);
    return res;
}

void solve(){
    judge();
    ll n;
    cin>>n;
    ll res=0;
    for(int i=1;i<=n;i++) res+=f(i);//,cout<<f(i)<<endl;
    cout<<res<<endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

H - Hack DSU!

题目链接

答案

#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define x first
#define y second
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eb emplace_bakc
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;

void solve(){
    int n,t;
    cin>>n>>t;
    cout<<n<<" "<<1<<endl;
    for(int i=n-1;i>1;i--) cout<<i<<" "<<i-1<<endl;
    cout<<1<<" "<<n<<endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

J - JOJO’s Factory

题目链接

答案

#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define x first
#define y second
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 1e6 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;

int a[N],b[N];
int aa,bb;

void solve(){
    int n,m;
    cin>>n>>m;
    aa=bb=n;
    while(m--){
        int u,v;
        cin>>u>>v;
        a[u]++;
        b[v]++;
        if(a[u]>=n) aa--;
        if(b[v]>=n) bb--; 
    }
    cout<<min(aa,bb)<<endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

K - Keep Eating

题目链接

答案

#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define x first
#define y second
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;

void solve(){
    ll n,k;
    cin>>n>>k;
    ll sum=0;
    for(ll i=1;i<=n;i++){
        ll x;
        cin>>x;
        sum+=x;
    }
    if(sum<k) cout<<"0"<<endl;
    else cout<<sum-k+(k/2)<<endl;
    //cout<<sum-k<<" "<<k/2<<endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}
  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值