6.16-再次apple题-猜猜哪个教室

· · 个人记录

<<6.16-再次apple题-猜猜哪个教室>>总结

今日宣言:以AKmango题的实力,在int128爆0!!!

题目 预计得分 实际得分 考场算法 标准算法
签到题 100 70 打表判断 if and else
排序 100 100 栈 栈
要塞防御 50 0 cout<<0 优先队列
操作 60 0 dfs 贪心+堆
红黑树 0 50 dfs 挑战ing......

第一题:签到题

思路:

1.x<y
如果x和y同号->abs(y-x) 

如果x和y异号->abs(x+y)+1
2.x>y
如果x和y同号->abs(x-y)+2

如果x和y异号->abs(x+y)+1
3.x=y
直接输出0即可

代码:

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int x,y;
signed main()
{
//  freopen("T1.in","r",stdin);
//  freopen("T1.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>x;
    cin>>y;
    if(x==y)
    {
        cout<<0;
    }
    if(x<y)
    {
        cout<<min(abs(x+y)+1,abs(x-y));
    }
    if(x>y)
    {
        cout<<min(abs(x+y)+1,abs(x-y)+2);
    }
    return 0;
}

第二题:排序

思路:倒序输出更改数组,已输出则continue

代码:

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=1e5+25;
int n,m;
int a[N],b[N],c[N];
map<int,bool>mp;
bool vis[N];
stack<int>st;
signed main()
{
    // freopen("T2.in","r",stdin);
    // freopen("T2.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    for(int i=n;i>=1;i--)
    {
        st.push(i);
    }
    for(int i=1;i<=m;i++)
    {
        cin>>b[i];
        st.push(b[i]);
    }
    while(st.size())
    {
        int f=st.top();
        st.pop();
        if(mp[f]==0)
        {
            mp[f]=1;
            cout<<f<<endl;
        }
    }
    return 0;
}

第三题:要塞防御

思路:用优先队列来比较摆放价值,进而得到结果

代码:

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int n,s;
int sum;
struct node{
    int k,a; 
    bool operator<(const node &K) const{
        return k<K.k;
    }
};
priority_queue<node>q;
signed main()
{
//  freopen("T3.in","r",stdin);
//  freopen("T3.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>s;
    for(int i=1;i<=n;i++)
    {
        int a,k;
        cin>>a>>k;
        sum+=a;
        q.push({k,a});
    }
    while(s&&q.size())
    {

        int y=q.top().a; 
        int x=q.top().k;
        q.pop();
        if (y)
        {
            sum-=min(s,y/x)*x;
            s=max(s-y/x,0ll);
            q.push({y%x,0});
        }
        else
        {
            sum-=x;
            s--;
        }
    }
    cout<<sum;
    return 0;
}

第四题:操作

思路:逆向处理+差分处理+dp思想(这个我个人是这么认为的qwq)

代码:

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=5e5+25,mod=10007;
struct node{
int c;
int x,y;
}op[N];
int n,m,k,sum;
int a[N],dep[N];
int c1(int x,int y){
return ((x-y)%mod+mod)%mod;
}
int c2(int x,int y){
return (x+y)%mod;
}
signed main()
{
// freopen("T4.in","r",stdin);
// freopen("T4.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>k;
for(int i=1;i<=k;i++)
{
int x;
cin>>x;
dep[x]++;
dep[x-1]--;
}
for(int i=1;i<=m;i++)
{
cin>>op[i].c>>op[i].x>>op[i].y;
}
for(int i=m;i>=1;i--)
{
sum+=dep[i];
if(op[i].c==1)
{
a[op[i].x]=c2(a[op[i].x],op[i].y*sum);
}
else
{
dep[op[i].x-1]=c1(dep[op[i].x-1],sum);
dep[op[i].y]=c2(dep[op[i].y],sum);
}
}
for(int i=1;i<=n;i++)
{
cout<<a[i]<<" ";
}
return 0;
}

第五题:红黑树

未完待续...

挑战ing...

我似乎废了qwq