贪心1

B2. The Strict Teacher (Hard Version)
题目链接:https://codeforces.com/contest/2005/problem/B2
题解代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,m,q;
        cin>>n>>m>>q;
        vector<int> b(m);
        for(int i=0;i<m;i++){
            cin>>b[i];
        }
        sort(b.begin(),b.end());
        for(int i=0;i<q;i++){
            int p;
            cin>>p;
            int d=upper_bound(b.begin(),b.end(),p)-b.begin();
            if(d==0) cout<<b[0]-1<<' ';
			else if(d==m) cout<<n-b[m-1]<<' ';
            else cout<<(b[d]-b[d-1])/2<<' ';
        }   
        cout<<endl;
    }
    return 0;
}

P1223 排队接水
题目链接:https://www.luogu.com.cn/problem/P1223
题解代码:

#include<bits/stdc++.h>
using namespace std;
double sum=0;
long int n;
long long int t[1001];
double ans;
int main(int argc, const char * argv[])
{
    cin>>n;
    int x;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        t[i]=x*1001+i;
    }
    sort(t+1,t+1+n);
    for(int j=1;j<=n;j++)
    {
        cout<<t[j]%1001<<" ";
        sum+=t[j]/1001*(n-j);
    }
    cout<<endl;
    ans=sum/n;
    printf("%0.2lf",ans);
    return 0;
}
posted @ 2024-11-24 16:40  fufuaifufu  阅读(6)  评论(0编辑  收藏  举报