[关闭]
@2368860385 2018-07-02T00:33:17.000000Z 字数 2002 阅读 183

998——Codeforces Round #493 (Div. 2)

http://codeforces.com/contest/998

codeforces

2018.7.1参加(A,B,C)
2018.7.2整理


A:模拟
B:找到所有可以分割的点,从小的取。
C:两种情况讨论。

A

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. inline int read() {
  5. int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
  6. for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';return x*f;
  7. }
  8. int a[1000];
  9. int main () {
  10. int n = read(),sum = 0;
  11. for (int i=1; i<=n; ++i) {
  12. a[i] = read();sum += a[i];
  13. }
  14. if (n == 1) {
  15. return !printf("-1");
  16. }
  17. if (n==2) {
  18. if (a[1] == a[2]) printf("-1");
  19. else printf("1\n1");
  20. return 0;
  21. }
  22. for (int i=1; i<=n; ++i) {
  23. if (a[i] != sum-a[i]) {
  24. printf("1\n%d",i);return 0;
  25. }
  26. }
  27. return 0;
  28. }

B

  1. /*
  2. 10 3
  3. 4 1 2 3 4 5 4 4 5 5
  4. */
  5. #include<bits/stdc++.h>
  6. using namespace std;
  7. typedef long long LL;
  8. inline int read() {
  9. int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
  10. for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';return x*f;
  11. }
  12. int a[1010],f[1010];
  13. int main () {
  14. int n = read(),B = read();
  15. for (int i=1; i<=n; ++i) a[i] = read();
  16. int c1 = 0,c2 = 0;
  17. if (a[1] & 1) c1++;
  18. else c2++;
  19. int tot = 0;
  20. for (int i=2; i<n; ++i) {
  21. if (a[i] & 1) c1++;
  22. else c2++;
  23. if (c1 == c2) {
  24. f[++tot] = abs(a[i+1] - a[i]); // a[i+1]-a[i] 不是 a[i]-a[i-1]
  25. c1 = 0,c2 = 0;
  26. }
  27. }
  28. sort(f+1,f+tot+1);
  29. int cnt = 0,ans = 0;
  30. for (int i=1; i<=tot; ++i) {
  31. if (ans + f[i] <= B) ans += f[i],cnt ++;
  32. }
  33. cout << cnt;
  34. return 0;
  35. }

C

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. inline int read() {
  5. int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
  6. for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';return x*f;
  7. }
  8. char s[500000];
  9. int main () {
  10. int n = read(),x = read(),y = read();
  11. scanf("%s",s+1);
  12. int cnt = 0;
  13. LL ans1 = 0,ans2 = 0;
  14. cnt = 0;
  15. s[0] = '#';
  16. for (int i=1; i<=n; ++i) {
  17. if (s[i] == '0') {
  18. cnt ++;
  19. if (s[i] == s[i-1]) cnt--;
  20. }
  21. }
  22. if (cnt == 0) {cout << 0; return 0;}
  23. if (cnt == 1) {cout << y;return 0;}
  24. if (x < y) ans1 = 1ll * (cnt - 1) * x + y;
  25. else ans1 = 1ll * cnt * y;
  26. cout << ans1;
  27. return 0;
  28. /*if (x >= y) {
  29. cnt = 0;
  30. s[0] = '#';
  31. for (int i=1; i<=n; ++i) {
  32. if (s[i] == '0') {
  33. cnt ++;
  34. if (s[i] == s[i-1]) cnt--;
  35. }
  36. }
  37. ans1 = 1ll * cnt * y;
  38. cout << ans1;
  39. //return 0;
  40. }
  41. else {
  42. cnt = 0;
  43. s[0] = '#';
  44. for (int i=1; i<=n; ++i) {
  45. if (s[i] == '1') {
  46. cnt ++;
  47. if (s[i] == s[i-1]) cnt--;
  48. }
  49. }
  50. if (s[1] == '1') cnt--;
  51. if (s[n] == '1') cnt--;
  52. if (cnt < 0) {cout << 0;return 0;}
  53. ans2 = cnt * x + y;
  54. cout << ans2;
  55. }*/
  56. return 0;
  57. }
  58. /*
  59. 9 3 2
  60. 101010101
  61. */
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注