2011 noip 提高组

时间:2023-11-10 19:29:26

首先吐槽:刚刚写着写着突然蓝屏了,,emmm,写到最后一题了蓝屏了、

当时我的内心是崩溃的。

然后,旁边的大佬默默来了一句:论保存草稿的重要性。

连着蓝了三次之后开了防火墙,然后,,我左边那位同学又开始蓝屏了。。

Day 1

T1  铺地毯

2011 noip 提高组

2011 noip 提高组

判断条件是

x >= a[i] &&x <= a[i] + g[i] && y >= b[i] && y <= b[i] + k[i]

#include <cstdio>
int n, a[], b[], g[], k[], t, x, y;
int main() {
scanf("%d", &n);
for(int i = ; i <= n; i++)
scanf("%d%d%d%d", &a[i], &b[i], &g[i], &k[i]);
scanf("%d%d", &x, &y);
for(int i = ; i <= n; i++)
if(x >= a[i] &&x <= a[i] + g[i] && y >= b[i] && y <= b[i] + k[i])
t = i;
t == 0 ? printf("-1") : printf("%d", t);
return ;
}

T2 选择客栈

2011 noip 提高组

2011 noip 提高组

把三重循环的暴力优化成一层。

#include <cstdio>
#include <iostream>
#define in inline
#define is isdigit
using namespace std;
in int read() {
int X = , w = ;
char ch = ;
while(!is(ch)) {
w |= ch == '-';
ch = getchar();
}
while(is(ch)) {
X = (X << ) + (X << ) + (ch ^ );
ch = getchar();
}
return w ? -X : X;
}
void print(int x) {
if(x < ) putchar('-'), x = -x;
if(x > ) print(x / );
putchar(x % + '');
}
int n, k, p, m, sum, num, ans, a[], b[], c[];
int main() {
n = read();
k = read();
p = read();
for(int i = ; i <= n; i++) {
num = read();
sum = read();
if(sum <= p) m = i;
if(m >= a[num]) c[num] = b[num];
a[num] = i;
ans += c[num];
b[num]++;
}
print(ans);
return ;
}

T3 Mayan游戏

2011 noip 提高组

2011 noip 提高组

2011 noip 提高组

2011 noip 提高组

大模拟搜索题,唔,,,我的代码会被hack,,虽然A了。

这里参照一位大佬的做法->https://www.luogu.org/blog/sumijie/solution-p1312

Day 2

T1 计算系数

2011 noip 提高组

大家都用杨辉三角但是我太弱了,,不会

于是,dp

#include <cstdio>
long long f[][] = {}, a, b, n, m, k;
int main() {
scanf("%lld%lld%lld%lld%lld", &a, &b, &k, &n, &m);
for(int i = ; i <= n; i++)
for(int j = ; j <= m; j++) {
if(i) f[i][j] = (f[i][j] + f[i - ][j] * a) % ;
if(j) f[i][j] = (f[i][j] + f[i][j - ] * b) % ;
}
printf("%lld", f[n][m]);
return ;
}

T2 聪明的质检员

2011 noip 提高组

2011 noip 提高组

非常经典的二分题目,出去学习老师们应该都会讲

#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int w[], v[], l[], r[], m, n, ll, rr = ;
long long sumw[], sumv[], s, ansn = 10000000000000000LL;
long long ok(int mid) {
long long ret = ;
for(int i = ; i <= n; ++i)
if(w[i] >= mid) sumw[i] = sumw[i - ] + , sumv[i] = sumv[i - ] + v[i];
else sumw[i] = sumw[i - ], sumv[i] = sumv[i - ];
for(int i = ; i <= m; ++i)
ret += (sumw[r[i]] - sumw[l[i] - ]) * (sumv[r[i]] - sumv[l[i] - ]);
return ret;
}
int main() {
scanf("%d%d%lld", &n, &m, &s);
for(int i = ; i <= n; ++i) scanf("%d%d", &w[i], &v[i]);
for(int i = ; i <= m; ++i) scanf("%d%d", &l[i], &r[i]);
while(ll < rr) {
int mid = (ll + rr) / + ;
long long tmp = ok(mid) - s;
ansn = min(ansn, abs(tmp));
if(tmp > ) ll = mid;
else if(tmp < ) rr = mid - ;
else {
ansn = ; break;
}
}
printf("%lld", ansn);
}

T3 观光公交

2011 noip 提高组

2011 noip 提高组

2011 noip 提高组

贪心的经典题目

#include <cstdio>
#include <iostream>
using namespace std;
#define MAXN 10100
int p, temp, ans, n, m, k, d[MAXN], t[MAXN], a[MAXN], b[MAXN], num[MAXN], vis[MAXN], dis[MAXN], sum[MAXN];
int main() {
scanf("%d%d%d", &n, &m, &k);
for(int i = ; i < n; i++)
scanf("%d", &d[i]);
for(int i = ; i <= m; i++)
scanf("%d%d%d", &t[i], &a[i], &b[i]);
for(int i = ; i <= m; i++)
num[b[i]]++, vis[a[i]] = max(vis[a[i]], t[i]);
for(int i = ; i <= n; i++)
dis[i] = max(dis[i - ], vis[i - ]) + d[i - ];
for(int i = ; i <= m; i++)
ans += dis[b[i]] - t[i];
while(k--) {
p = temp = -;
for(int i = n - ; i; i--) {
dis[i + ] <= vis[i + ] ? sum[i] = num[i + ] : sum[i] = sum[i + ] + num[i + ];
if(sum[i] > temp && d[i]) temp = sum[i], p = i;
}
if(p == -) break;
ans -= temp, d[p]--;
for(int i = p + ; i <= n; i++)
dis[i] = max(dis[i - ], vis[i - ]) + d[i - ];
}
printf("%d", ans);
return ;
}

一世安宁