# Codeforces Round 857 (Div. 2) 感想

5 篇文章 0 订阅

## 感想

2/7，笑嘻了，D题忘了一个情况结果后面被卡了，排名直接翻一番，一看周围都是被卡了的哥们。1100的通过直接变600。
C题疑似找规律题，但我不是很懂原理，没写出来，场下照着样例编了一个过的，有个牛人写了个(i >> 32) + j也过了，完全不懂原理。

## A. Likes

### 3.代码：

ll t, m, n, p = 998244353;
ll mix[105];

int main() {
cin >> t;
while (t--) {
cin >> n;
int ma = 0;
for (int i = 1; i <= n; i++) {
cin >> mix[i];
if (mix[i] > 0) ma++;
}
int mi = n - ma, tmp = mi;
for (int i = 1; i <= n; i++) {
if (i > ma) ma--;
cout << (i > ma ? ma : i) << " ";
}
cout << "\n";
int la = 0;
for (int i = 1; i <= n; i++) {
if (i <= mi * 2) {
if (i % 2) cout << 1 << " ";
else cout << 0 << " ";
la = i % 2;
}
else {
la++;
cout << la << " ";
}
}
cout << "\n";
}
return 0;
}


## B. Settlement of Guinea Pigs

### 3.代码：

ll t, m, n, p = 998244353;
ll arr[100005];

int main() {
cin >> t;
while (t--) {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
int sum = 0, now = 0, res = 0;
int tot = 0;
for (int i = 1; i <= n; i++) {
if (arr[i] == 1) {
sum++;
now++;
tot++;
}
else {
if(tot % 2 == 0 && tot > 0) now = tot / 2 + tot % 2 + 1;
else now = tot / 2 + tot % 2;
}
res = max(res, now);
}
cout << res << "\n";
}
return 0;
}


## C. The Very Beautiful Blanket

### 3.代码：

ll t, m, n, p = 998244353;
ll mir[305][305];

int main() {
cin >> t;
while (t--) {
cin >> n >> m;
int now = 0;
for (int i = 1; i <= n; i += 2) {
now = 512 * (i / 2);
for (int j = 1; j * 2 <= m + 1; j++) {
mir[i][j * 2 - 1] = now++;
mir[i][j * 2] = now++;
mir[i + 1][j * 2 - 1] = now++;
mir[i + 1][j * 2] = now++;
}
}
cout << n * m << "\n";
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cout << mir[i][j] << " ";
}
cout << "\n";
}
}
return 0;
}


### 2.个人思路：

dp[i] = min(dp[i], abs(a[i] - max(max[i + 1], 1~i - 1中最接近a[i]的)))

dp[i] = min(dp[i], abs(a[i] - max[i + 1]))。

### 3.代码：

struct com {
ll f;
ll to;
bool operator < (const com& b) const {
return f < b.f;
}
}crr[500005];

ll t, m, n, p = 998244353;
ll dp[500005], mm[500005];
set<ll> useb;

int main() {
cin >> t;
while (t--) {
cin >> n;
ll ans = 2147483647ll;
useb.clear();
for (int i = 1; i <= n; i++) {
ll a, b;
cin >> a >> b;
crr[i] = { a, b };
}
mm[n + 1] = 0;
sort(crr + 1, crr + 1 + n);
for (int i = n; i > 0; i--) {
mm[i] = max(crr[i].to, mm[i + 1]);
}
useb.insert(crr[1].to);
ans = abs(crr[1].f - mm[2]);
for (int i = 2; i <= n; i++) {
dp[i] = 2147483647ll;
auto x = useb.lower_bound(crr[i].f);
if (x != useb.end()) {
if (mm[i + 1] >= *x) {
dp[i] = min(dp[i], abs(crr[i].f - mm[i + 1]));
}
else {
dp[i] = min(dp[i], abs(crr[i].f - *x));
}
}
if (x != useb.begin()) {
x--;
if (mm[i + 1] >= *x) {
dp[i] = min(dp[i], abs(crr[i].f - mm[i + 1]));
}
else {
dp[i] = min(dp[i], abs(crr[i].f - *x));
}
}
if(i != n)
dp[i] = min(dp[i], abs(crr[i].f - mm[i + 1]));
ans = min(ans, dp[i]);
useb.insert(crr[i].to);
}
cout << ans << "\n";
}
return 0;
}


## E. Music Festival

### 3.代码：

struct com {
ll f;
ll to;
ll s;
bool operator < (const com& b) const {
return f < b.f;
}
}lis[200005];

ll t, m, n, p = 998244353;
ll dp[200005];
map<ll, ll> lim;
vector<ll> alb[200005];
//ll tr[2000005], lz[2000005];

int main() {
cin >> t;
while (t--) {
cin >> n;
int ans = 0;
lim.clear();
for (int i = 1; i <= n; i++) {
alb[i].clear();
dp[i] = 0;
int k;
scanf_s("%d", &k);
int f = 0, l = 0;
for (int j = 0; j < k; j++) {
int a;
scanf_s("%d", &a);
if (a > f) {
f = a;
l++;
}
alb[i].push_back(a);
}
lis[i] = { f, l, i };
}
sort(lis + 1, lis + 1 + n);
int now = 0;
lim.insert({ 0, 0 });
for (int i = 1; i <= n; i++) {
int tmp = alb[lis[i].s].size(), x = lis[i].s;
int nm = 0, ns = 0;
for (int j = 0; j < tmp; j++) {
int y = alb[x][j];
if (y > nm) {
nm = y;
auto z = lim.lower_bound(y);
z--;
dp[i] = max(dp[i], z->second + lis[i].to - ns);
ns++;
}
}
dp[i] = max(dp[i], dp[i - 1]);
lim.insert({ lis[i].f, dp[i] });
}
cout << dp[n] << "\n";
}
return 0;
}


## 总结

• 2
点赞
• 0
收藏
觉得还不错? 一键收藏
• 6
评论
02-17 461
03-24 301
06-14 493
07-31 488
08-03 491
08-03 677
08-03 703
08-03 542

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。