蓝桥杯 H整数删除
尝试代码未果:希望有题感之后能按照这个思路AC
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<cmath>using namespace std;int n,k;
int a[10010];
int h[2],e[10010],ne[10010],idx;
int weizhi;
int preweizhi;void add(int aa){e[idx] = aa;ne[idx] = h[0];h[0] = idx ++;
}void delete1(int wei,int prewei){ne[prewei] = ne[wei];
}
int main()
{cin>>n>>k;h[0] = -1;int temp=0;for(int i=0;i<n;i++){cin>>a[i];temp++;}for(int j=temp-1;j>=0;j--){add(a[j]);}//怎样在链表里找最小值int t = h[0];cout<<t<<"***"<<e[t]<<endl;int minn = 10000000;while(k--){for(int i=h[0];i!=-1;i=ne[i]){int j=e[i];if(j<minn){minn = j;weizhi = i;}}cout<<weizhi<<"weizhi"<<endl; for(int i=h[0];i!=-1;i=ne[i]){if(i==weizhi){break;}preweizhi = i;}cout<<e[weizhi]<<"最小值"<<" "<<preweizhi<<"前面的"<<endl;e[preweizhi] += minn;e[ne[weizhi]] += minn;delete1(weizhi,preweizhi);}for(int i=h[0];i!=-1;i=ne[i]){cout<<e[i]<<' ';}return 0;
}