- 一、比赛基本情况
- 二、比赛整体回顾
- T1
- T2
- T3
- T4
一、比赛基本情况
比赛日期:7月14号
比赛时长:3小时30分钟
比赛得分:45
比赛排名:22名
二、比赛整体回顾
做题顺序
T1 -> T2 -> T4 -> T3
时间安排
第1题: 1小时
第2题: 10 ~ 20 分钟
第3题: 40 分钟
第4题: 1小时10分钟
比赛状态
良好
整体感受
我比赛时有: 细节错误较多、思路不全面、且时间安排不合理等错误
三、题目复盘
T1:Bakery S
(又菜又爱玩)
开始时间:8:30
结束时间:9:27
总用时:57分钟
初始思路
发现总的钱数是具有单调性,所以可以二分。
考场解题过程
对于里面我们贪心的解题:
- 对x减少数量之后再对y减少数量
- 对y减少数量之后再对x减少数量
(我脑子抽抽了吗,这贪心看着不对其实真不对)
考场代码
#include<bits/stdc++.h>
using namespace std;
int t, n, x, y, asx, asy, ansx, ansy;
bool check(int stp, int a, int b, int c){
// cout << stp << " " << a << " " << b << " " << c << "\n";
bool pd;
if(x <= stp){
pd = ((a + (y - (stp - x + 1)) * b) <= c);
if(pd){
asx = 1;
asy = (y - stp + x - 1);
return 1;
}
}else{
pd = ((x - stp) * a + y * b <= c);
if(pd){
asx = (x - stp);
return 1;
}
}
swap(x, y);
swap(a, b);
if(x <= stp){
pd = ((a + (y - (stp - x + 1)) * b) <= c);
if(pd){
asx = 1;
asy = (y - stp + x - 1);
return 1;
}
}else{
pd = ((x - stp) * a + y * b <= c);
if(pd){
asx = (x - stp);
return 1;
}
}
return 0;
}
void slove(){
cin >> n >> x >> y;
ansx = x, ansy = y;
for(int i = 1; i <= n; i++){
asx = asy = 0;
int a, b, c;
cin >> a >> b >> c;
int l = 0, r = x + y - 2;
while(l <= r){
int mid = (l + r) >> 1;
if(check(mid, a, b, c)) r = mid - 1;
else l = mid + 1;
}
// cout<< asx << " " << asy << "\n";
ansx = min(ansx, asx), ansy = min(ansy, asy);
}
cout<< (x - ansx) + (y - ansy) << "\n";
}
int main(){
freopen("bakery.in", "r", stdin);
freopen("bakery.out", "w", stdout);
cin>> t;
while(t--)slove();
}赛后题解
对于题目如果我们知道以下几种条件则可以知道答案
我们发现具有单调性所以尝试
那么具有不等式:
设
展开后是
移项一下
让
分类讨论一下:
直接二分
补题代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
int t, n, ctc, mtm, ans;
int const N = 1e5 + 5;
int a[N], b[N], c[N];
bool check(int step){
int rf = min(ctc-1ll, step), lf = max(0ll, step - mtm + 1ll);
for(int i = 1; i <= n; i++){
int p = (b[i] - a[i]), q = c[i] - ctc * a[i] - mtm * b[i] + step * b[i];
if(p == 0 && q < 0)return 0;
if(p < 0) lf = max(lf, (int)ceil(1.0 * q / p));
if(p > 0) rf = min(rf, (int)floor(1.0 * q / p));
}
if(rf >= lf)ans = step;
return rf >= lf;
}
void slove(){
ans = 0;
cin >> n >> ctc >> mtm;
for(int i = 1; i <= n; i++)cin >> a[i] >> b[i] >> c[i];
int l = 0, r = ctc + mtm;
while(l <= r){
int mid = (l + r) >> 1;
if(check(mid)) r = mid - 1;
else l = mid + 1;
}
cout<< ans << "\n";
}
signed main(){
cin>> t;
while(t--)slove();
}复杂度
时间复杂度:
本题总结
可以把所有可能的情况,然后尝试,尝试之后再验证解法是否正确,如果有未知数的话就可以列出方程或不等式,然后把它进行移项等操作,之后找到规律
T2:Shell Game B
开始时间:9:30
结束时间:9:45
总用时:15分钟
初始思路
直接模拟
考场解题过程
直接模拟
考场代码
#include<bits/stdc++.h>
using namespace std;
int n, ans;
int const N = 2e5 + 5;
int a[N], b[N], c[N];
int main(){
freopen("shell.in", "r", stdin);
freopen("shell.out", "w", stdout);
cin>> n;
for(int i = 1; i <= n; i++){
cin >> a[i] >> b[i] >> c[i];
}
for(int i = 1; i <= 3; i++){
int w = i, sum = 0;
for(int j = 1; j <= n; j++){
if(a[i] == w){
w = b[i];
}else if(b[i] == w){
w = a[i];
}
if(c[i] == w){
sum++;
}
}
ans = max(ans, sum);
}
cout<< ans;
return 0;
}赛后题解
直接模拟
补题代码
#include<bits/stdc++.h>
using namespace std;
int n, ans;
int const N = 205;
int k[N];
string s[N][N];
int main(){
cin >> n;
for(int i = 1; i <= n; i++){
string bs;
cin>> bs >> k[i];
for(int j = 1; j <= k[i]; j++){
cin >> s[i][j];
}
}
for(int i = 1; i <= n; i++){
for(int j = i + 1; j <= n; j++){
int sum = 0;
for(int p = 1; p <= k[i]; p++){
int f=0;
for(int q = 1; q <= k[j]; q++){
if(s[i][p] == s[j][q]){
f=1;
break;
}
}
sum += f;
}
ans = max(ans, sum + 1);
}
}
cout << ans;
return 0;
}复杂度
时间复杂度:
本题总结
要注意细节问题
T3:Guess the Animal B
开始时间:9:45
结束时间:10:20
总用时:35分钟
初始思路
不会正解直接暴力dfs
考场解题过程
把每个动物的特点放在一个vector数组,然后搞一次去重,对这个vector数组做dfs
考场代码
#include<bits/stdc++.h>
using namespace std;
int n, ans;
int const N = 205 + 5;
int k[N];
string s[N][N];
bool vis[N];
map<string, int> mp;
map<string, vector<int>> m;
vector<string>v;
void dfs(int x, int sum){
if(x == v.size()){
ans = max(ans, sum);
return;
}
if(mp[v[x]]){
bool p[N] = {0}, nvis[N];
for(int vs : m[v[x]]){
p[vs] = 1;
}
for(int i = 1; i <= n; i++)nvis[i] = vis[i];
for(int i = 1; i <= n; i++){
if(!p[i])vis[i] = 1;
}
dfs(x + 1, sum + 1);
for(int i = 1; i <= n; i++)vis[i] = nvis[i];
}
dfs(x + 1, sum);
}
int main(){
cin >> n;
for(int i = 1; i <= n; i++){
string bs;
cin>> bs >> k[i];
for(int j = 1; j <= k[i]; j++){
cin >> s[i][j];
v.push_back(s[i][j]);
m[s[i][j]].push_back(i);
}
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
for(int i = 1; i <= n; i++){
mp.clear();
for(int j = 1; j <= k[i]; j++){
mp[s[i][j]] = 1;
}
dfs(0, 0);
}
cout << ans - 1;
return 0;
}赛后题解
如果你是是也包含了倒数第2个询问的动物
换句话说就是第i个去掉的动物所有是的是其实第i+1个到第n-1个去掉的动物一定也有,不然他早就被删了
所欲我们只要枚举最后2种动物的相同的数量就可以了
补题代码
#include<bits/stdc++.h>
using namespace std;
int n, ans;
int const N = 205;
int k[N];
string s[N][N];
int main(){
cin >> n;
for(int i = 1; i <= n; i++){
string bs;
cin>> bs >> k[i];
for(int j = 1; j <= k[i]; j++){
cin >> s[i][j];
}
}
for(int i = 1; i <= n; i++){
for(int j = i + 1; j <= n; j++){
int sum = 0;
for(int p = 1; p <= k[i]; p++){
int f=0;
for(int q = 1; q <= k[j]; q++){
if(s[i][p] == s[j][q]){
f=1;
break;
}
}
sum += f;
}
ans = max(ans, sum + 1);
}
}
cout << ans;
return 0;
}复杂度
时间复杂度:
本题总结
对一个问题可以尝试找到没有用的循环,然后优化掉
T4:Pogo-Cow S 加强版
开始时间:10:20
结束时间:11:26
总用时:1小时6分钟
初始思路
很明显是一道店dp题,由于他不停上升于是很快就联想到了最长上升子序列
考场解题过程
状态定义:
dp[i][0]=表示这个位置与之前做最长上升子序列的得分的最大值
dp[i][1]=表示这个位置与之前做最长上升子序列的最后一次移动的长度
dp[i][2]=表示这个位置与之前不上升子序列的得分的最大值
dp[i][3]=表示这个位置与之前不做最长上升子序列的最后一次移动的长度
状态转移方程:
if(dp[v[j]][1] < i - v[j] + 1){
if(dp[v[j]][0] + a[i] > dp[i][0]){
dp[i][0] = dp[v[j]][0] + a[i];
dp[i][1] = i - v[j] + 1;
}
}
if(dp[v[j]][3] < i - v[j] + 1){
if(dp[v[j]][2] + a[i] > dp[i][0]){
dp[i][0] = dp[v[j]][2] + a[i];
dp[i][1] = i - v[j] + 1;
}
}答案:
for(int i = 1; i <= n; i++)ans = max(ans, dp[i][0]);考场代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n, ans;
int const N = 1e6+5;
struct Node{
int x, p;
}s[N];
int dp[N][5], a[N], id[N], v[N];
bool cmp(Node x, Node y){
return x.x < y.x;
}
signed main(){
cin >> n;
for(int i = 1; i <= n; i++){
cin >> s[i].x >> s[i].p;
}
sort(s + 1, s + n + 1, cmp);
for(int i = 1; i <= n; i++){
a[s[i].x] = s[i].p;
id[s[i].x] = i;
v[i] = s[i].x;
}
for(int i = 1; i <= 1e6; i++){
if(!a[i])continue;
dp[i][0] = dp[i][2] = a[i];
dp[i][1] = dp[i][3] = 0;
for(int j = 1; j < id[i]; j++){
if(dp[v[j]][1] < i - v[j] + 1){
if(dp[v[j]][0] + a[i] > dp[i][0]){
dp[i][0] = dp[v[j]][0] + a[i];
dp[i][1] = i - v[j] + 1;
}
}
if(dp[v[j]][3] < i - v[j] + 1){
if(dp[v[j]][2] + a[i] > dp[i][0]){
dp[i][0] = dp[v[j]][2] + a[i];
dp[i][1] = i - v[j] + 1;
}
}
}
// cout<< dp[i][0] << "\n";
ans=max(ans,dp[i][0]);
}
cout<< ans;
return 0;
}赛后题解
50分
状态定义
dp[i][j] = 到了i,上一个是j
状态转移方程
if(a[j].x - a[k].x <= a[i].x - a[j].x){
dp[i][j] = max(dp[i][j], dp[j][k] + a[i].p);
}答案
max{dp[i][j]};
满分
因为50分是的复杂度,对于3000太大了,所以要优化掉一层循环
我们不难发现你如果k越小a[j].x - a[k].x越大,i越大a[i].x - a[j].x越大
然后我们还发现dp[i][j]初始化成dp[i - 1][j] - a[i - 1].p; 是可行的
所以做一遍双指针,就可以,不用第3层循环就可以了
补题代码
```#include<bits/stdc++.h>
using namespace std;
#define int long long
int n, ans;
int const N = 3e3+5;
struct Node{
int x, p;
}s[N];
int dp[N][N];
bool cmp(Node xx, Node yx){
return xx.x < yx.x;
}
signed main(){
cin >> n;
for(int i = 1; i <= n; i++){
cin >> s[i].x >> s[i].p;
}
sort(s + 1, s + n + 1, cmp);
for(int j = 1; j <= n; j++){
dp[j][j] = s[j].p;
ans = max(ans, dp[j][j]);
// cout<< dp[j][j] << " ";
for(int i = j + 1, nw = j; i <= n; i++){
dp[i][j] = dp[i - 1][j] - s[i - 1].p;
while(nw >= 1 && abs(s[j].x - s[nw].x) <= abs(s[i].x - s[j].x))
dp[i][j]=max(dp[i][j],dp[j][nw--]);
dp[i][j] += s[i].p;
// cout<< dp[i][j] << " ";
ans = max(ans, dp[i][j]);
}
// cout<< "\n";
}
memset(dp, 0, sizeof(dp));
for(int j = n; j >= 1; j--){
dp[j][j] = s[j].p;
ans = max(ans, dp[j][j]);
for(int i = j - 1, nw = j; i >= 1; i--){
dp[i][j] = dp[i + 1][j] - s[i + 1].p;
while(nw <= n && abs(s[j].x - s[nw].x) <= abs(s[i].x - s[j].x))
dp[i][j]=max(dp[i][j],dp[j][nw++]);
dp[i][j] += s[i].p;
ans = max(ans, dp[i][j]);
}
}
cout<< ans;
return 0;
}复杂度
时间复杂度:
本题总结
要找规律优化
四、整体反思
做得较好的地方
无
需要改进的地方
细节错误较多、思路不全面、且时间安排不合理
时间安排总结
做题顺序: 应该是 2 -> 3 -> (1,4)
第1题: 我时间用的太久,导致我后面的时间少了
第3题: 思考时间太短了,直接打的暴力写法
