生活随笔
收集整理的這篇文章主要介紹了
Acwing第 24 场周赛【完结】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
打的很爛T2調試了好久,AK了,但是時間有點長,看來還得努力。
目錄
- 4070. 異或【簽到】
- 4071. 國際象棋【暴力枚舉】
- 4072. 習題冊【模擬 小根堆】
4070. 異或【簽到】
https://www.acwing.com/problem/content/4073/
#include<bits/stdc++.h>
using namespace std
;
const int N
=1e5*2+10;
int n
,m
,t
,a
[N
];
int main(void)
{cin
>>n
;int ans
=-1e9;for(int i
=0;i
<n
;i
++) cin
>>a
[i
],ans
=max(ans
,a
[i
]);int temp
=ans
^a
[n
-1];cout
<<temp
<<endl
;return 0;
}
4071. 國際象棋【暴力枚舉】
https://www.acwing.com/problem/content/4074/
#include<bits/stdc++.h>
using namespace std
;
int a
[15][15],x
,y
,xx
,yy
;
int dx
[8]={-2,-2,-1,-1,1,1,2,2};
int dy
[8]={-1,1,-2,2,-2,2,-1,1};
string s1
,s2
;
int get(char c
)
{if(c
<='9') return c
-'1';else return c
-'a';
}
void init()
{for(int i
=0;i
<8;i
++) a
[x
][i
]=1;for(int i
=0;i
<8;i
++) a
[i
][y
]=1;a
[x
][y
]=-1;a
[xx
][yy
]=-1;for(int i
=0;i
<8;i
++){int tempx
=xx
+dx
[i
];int tempy
=yy
+dy
[i
];if(tempx
<0||tempx
>=8) continue;if(tempy
<0||tempy
>=8) continue;a
[tempx
][tempy
]=1;}
}
bool check(int x
,int y
)
{if(a
[x
][y
]) return false;for(int i
=0;i
<8;i
++){int tempx
=x
+dx
[i
];int tempy
=y
+dy
[i
];if(tempx
<0||tempx
>=8) continue;if(tempy
<0||tempy
>=8) continue;if(a
[tempx
][tempy
]==-1) return false;}return true;
}
int main(void)
{cin
>>s1
>>s2
;y
=get(s1
[0]),x
=get(s1
[1]);yy
=get(s2
[0]),xx
=get(s2
[1]);init();int cnt
=0;for(int i
=0;i
<8;i
++)for(int j
=0;j
<8;j
++)if(check(i
,j
)) cnt
++;cout
<<cnt
<<endl
;return 0;
}
4072. 習題冊【模擬 小根堆】
https://www.acwing.com/problem/content/description/4075/
#include<bits/stdc++.h>
using namespace std
;
typedef pair
<int,int> PII
;
const int N
=1e5*2+10;
struct node{int p
,a
,b
;}temp
,s
[N
];
priority_queue
<PII
,vector
<PII
>,greater
<PII
> >heap
[5];
int n
,m
;
unordered_map
<int,int>mp
;
int main(void)
{cin
>>n
;for(int i
=0;i
<n
;i
++) scanf("%d",&s
[i
].p
);for(int i
=0;i
<n
;i
++) scanf("%d",&s
[i
].a
),heap
[s
[i
].a
].push({s
[i
].p
,i
});for(int i
=0;i
<n
;i
++) scanf("%d",&s
[i
].b
),heap
[s
[i
].b
].push({s
[i
].p
,i
});scanf("%d",&m
);for(int i
=0;i
<m
;i
++){int x
; scanf("%d",&x
);while(heap
[x
].size()){auto t
=heap
[x
].top();int u
=t
.second
;if(mp
[u
]) heap
[x
].pop();else break;}if(heap
[x
].size()) {auto t
=heap
[x
].top();int w
=t
.first
;int u
=t
.second
;printf("%d ",w
);mp
[u
]=1; heap
[x
].top();}else printf("-1 ");}return 0;
}
總結
以上是生活随笔為你收集整理的Acwing第 24 场周赛【完结】的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。