9.11
L_xiang365 · · 个人记录
一、比赛基本情况
比赛日期:9月11日
比赛时长:2小时15分钟
比赛得分:400分
比赛排名:第10名
二、比赛整体回顾
简要记录本场比赛的做题顺序、时间安排、比赛状态以及整体感受。
T1 -> T2 -> T3 -> T4 -> T5
T5的代码几乎全对了,但是要把:
hh[xx].second改成:id[xx]
就a了
三、题目复盘
T1:____Cards for Friends____
本题得分:100分
开始时间:2:10
结束时间:2:26
总用时:16分钟
初始思路
可以尝试直接模拟,复杂度
如果lowbit计算可以优化至
考场解题过程
模拟
考场代码
#include<bits/stdc++.h>
using namespace std;
int n, m, x;
int sl(int x, int y){
int ans = 1;
while(x % 2 == 0) x /= 2, ans *= 2;
while(y % 2 == 0) y /= 2, ans *= 2;
return ans;
}
void solve(){
cin >> n >> m >> x;
if(sl(n, m) >= x) cout << "YES";
else cout << "NO";
cout << "\n";
}
int main(){
int t = 1;
cin >> t;
while(t--) solve();
return 0;
}
复杂度
时间复杂度:
空间复杂度:
本题总结
无
T2:____Fair Division____
本题得分:100分
开始时间:2:26
结束时间:2:37
总用时:11分钟
初始思路
两个1=一个2
考场解题过程
数字无法拆分,但是可以分配,所以按照上面的模拟就可以了
考场代码
#include<bits/stdc++.h>
using namespace std;
int n;
void solve(){
cin >> n;
int ct[3] = {0, 0, 0};
for(int i = 1; i <= n; i++){
int x;
cin >> x;
ct[x]++;
}
ct[2] %= 2;
if(ct[2] == 1 && ct[1] >= 2) ct[2] = 0;
ct[1] %= 2;
if(ct[1] || ct[2]) cout << "NO";
else cout << "YES";
cout << "\n";
}
int main(){
int t = 1;
cin >> t;
while(t--) solve();
return 0;
}
复杂度
时间复杂度:O(n)
空间复杂度:O(n)
本题总结
无
T3:____Long Jumps____
本题得分:100
开始时间:2:37
结束时间:2:47
总用时:10分钟
初始思路
模拟不行,从后往前满足无后效性
考场解题过程
dp[i] = dp[min(n + 1, i + a[i])] + a[i];
n + 1避免越界,dp[n+1]=0, ok了
考场代码
#include<bits/stdc++.h>
using namespace std;
int n;
int const N = 2e5 + 5;
int dp[N];
void solve(){
cin >> n;
for(int i = 1; i <= n; i++){
cin >> dp[i];
}
for(int i = n; i >= 1; i--) dp[i] += dp[min(n + 1, i + dp[i])];
int ans = 0;
for(int i = 1; i <= n; i++) ans = max(ans, dp[i]);
for(int i = 1; i <= n; i++) dp[i] = 0;
cout << ans << "\n";
}
int main(){
int t = 1;
cin >> t;
while(t--) solve();
return 0;
}
复杂度
时间复杂度:
空间复杂度:
本题总结
T4:____Even-Odd Game____
本题得分:100
开始时间:2:47
结束时间:3:23
总用时:36分钟
初始思路
这题有2种可能,吃偶数最大,吃奇数最大
考场解题过程
我们发现,这样不是最好的,样例都过不了,于是向新思路
我们发现如果每次选最大值就是最好情况,可是为什么?
我们的每次都是一定是最大的,因为你要让对手拿不到最大的:两种情况
-
1,是可得分的,对手如果拿走了,你就会少得分,且那不浪费机会,且对手这局拿不到比你大的分数
-
2,是不可得分的,你不能让对手拿下他,不然对手就得分了,你选x,则对手优势-x+最大值,否则优势-最大值+y(y<最大值)一定是选最大值更好
考场代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n;
int const N = 2e5 + 5;
int a[N];
void solve(){
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
sort(a + 1, a + n + 1, greater<int>());
int ans[2] = {0, 0};
for(int i = 1; i <= n; i++){
if(a[i] % 2 == (i - 1) % 2) ans[(i - 1) % 2] += a[i];
}
if(ans[0] == ans[1]) cout << "Tie";
else if(ans[0] < ans[1]) cout << "Bob";
else cout << "Alice";
cout << "\n";
}
signed main(){
int t = 1;
cin >> t;
while(t--) solve();
return 0;
}
复杂度
时间复杂度:
空间复杂度:
T5:____Correct Placement____
本题得分:0
开始时间:3:23
结束时间:比赛结束
总用时:不知道
初始思路
两个太难求了,改一下
- h比h[i]小的最小的w (前缀最小值)
- h比w[i]小的最小的h (lower_bound二分)
考场解题过程
直接疯狂初始化就可以了
考场代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
int n;
int const N = 2e5 + 5;
int a[N], hid[N], pre[N], h[N], w[N], id[N], hhid[N];
pair<int, int> ww[N], hh[N];
void solve(){
cin >> n;
for(int i = 1; i <= n; i++){
cin >> h[i] >> w[i];
hh[i] = {h[i], i};
// ww[i] = {w[i], i};
}
sort(hh + 1, hh + n + 1);
for(int i = 1; i <= n; i++) a[i] = hh[i].f;
hh[0] = {0, 0};
for(int i = 1; i <= n; i++){
if(hh[i].f == hh[i - 1].f) hhid[hh[i].s] = hhid[hh[i - 1].s];
else hhid[hh[i].s] = i - 1;
}
for(int i = 1; i <= n; i++) hid[hh[i].s] = i;
pre[0] = 2e18;
for(int i = 1; i <= n; i++){
pre[i] = min(pre[i - 1], w[hh[i].s]);
if(pre[i] != pre[i - 1]) id[i] = hh[i].s;
else id[i] = id[i - 1];
}
for(int i = 1; i <= n; i++){
int x = pre[hhid[i]];
int xx = lower_bound(a + 1, a + n + 1, w[i]) - a - 1;
int y = pre[xx];
// cout << hid[i] << "\n";
if(x < w[i]){
cout << id[hhid[i]] << " ";
}else if(y < h[i]){
cout << hh[xx].s << " ";
}else{
cout << -1 << " ";
}
}
cout << "\n";
for(int i = 1; i <= n; i++) hid[i] = hhid[i] = id[i] = a[i] = 0;
}
signed main(){
int t = 1;
cin >> t;
while(t--) solve();
return 0;
}
赛后题解
其实思路是对的
只不过我太蒟蒻了,有一个细节错误
补题代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
int n;
int const N = 2e5 + 5;
int a[N], hid[N], pre[N], h[N], w[N], id[N], hhid[N];
pair<int, int> ww[N], hh[N];
void solve(){
cin >> n;
for(int i = 1; i <= n; i++){
cin >> h[i] >> w[i];
hh[i] = {h[i], i};
// ww[i] = {w[i], i};
}
sort(hh + 1, hh + n + 1);
for(int i = 1; i <= n; i++) a[i] = hh[i].f;
hh[0] = {0, 0};
for(int i = 1; i <= n; i++){
if(hh[i].f == hh[i - 1].f) hhid[hh[i].s] = hhid[hh[i - 1].s];
else hhid[hh[i].s] = i - 1;
}
for(int i = 1; i <= n; i++) hid[hh[i].s] = i;
pre[0] = 2e18;
for(int i = 1; i <= n; i++){
pre[i] = min(pre[i - 1], w[hh[i].s]);
if(pre[i] != pre[i - 1]) id[i] = hh[i].s;
else id[i] = id[i - 1];
}
for(int i = 1; i <= n; i++){
int x = pre[hhid[i]];
int xx = lower_bound(a + 1, a + n + 1, w[i]) - a - 1;
int y = pre[xx];
// cout << hid[i] << "\n";
if(x < w[i]){
cout << id[hhid[i]] << " ";
}else if(y < h[i]){
cout << id[xx] << " ";
}else{
cout << -1 << " ";
}
}
cout << "\n";
for(int i = 1; i <= n; i++) hid[i] = hhid[i] = id[i] = a[i] = 0;
}
signed main(){
int t = 1;
cin >> t;
while(t--) solve();
return 0;
}
复杂度
时间复杂度:
空间复杂度:
本题总结
要检查细节错误,不然空悲切
T6:____New Year's Puzzle____
本题得分:0
开始时间:无
结束时间:无
总用时:无
赛后题解
-
我们如果上下同色,竖着放
-
上下无色,不放
-
上有色,上横放
-
下有色,下横放
由于竖着放可以不威胁下一列,所有能竖着放就竖着放是对的。
我们发现可以O(n)贪心的方式求出答案,但是我们发现
可以直接把他离散化一下
因为全是竖着放的话没有影响,那不就可以压缩了吗。
补题代码
#include<bits/stdc++.h>
using namespace std;
int n, q;
map<int, int> mp;
void solve(){
mp.clear();
cin >> n >> q;
while(q--){
int x, y;
cin >> x >> y;
mp[y] += x;
}
int pd = 1, lst = -1;
for(auto t : mp){
int f = t.first, s = t.second;
if(lst == -1){
if(s != 3) lst = f + s;
}else{
if(s == 3 || (lst + f + s) % 2 == 0){
pd = 0;
break;
}
lst = -1;
}
}
if(lst != -1) pd = 0;
if(pd == 0) cout << "NO";
else cout << "YES";
cout << "\n";
}
int main(){
int t = 1;
cin >> t;
while(t--) solve();
}
复杂度
时间复杂度:
空间复杂度:
本题总结
T7:____Moving to the Capital____
本题得分:0
开始时间:无
结束时间:无
总用时:无
赛后题解
dis可以bfs求,后面直接做树形dp就可以了
补题代码
#include<bits/stdc++.h>
using namespace std;
int n, m;
int const N = 2e5 + 5;
int dis[N], vis[N], dp[N];
vector<int> G[N];
void bfs(int st){
queue<int> q;
q.push(st);
dis[st] = 0;
while(!q.empty()){
int u = q.front();
q.pop();
vis[u] = 1;
for(int v : G[u]){
if(vis[v]) continue;
vis[v] = 1;
dis[v] = dis[u] + 1;
q.push(v);
}
}
}
void dfs(int u){
if(vis[u]) return;
dp[u] = dis[u];
vis[u] = 1;
for(int v : G[u]){
if(dis[u] < dis[v]){
dfs(v);
dp[u] = min(dp[u], dp[v]);
}else{
dp[u] = min(dp[u], dis[v]);
}
}
}
void solve(){
cin >> n >> m;
for(int i = 1; i <= n; i++) vis[i] = 0, dis[i] = 1e18;
for(int i = 1; i <= n; i++) G[i].clear();
for(int i = 1; i <= m; i++){
int u, v;
cin >> u >> v;
G[u].push_back(v);
// G[v].push_back(u);
}
bfs(1);
for(int i = 1; i <= n; i++) vis[i] = 0;
dfs(1);
for(int i = 1; i <= n; i++) cout << dp[i] << " ";
cout << "\n";
}
signed main(){
int t = 1;
cin >> t;
while(t--) solve();
return 0;
}
复杂度
时间复杂度:
空间复杂度:
本题总结
四、整体反思
做得较好的地方
无
需要改进的地方
注意细节
时间安排总结
起码F和G留点时间思考,不能压在后面全压E题上