SMU Summer 2024 Contest Round 1

反思:赛时死磕a题,c题写了十分钟,赛后5分钟就过了,打字速度太慢不敢换题换思路(其实换一个方向考虑,赛时看的题多,赛后也好补题)。补完之后感觉整体都还行,还是太菜了。下次一定要通览一遍,不能偷懒了

a.Dice and Coin - SMUOJ

思路:以为会TLE,写了二分做法节约时间,但是写错了,浪费了很多时间,其实直接模拟就好

代码:

#include<bits/stdc++.h>
using namespace std;
int n, k;  
double s;  
int main()
{
    cin >> n >> k;  
    
    for(int i = 1; i <= n; i++)
    {
        int t = i;  
        double w = 1;  
        while(t < k)
        {
            t *= 2;  
            w /= 2;  
        }
        
        s += (w / n);  
    }
    
    printf("%.12lf", s);  
    return 0;
}

b.equeue - SMUOJ

思路:数据不大,时间合适,是一个暴力枚举的题,但是听取wa声一片(主要是细节没有处理好)

代码:

#include<bits/stdc++.h>
#define int long long
using namespace std;
void solve(){
    int n,k;
    cin>>n>>k;
    int a[n+10];
    int sum=0;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<=min(n,k);i++){
        for(int j=0;i+j<=min(n,k);j++){


                for(int g=0;g<=k-i-j&&g<=(i+j);g++){
                    multiset<int>b;
                    for(int l=0;l<i;l++) b.insert(a[l]);
                    for(int r=n-j;r<n;r++) b.insert(a[r]);
                    for(int h=0;h<g;h++){
                        b.erase(b.begin());
                    }
                    auto it=b.begin();
                    int yy=0;
                    for(int p=0;p<b.size();p++){
                        yy+=*it;
                        it++;
                    }
                    sum=max(yy,sum);
                }
            }
    }
    cout<<sum<<endl;

}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
   //cin>>t;
    while(t--){
        solve();
    }
}

c.Sequence Decomposing - SMUOJ

思路:贪心+二分,这里用的二分函数

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1005;
#define PII pair<int,int>
void solve(){
    int n;
    cin>>n;
    multiset<int>q;
    for(int i=0;i<n;i++) {
        int k;
        cin>>k;
        if(q.size()==0){
            q.insert(k);
        }
        else{
            auto it=q.end();
            it--;
            if(q.lower_bound(k)!=q.end()){
                it=q.lower_bound(k);
                if(it==q.begin()){
                    q.insert(k);
                }
                else {
                    it--;
                    q.erase(it);
                    q.insert(k);
                }
            }
            else{
                q.erase(it);
                q.insert(k);
            }
        }
    }
    cout<<q.size()<<endl;

}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;

}

*d.Cell Distance - SMUOJ

思路:数学知识,x,y坐标对答案的贡献是独立的,可以拆开后,枚举横坐标的差值d,固定两个横坐标差值为d的两块,显然有(n−d)∗m 2个,那么这两块的贡献就是

( n − d ) ∗ m 2 ∗ d (n-d)*m^2*d(n−d)∗m 2∗d。纵坐标显然也是如此。然后就没有然后了。
 

*e.Friendships - SMUOJ

思路:怎么看,怎么感觉像离散数学。但是,这道题的构造十分巧妙(我认为),首先考率构造最短距离为2最多的点,然后通过增加边减少k,详细见代码,思维很重要,实现哼简单

代码如下:

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int,int>
const int maxm=1e5+5;
vector<PI>ans;
int n,k,m;
signed main(){
    ios::sync_with_stdio(0);
    cin>>n>>k;
    int m=(n-1)*(n-2)/2;
    if(k>m){
        cout<<-1<<endl;
        return 0;
    }
    for(int i=2;i<=n;i++){
        ans.push_back({1,i});
    }
    m-=k;
    for(int i=2;i<=n&&m;i++){
        for(int j=i+1;j<=n&&m;j++){
            ans.push_back({i,j});
            m--;
        }
    }
    cout<<ans.size()<<endl;
    for(auto i:ans){
        cout<<i.first<<' '<<i.second<<endl;
    }
    return 0;
}

f.Integer Cards - SMUOJ

思路:通过优先队列节省时间,正常思路,模拟即可。

代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1005;
#define PII pair<int,int>
priority_queue<int,vector<int>,greater<int> > q;
int n,k,i,j,x,top;
struct node
{
    int no,s;
}e[110000];
long long ans=0;
bool cmp(node x,node y)
{
    return x.s>y.s;
}
void solve() {
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        q.push(x);
    }
    for(i=1;i<=k;i++)
        cin>>e[i].no>>e[i].s;
    sort(e+1,e+1+k,cmp);
    for(i=1;i<=k;i++)
    {
        while(e[i].no>0)
        {
            if(q.top()>=e[i].s)
                break;
            q.pop();
            q.push(e[i].s);
            e[i].no--;
        }
    }
    for(i=1;i<=n;i++)
    {
        ans+=q.top();
        q.pop();
    }
    printf("%lld",ans);

}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值