abc243補足レポート

D-二分木に移動します

この問題は直接シミュレーションであり、どちら側が入っていてどちら側が出ているかという両端キューを使用する必要があります。

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#define int long long
using namespace std;
const int N = 1e6+10;
const int mod = 1e9+7;
deque<int>st;
char a[N];
signed main()
{
    int n,x;cin>>n>>x;
//    getchar();
    scanf("%s",a+1);
    for(int i=1;i<=n;i++)
    {
        
        if(a[i]=='R')
            st.push_back(1);
        else if(a[i]=='L')
            st.push_back(0);
        else if(a[i]=='U'){
            if(!st.empty()){
                st.pop_back();
            }
            else{
                x /= 2;
            }
        }
    }
    while(!st.empty())
    {
        if(st.front()==0){
            x = 2*x;
        }
        else if(st.front()==1){
            x = 2*x+1;
        }
        st.pop_front();
    }
    cout<<x<<endl;
    return 0;
}

E-エッジの削除

フロイトがリラックスしたら、両端を操作し、取り外せる場合は取り除いてください。

配列サイズに注意してください!

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#define int long long
using namespace std;
const int M = 1e4+10;
const int N = 300+10;
const int mod = 1e9+7;


int n,m;
int a[N][N];
struct node{
    int x,y,val;
}edge[N*N];
signed main(){
    scanf("%lld%lld",&n,&m);
    memset(a,0x3f,sizeof(a));
//    for(int i=1;i<=n;i++) a[i][i]=0;
    for(int i=1;i<=m;i++){
        int x,y,c;
        scanf("%lld%lld%lld",&x,&y,&c);
        a[x][y] = c;
        a[y][x] = a[x][y];
        edge[i] = {x,y,a[x][y]};
    }
    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
            }
        }
    }
    int ans=0,tem=0;
//    int ans = 0;
    for(int i = 1; i <= m; i++){
        tem=0;
        for(int j = 1; j <= n; j++){
            if(a[edge[i].x][j] + a[j][edge[i].y] <= edge[i].val || a[edge[i].y][j] + a[j][edge[i].x] <= edge[i].val) tem = 1;
        }
        ans += tem;
    }
    cout<<ans<<endl;
    return 0;
}

おすすめ

転載: blog.csdn.net/weixin_60789461/article/details/123456525