直播获奖

思路:
留意数据范围,每个人的成绩在之间,可以用树状数组当桶来存每个分数的数量,然后利用二分来找到第k名对应的分数,二分满足单调性,虽然不连续,但最后一次比需要的分数大的分数就是答案。

code:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+7;
inline ll read() {
    ll s = 0, w = 1;
    char ch = getchar();
    while (ch < 48 || ch > 57) {
        if (ch == '-') w = -1;
        ch = getchar();
    }
    while (ch >= 48 && ch <= 57)
        s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return s * w;
}
int Max(int a,int b){
    return a>=b?a:b;
}
int tree[600],ans[maxn],b;
#define lowbit(x)    ((x)&-(x))
void add(int x,int d) {
    while(x<=600) {
        tree[x]+=d;
        x+=lowbit(x);
    }
}
int sum(int x) {
    int sum=0;
    while(x) {
        sum+=tree[x];
        x-=lowbit(x);
    }
    return sum+b;
}
int findpos(int x) {
    int l=0,r=600;
    while(l<r) {
        int mid=(l+r)>>1;
        if(sum(mid)<x)    l=mid+1;
        else    r=mid;
    }
    return l;
}
int main() {
    int n=read(),w=read();
    for(int i=1,x,ran;i<=n;++i) {
        x=read(),ran=Max(1,i*w/100);
        if(x)
            add(x,1);
        else
            ++b;
        printf("%d ",findpos(i-ran+1));
    }
    return 0;
}

方格取数

思路:
dp,只能走往左、右、下走而且不能走后头路,也就是只能往右下,右上走,所以每次先往右走,然后从下往上走一遍,再从上往下走一遍取最大值。

code:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3+7,inf=0x3f3f3f3f;
inline ll read() {
    ll s = 0, w = 1;
    char ch = getchar();
    while (ch < 48 || ch > 57) {
        if (ch == '-') w = -1;
        ch = getchar();
    }
    while (ch >= 48 && ch <= 57)
        s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return s * w;
}
ll g[maxn][maxn],f[maxn][maxn],a[maxn][maxn];
int main() {
    int n=read(),m=read();
    for(int i=1;i<=n;++i)
    for(int j=1;j<=m;++j) {
        a[i][j]=read();
        g[i][j]=f[i][j]=-inf;
    }
    for(int j=1;j<=m;++j) {
        g[0][j]=f[0][j]=-inf;
        g[n+1][j]=-inf;
    }
    for(int i=1;i<=n;++i) {
        f[i][0]=-inf;
    }
    f[1][1]=a[1][1];
    for(int j=1;j<=m;++j) {
        for(int i=1;i<=n;++i)
            g[i][j]=f[i][j]=max(f[i][j],f[i][j-1]+a[i][j]);//left
        for(int i=1;i<=n;++i)
            f[i][j]=max(f[i][j],f[i-1][j]+a[i][j]);
        for(int i=n;i;--i)
            g[i][j]=max(g[i][j],g[i+1][j]+a[i][j]);
        for(int i=1;i<=n;++i)
            f[i][j]=max(f[i][j],g[i][j]);
    }
    printf("%lld\n",f[n][m]);
    return 0;
}