2026/2/27上午 总结

· · 个人记录

P15413 [CCC 2019 J4/S1] Flipper 翻转

100分

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+50;
int n,ans,m;
string s;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='H')n++;
        else m++;
    }
    n%=2;
    m%=2;
    if(n&&m){
        cout<<"4 3\n2 1";
    }else if(n){
        cout<<"3 4\n1 2";
    }else if(m){
        cout<<"2 1\n4 3";
    }else{
        cout<<"1 2\n3 4";
    }
    return 0;
}

P13646 [NOISG 2016] LunchBox

100分

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+50;
int n,m,ans,a[N];
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>a[i];
    }
    sort(a+1,a+1+m);
    for(int i=1;i<=m;i++){
        if(a[i]<=n){
            n-=a[i];
            ans++;
        }
    }
    cout<<ans;
    return 0;
}

P15024 [UOI 2020 II Stage] 修理帕萨特

100分

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+50;
int n,ans=1e9;
struct E{
    int t,d;
}a[N];
int cmp(E x,E y){
    return x.d>y.d;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].t>>a[i].d;
    }
    sort(a+1,a+1+n,cmp);
    for(int i=1;i<=n;i++){
        ans=min(a[i].d,ans);
        ans-=a[i].t;
    }
    cout<<ans;
    return 0;
}

P6473 [NOI Online #2 入门组] 未了

85分

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+50;
int n,l,u,a[N],ans,t,q;
double c;
int cmp(int x,int y){
    return x>y;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n>>l>>u;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+1+n,cmp);
    cin>>q;
    while(q--){
        cin>>t;
        c=double(l)/u;
        ans=0;
        for(int i=1;i<=n;i++){
            if(c<=t){
                ans++;
                c+=double(a[i])/u;
            }else{
                break;
            }
        }
        if(c<=t)cout<<"-1\n";
        else cout<<ans<<"\n";
    }
    return 0;
}

100分

二分查找+前缀+反向思考由除改乘

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+50;
long long n,l,u,a[N],ans,t,q;
double c;
int cmp(int x,int y){
    return x>y;
}
int ch(long long k){
    long long s=l;
    s+=a[k];
    return s>t*u;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n>>l>>u;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+1+n,cmp);
    cin>>q;
    for(int i=2;i<=n;i++)a[i]+=a[i-1];
    while(q--){
        cin>>t;
        long long ll=-1,rr=n+1;
        while(ll+1<rr){
            long long mid=(ll+rr)/2;
            if(ch(mid))rr=mid;
            else ll=mid;
        }
        if(a[rr]+l>t*u)cout<<rr<<"\n";
        else cout<<"-1\n";
    }
    return 0;
}

P3611 [USACO17JAN] Cow Dance Show S

10分

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+50;
int n,t;
priority_queue<int,vector<int>,greater<int> >a;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n>>t;
    for(int i=1,x;i<=n;i++){
        cin>>x;
        a.push(x);
    }
    while(a.size()){
        int x=a.top();
        a.pop();
        int y=a.top();
        a.pop();
        if(x+y<=t){
            a.push(x+y);
        }else{
            a.push(x);
            a.push(y);
            break;
        }
    }
    cout<<a.size();
    return 0;
}

100分

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+50;
long long n,ans,t,a[N];
priority_queue<int,vector<int>,greater<int> >e;
int ch(int k){//可以小根堆,存储每个位置最后用完的时间,按顺序让奶牛每次选最快用完的位置,然后把这头奶牛的表演时间加上,重新入队 
    for(int i=1;i<=k;i++){
        e.push(a[i]);
    }
    for(int i=k+1;i<=n;i++){
        e.push(e.top()+a[i]);
        e.pop();
    }
    ans=0;
    while(e.size()){
        ans=e.top();
        e.pop();
    }
    return ans<=t;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n>>t;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    long long l=0,r=n+1;
    while(l+1<r){//二分查找 K 值
        long long mid=(l+r)/2;
        if(ch(mid))r=mid;
        else l=mid;
    }
    cout<<r;
    return 0;
}