返回顶部

数组模拟链表

双向链表的删除操作

 1 #include<bits/stdc++.h>
 2 #define mp make_pair
 3 #define pb push_back
 4 #define pw(x) (1ll << (x))
 5 #define sz(x) ((int)(x).size())
 6 #define all(x) (x).begin(),(x).end()
 7 #define rep(i,l,r) for(int i=(l);i<(r);i++)
 8 #define per(i,r,l) for(int i=(r);i>=(l);i--)
 9 #define FOR(i,l,r) for(int i=(l);i<=(r);i++)
10 #define eps 1e-9
11 #define PIE acos(-1)
12 #define cl(a,b) memset(a,b,sizeof(a))
13 #define fastio ios::sync_with_stdio(false);cin.tie(0);
14 #define lson l , mid , ls
15 #define rson mid + 1 , r , rs
16 #define ls (rt<<1)
17 #define rs (ls|1)
18 #define INF 0x3f3f3f3f
19 #define LINF 0x3f3f3f3f3f3f3f3f
20 #define lowbit(x) (x&(-x))
21 #define sqr(a) a*a
22 #define ll long long
23 #define ull unsigned long long
24 #define vi vector<int>
25 #define pii pair<int, int>
26 #define dd(x) cout << #x << " = " << (x) << ", "
27 #define de(x) cout << #x << " = " << (x) << "\n"
28 #define endl "\n"
29 using namespace std;
30 //**********************************
31 
32 //**********************************
33 const int maxn=5e3+7;
34 int le[maxn],ri[maxn],a[maxn];
35 inline void link(int l,int r)
36 {
37     ri[l]=r;le[r]=l;
38 }
39 //**********************************
40 int main()
41 {
42     int n,m,t,cnt,n1;
43     scanf("%d %d",&n,&m);n1=n;
44     cl(le,-1);cl(ri,-1);
45     FOR(i,1,n)scanf("%d",&a[i]),ri[i-1]=i,le[i]=i-1;
46     FOR(i,1,m){
47         scanf("%d",&t);
48         cnt=0;
49         for(int i=ri[0];~i&&cnt<=n;i=ri[i]){
50             cnt++;
51 //            de(cnt);
52             if(cnt%t==0)link(le[i],ri[i]),n1--;
53         }
54     }
55     printf("%d\n",n1);
56     cnt=0;
57     for(int i=ri[0];~i;i=ri[i])printf("%d%c",a[i],++cnt==n1?'\n':' ');
58     return 0;
59 }
View Code

 

posted @ 2018-09-17 20:38  牛奶加咖啡~  阅读(170)  评论(0编辑  收藏  举报