[关闭]
@ljt12138 2017-06-10T17:34:48.000000Z 字数 1535 阅读 817

Codeforces #418(Div 2)


C. An impassioned circulation of affection

预处理种询问,每次用双指针查找。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int MAXN = 1505;
  4. int n, q;
  5. char str[MAXN];
  6. int A[MAXN][26];
  7. int pos[MAXN], top = 0;
  8. void init()
  9. {
  10. for (int i = 1; i <= n; i++) {
  11. for (int j = 0; j < 26; j++) {
  12. top = 0;
  13. memset(pos, 0, sizeof pos);
  14. for (register int k = 1; k <= n; k++)
  15. if (str[k]-'a' == j)
  16. pos[k] = 1;
  17. int l = 1, len = 0, t = 0, ans = 0;
  18. for (register int k = 1; k <= n; k++) {
  19. len += 1-pos[k], t++;
  20. while (len > i) len -= 1-pos[l], t--, l++;
  21. ans = max(ans, t);
  22. }
  23. A[i][j] = ans;
  24. }
  25. }
  26. }
  27. int main()
  28. {
  29. scanf("%d", &n);
  30. scanf("%s", str+1);
  31. init();
  32. scanf("%d", &q);
  33. for (int i = 1; i <= q; i++) {
  34. int u; char c;
  35. scanf("%d %c", &u, &c);
  36. printf("%d\n", A[u][c-'a']);
  37. }
  38. return 0;
  39. }

D. An overnight dance in discotheque

大力贪心,不会证明。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int MAXN = 1005;
  4. const double eps = 1e-9;
  5. struct circ {
  6. int x, y, r;
  7. friend bool operator < (const circ &a, const circ &b)
  8. { return a.r > b.r; }
  9. } c[MAXN], A[MAXN], B[MAXN];
  10. int n;
  11. int ta = 0, tb = 0;
  12. int main()
  13. {
  14. scanf("%d", &n);
  15. for (int i = 1; i <= n; i++)
  16. scanf("%d%d%d", &c[i].x, &c[i].y, &c[i].r);
  17. sort(c+1, c+n+1);
  18. long long ans = 0;
  19. for (int i = 1; i <= n; i++) {
  20. int tmsa = 0, tmsb = 0;
  21. for (int j = 1; j <= ta; j++)
  22. if ((long long)(A[j].x-c[i].x)*(A[j].x-c[i].x)+(long long)(A[j].y-c[i].y)*(A[j].y-c[i].y) <= (long long)(A[j].r-c[i].r)*(A[j].r-c[i].r)) tmsa++;
  23. for (int j = 1; j <= tb; j++)
  24. if ((long long)(B[j].x-c[i].x)*(B[j].x-c[i].x)+(long long)(B[j].y-c[i].y)*(B[j].y-c[i].y) <= (long long)(B[j].r-c[i].r)*(B[j].r-c[i].r)) tmsb++;
  25. if ((tmsa&1)==0) A[++ta] = c[i], ans += (long long)c[i].r*c[i].r;
  26. else if ((tmsb&1)==0) B[++tb] = c[i], ans += (long long)c[i].r*c[i].r;
  27. else A[++ta] = c[i], ans -= (long long)c[i].r*c[i].r;
  28. }
  29. printf("%.10f\n", ans*M_PI);
  30. return 0;
  31. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注