跳到正文

个人记录

250723总结

wendywu约 15 分钟
原文
文章信息与版本

文章信息

发布
2025年7月23日
收录
2025年12月12日
更新
2026年11月11日
篇幅
约 15 分钟

版本

  1. v1当前

day3:二分(太好了,是我喜欢的算法:)
我太菜了,只会喜欢这种基础算法qwq
差H和J没写qwq

A - Non-square Equation

写了17分钟,WA 2发(A就写那么久,我心态崩了qwq
WA了2发是因为一开始写的二分,后面发现没有单调性就去看题解,然后写了个枚举,过了:)

B - Frodo and pillows

写了1h,WA 3发(B还写那么久,我心态炸了qwq
二分fld的枕头数量,然后就可以算出最少要几个枕头才能没人受伤,只要少于总枕头数就行,因为多的枕头可以分给最少的人。
WA 3发是写的时候忘了没人至少要有1个枕头qwq

C++
#include <bits/stdc++.h>
#define LL long long

using namespace std;

LL n, m, k;

bool check (LL x) {
	LL l = min(k - 1, x - 1), r = min(n - k, x - 1);
	l = max(l, 0ll); r = max(r, 0ll);
	LL tmp = l * (x - 1 + x - l) / 2 + x + r * (x - 1 + x - r) / 2;
	if (m - tmp >= k - l - 1 + n - k - r) return 1;
	return 0;
}

int main () {
	cin >> n >> m >> k;
	LL l = 0, r = m, ans = 0;
	while (l <= r) {
		LL mid = l + r >> 1;
		if (check(mid)) {
			ans = mid;
			l = mid + 1;
		} else {
			r = mid - 1;
		}
	}
	cout << ans;
	return 0;
}

C - Printer

写了25分钟,WA 1发(怎么还没有一遍过的题qwq
二分秒数,算能出几份,跟需要的份数比一下就好
WA 1发是因为炸long long了qwq

C++
#include <bits/stdc++.h>
#define LL long long

using namespace std;

LL t, n, k, ans;
struct qwq {
  LL t, l, w;
} a[110];

bool check (LL x) {
  LL ret = 0;
  for (int i = 1; i <= n; i++) {
    ret += x / (a[i].t * a[i].l + a[i].w) * a[i].l;
    if (ret >= k) return 1;
    LL tmp = x % (a[i].t * a[i].l + a[i].w);
    ret += min(tmp, a[i].t * a[i].l) / a[i].t;
    if (ret >= k) return 1;
  }
  return ret >= k;
}

int main () {
  for (cin >> t; t--;) {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
      cin >> a[i].t >> a[i].l >> a[i].w;
    }
    LL l = 0, r = 2e18;
    while (l <= r) {
      LL mid = l + r >> 1;
      if (check(mid)) {
        ans = mid;
        r = mid - 1;
      } else {
        l = mid + 1;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}

D - Save Energy!

写了1h,WA 1发(怎么还WA!
不难发现,它有一个>=k的第一个d的倍数这么大的周期,然后就可以根据二分时间算出已经搞完了多少分钟(开着的时候把1分钟视为2分钟),跟需要的时间比一下就可以了。:)
写了那么久还WA其实就是因为我太菜了不会用double qwq

C++
#include <bits/stdc++.h>
#define LL long long

using namespace std;

__int128 k, d, t;
LL ans;

bool check (__int128 x) {
  __int128 tmp = k / d;
  if (tmp * d < k) tmp++;
  tmp *= d;
  __int128 ret = x / 2 / tmp * (k * 2 + tmp - k);
  if (ret >= t) return 1;
  x %= (2 * tmp);
  ret += min(x, k * 2);
  if (ret >= t) return 1;
  x -= min(x, k * 2);
  ret += x / 2;
  return ret >= t;
}

int main () {
  LL k1, d1, t1;
  cin >> k1 >> d1 >> t1;
  k = k1; d = d1; t = t1;
  t *= 2;
  __int128 l = 0, r = t * 2;
  while (l <= r) {
    __int128 mid = l + r >> 1;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;  
    } else {
      l = mid + 1;
    }
  }
  cout << ans / 2 << (ans % 2 == 1 ? ".5" : ".0");
  return 0;
}

E - 阿斯特赖亚

写了33分钟,WA 1发(怎么一个一遍过的都没有,我心态炸没了啊qwq
二分强化次数,然后算出每种需要多少个币,看能不能转换成这么多。
WA:不开long long见祖宗。qwq

C++
#include <bits/stdc++.h>
#define LL long long

using namespace std;

LL n, k, a[100010], sum[100010];
struct qwq {
  LL t, c;
} b[100010];

bool check (int x) {
  fill(sum + 1, sum + k + 1, 0);
  for (int i = 1; i <= x; i++) {
    sum[b[i].t] += b[i].c;
  }
  LL tmp = 0;
  for (int i = 1; i <= k; i++) {
    if (sum[i] > a[i]) {
      tmp += a[i] - sum[i];
    } else {
      tmp += (a[i] - sum[i]) / 3;
    }
  }
  return tmp >= 0;
}

int main () {
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i].t >> b[i].c;
  }
  int l = 0, r = n, ans;
  while (l <= r) {
    int mid = l + r >> 1;
    if (check(mid)) {
      l = mid + 1;
      ans = mid;
    } else {
      r = mid - 1;
    }
  }
  cout << ans;
  return 0;
}

F - Project Management

写了2h,WA 1发(2h我还有救吗qwq,已经菜到一定程度了qwq
二分人数,然后按职级从小到大选人。对于每一个职级的人,按b从大到小选,如果这个职级的人里面b>=这个人的b的人数+这个人的b+之前已经选过的人>=二分的人数,就可以选这个职级的人里面b>=这个人的b的人。每个职级尽量多选人。最后看能不能选完。
WA 1发是因为以为每个职级只要有人不能选了b比ta小的就也都不能选了。wssb
写了2h主要是因为一直不知道怎么check(贪心太菜了qwq

C++
#include <bits/stdc++.h>
#define LL long long

using namespace std;

int t, n, a[200010], b[200010];
struct aa {
  int b, i;
};
vector <aa> v[200010];

bool check (int x) {
  for (int i = 1; i <= n; i++) {
    int tmp = -1;
    for (int j = 0; j < v[i].size(); j++) {
      if (v[i][j].b >= x - j + tmp) {
        for (int l = tmp + 1; l <= j; l++) {
          b[x--] = v[i][l].i;
          if (x == 0) {
            for (int k = 1; k <= n; k++) {
              a[k] = b[k];
            }
            return 1;
          }
        }
        tmp = j;
      }
    }
  }
  return 0;
}

bool cmp (aa x, aa y) {
  return x.b > y.b;
}

int main () {
  for (cin >> t; t--;) {
    cin >> n;
    for (int i = 1; i <= n; i++) {
      v[i].clear();
    }
    for (int i = 1, a, b; i <= n; i++) {
      cin >> a >> b;
      v[a].emplace_back((aa){b, i});
    }
    for (int i = 1; i <= n; i++) {
      sort(v[i].begin(), v[i].end(), cmp);
    }
    int l = 1, r = n, ans;
    while (l <= r) {
      int mid = l + r >> 1;
      if (check(mid)) {
        ans = mid;
        l = mid + 1;
      } else {
        r = mid - 1;
      }
    }
    cout << ans << "\n";
    for (int i = 1; i <= ans; i++) {
      cout << a[i] << ' ';
    }
    cout << "\n";
  }
  return 0;
}

G - 布置WAP

写了42分钟,没吃罚时(终于一遍过了啊啊啊qwq
没想到像老师那样这么神奇的二分qwq数学太菜了
写了一个奇奇怪怪的三分就过了:)
三分位置,然后算最远的距离:)
比屎山还屎山的code:

C++
#include <bits/stdc++.h>
#define LL long long

using namespace std;

const double qwq = 1e-8;
int t, n;
double aa, b, c;
struct shb {
  double x, y;
} a[100010];

double D (double x, double y, double xx, double yy) {
  return sqrt((x - xx) * (x - xx) + (y - yy) * (y - yy));
}

double check (double x) {
  double y, ret = 0;
  if (b == 0) {
    y = x;
    x = -c / aa;
  } else {
    y = (aa * x + c) / (-b);
  }
  for (int i = 1; i <= n; i++) {
    ret = max(ret, D(x, y, a[i].x, a[i].y));
  }
  return ret;
}

int main () {
  for (cin >> t; t--;) {
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i].x >> a[i].y;
    }
    cin >> aa >> b >> c;
    double l = -1e5, r = 1e5;
    while (r - l > qwq) {
      double mid = (l + r) / 2, rmid = mid + qwq, lmid = mid - qwq;
      double cl = check(lmid), cr = check(rmid), cm = check(mid);
      if (cl < cm) {
        r = mid;
      } else if (cr < cm) {
        l = mid;
      } else {
        l = mid;
        break;
      }
    }
    cout << fixed << setprecision(8) << check(l) << "\n";
  }
  return 0;
}

H - 王国------迁移

没时间写叻(我太菜叻(心态崩叻qwq

I - 龙之研习

写了1个多小时(?),没吃罚时:)
二分年份,减掉闰年数,然后用前缀和的思想减掉24年的:)
不是就这么一句话我写1个多小时……没救了
主要是题面一开始是错的,导致我对着题研究半个多小时没整明白,还以为是我的问题qwq (怎么就不是我的问题,还不是我太菜了)

C++
#include <bits/stdc++.h>
#define LL long long

using namespace std;

LL t, k;

LL get_sum (LL x) {
  LL sum = x / 4 - x / 100;
  sum += x / 400 - x / 10000;
  sum += x / 40000 - x / 1000000;
  sum += x / 4000000 - x / 100000000;
  sum += x / 400000000 - x / 10000000000;
  sum += x / 40000000000 - x / 1000000000000;
  sum += x / 4000000000000 - x / 100000000000000;
  sum += x / 400000000000000 - x / 10000000000000000;
  sum += x / 40000000000000000 - x / 1000000000000000000;
  return x - sum;
}

bool check (LL x) {
  return get_sum(x) - get_sum(2024) >= k;
}

int main () {
  for (cin >> t; t--;) {
    cin >> k;
    LL l = 2024, r = 2e18, ans;
    while (l <= r) {
      LL mid = l + r >> 1;
      if (check(mid)) {
        ans = mid;
        r = mid - 1;
      } else {
        l = mid + 1;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}

J - Matrix Game

没时间写了(我太菜叻(心态炸叻qwq
写完总结叻哈哈哈

原文