8.9总结

· · 闲话

T1 U594497 名称称

简单的一个题目,模拟就行了,但是我赛时少写了一个 h ,所以少了

\Huge \text{\color{red}10}

分(`Д´)

死亡方式 :h 离家出走

AC Code:

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=1e5+10;
char a;
int x,y;
char f[]={' ','a','b','c','d','e','f','g','h'};
int main(){
    ios::sync_with_stdio(0);
    for(int i=1;i<=8;i++){
        for(int j=1;j<=8;j++){
            cin>>a;
            if(a=='*'){
                x=i;
                y=j;
            }
        }
    }
    cout<<f[y]<<8-x+1;
    return 0;
}

T2 U594502 数列列

好吧我又把这题想成了双指针

死亡方式 :用了不对的双指针

这题不是二分吗啊啊啊

用 lower_bound 找第一个大于等于 a_i+k 的值,然后判断是否等于就行了。

Code:

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=2e5+10;
ll n,k,a[N],l,r;
int main(){
    ios::sync_with_stdio(0);
    cin>>n>>k;
    if(k==0){
        cout<<"Yes";
        return 0;
    }
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++){
        int l=lower_bound(a+1,a+n+1,a[i]+k)-a;
        if(a[l]==a[i]+k){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}

T3 U594511 二进制猜猜

我也不知道我的代码哪有错(雾

用贪心不行吗。。。

正解:

由于 ? 可以选是 1 还是 0 ,所以可以用选和不选的方法来做 。

暴力会超时,所以要优化。

可以发现,在 (x<<(len-u+1))>n 的情况下,不可能再符合要求了,所以可以直接退出。

So:

#include<bits/stdc++.h>
#define int long long
#define AK string
using namespace std;
AK s;
int n,len,ans=-1;
void dfs(int u,int x)
{
    if((x<<(len-u+1))>n)
    {
        return ;
    }
    if(u>len)
    {
        cout<<x;
        exit(0);
    }
    if(s[u]=='?')
    {
        dfs(u+1,x*2+1);
        dfs(u+1,x*2+0);
    }
    else
    {
        dfs(u+1,x*2+(s[u]-'0'));
    }
}
signed main()
{
    cin>>s>>n;
    len=s.size();
    s='@'+s;
    dfs(1,0);
    cout<<"-1";
    return 0;
}

T4 U594516 优惠券券

写了一半才发现我的贪心思路是错的。。。

思路:只要用了这张券,那么就一定能够实现它的最大价值,因为能用券的商品价格一定大于 L , 而且 D<=L 。

最后的结果一定是:总价格 - 优惠的金额 。

所以我们要求出最大的优惠的金额 。

最后,用优先队列优化一下就行了。

Code:

#include<bits/stdc++.h>
#define int long long
using namespace std;
struct node
{
    int l,d;
}s[200010];
int n,m,a[200010],ans=0;
bool cmp(node x,node y)
{
    if(x.l!=y.l)
    {
        return x.l<y.l;
    }
    return x.d>y.d;
}
signed main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=m;i++)
    {
        cin>>s[i].l;
    }
    for(int i=1;i<=m;i++)
    {
        cin>>s[i].d;
    }
    sort(a+1,a+n+1);
    sort(s+1,s+m+1,cmp);
    priority_queue<int> q;
    int t=1;
    for(int i=1;i<=n;i++)
    {
        while(t<=m && s[t].l<=a[i])
        {
            q.push(s[t].d);
            t++;
        }
        ans+=a[i];
        if(!q.empty())
        {
            ans-=q.top();
            q.pop();
        }
    }
    cout<<ans;
    return 0;
}
\Huge Bye\sim