A:题意:你有一个1 * n的网格,有些地方是障碍。你有两个人,分别要从a到b和从c到d,一次只能向右跳1步或者两步。求是否可行。

解:先判断有没有2个连续的障碍,然后判断是否能错车。

  1. #include <bits/stdc++.h>
  2.  
  3. const int N = ;
  4.  
  5. char str[N];
  6.  
  7. int main() {
  8. int n, a, b, c, d;
  9. scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
  10. scanf("%s", str + );
  11. if(c < d) {
  12. for(int i = a; i < d; i++) {
  13. if(str[i] == '#' && str[i + ] == '#') {
  14. printf("No\n");
  15. return ;
  16. }
  17. }
  18. printf("Yes\n");
  19. return ;
  20. }
  21. else {
  22. for(int i = a; i < c; i++) {
  23. if(str[i] == '#' && str[i + ] == '#') {
  24. printf("No\n");
  25. return ;
  26. }
  27. }
  28. for(int i = b; i <= d; i++) {
  29. if(str[i - ] == '.' && str[i] == '.' && str[i + ] == '.') {
  30. printf("Yes\n");
  31. return ;
  32. }
  33. }
  34. printf("No\n");
  35. return ;
  36. }
  37. return ;
  38. }

AC代码

B:题意:你有一个ABC字符串,你能进行的操作就是把某个ABC变成BCA。求最多进行多少次操作。

解:发现可以把BC看做一个整体。单独的B和C看做障碍物。

那么对于每一段无障碍物的连续A,BC,求逆序对就好了。

  1. #include <bits/stdc++.h>
  2.  
  3. typedef long long LL;
  4. const int N = ;
  5.  
  6. char str[N];
  7. bool vis[N];
  8.  
  9. int main() {
  10.  
  11. scanf("%s", str + );
  12. int n = strlen(str + );
  13. for(int i = ; i <= n; i++) {
  14. if(str[i] == 'C' && str[i - ] != 'B') {
  15. vis[i] = ;
  16. }
  17. if(str[i] == 'B' && str[i + ] != 'C') {
  18. vis[i] = ;
  19. }
  20. }
  21. LL ans = ;
  22. for(int l = , r; l <= n; l = r + ) {
  23. while(vis[l]) {
  24. ++l;
  25. }
  26. if(l > n) break;
  27. r = l;
  28. while(!vis[r + ] && r < n) {
  29. ++r;
  30. }
  31. LL cnt = , t = ;
  32. for(int i = l; i <= r; i++) {
  33. if(str[i] == 'A') {
  34. ++cnt;
  35. }
  36. else if(str[i] == 'B' && str[i + ] == 'C') {
  37. ++i;
  38. t += cnt;
  39. }
  40. }
  41. ans += t;
  42. }
  43. printf("%lld\n", ans);
  44. return ;
  45. }

AC代码

C:题意:你有n场考试,满分X分。你的对手每场考试得了bi分。你每学习一个小时就能把某场考试提高1分。你能给每场考试选择一个li~ri之间的加权。求你最少花多少小时才能不比对手考的低。

解:发现加权要么是li要么是ri。且你比对手高就是ri,否则就是li。

然后发现如果有两场考试都没有满分,最优策略是把一场考试的分挪到另一场上。

然后就发现答案一定是若干场满分和一场非满分。这时候就可以排序了,然后二分答案,枚举非满分是哪一场。

  1. #include <bits/stdc++.h>
  2.  
  3. typedef long long LL;
  4. const int N = ;
  5.  
  6. struct Node {
  7. LL l, r, b, h;
  8. inline bool operator < (const Node &w) const {
  9. return h > w.h;
  10. }
  11. }node[N];
  12.  
  13. LL X, D, sum[N];
  14. int n;
  15.  
  16. inline LL cal(LL a, LL i) {
  17. if(a <= node[i].b) {
  18. return a * node[i].l;
  19. }
  20. return node[i].b * node[i].l + (a - node[i].b) * node[i].r;
  21. }
  22.  
  23. inline bool check(LL k) {
  24. LL ans = , r = k % X, t = k / X;
  25. if(t >= n) {
  26. return sum[n];
  27. }
  28. // printf("r = %lld t = %lld \n", r, t);
  29. for(int i = ; i <= n; i++) {
  30. if(i <= t) ans = std::max(ans, cal(r, i) + sum[t + ] - node[i].h);
  31. else {
  32. ans = std::max(ans, cal(r, i) + sum[t]);
  33. }
  34. }
  35. //printf("k = %lld ans = %lld D = %lld \n", k, ans, D);
  36. return ans >= D;
  37. }
  38.  
  39. int main() {
  40.  
  41. scanf("%d%lld", &n, &X);
  42. for(int i = ; i <= n; i++) {
  43. scanf("%lld%lld%lld", &node[i].b, &node[i].l, &node[i].r);
  44. node[i].h = node[i].b * node[i].l + (X - node[i].b) * node[i].r;
  45. D += node[i].b * node[i].l;
  46. }
  47. std::sort(node + , node + n + );
  48. for(int i = ; i <= n; i++) {
  49. sum[i] = sum[i - ] + node[i].h;
  50. }
  51. LL l = , r = 4e18;
  52. while(l < r) {
  53. LL mid = (l + r) >> ;
  54. if(check(mid)) {
  55. r = mid;
  56. }
  57. else {
  58. l = mid + ;
  59. }
  60. }
  61. printf("%lld\n", r);
  62. return ;
  63. }

AC代码

D:题意:给你平面上两组n个点,你要把它们配对,使得曼哈顿距离最大。n <= 1000。

解:曼哈顿距离有2个绝对值,拆开就是4种情况。直接建4个中转点表示这4种情况,跑最大费用最大流。

  1. #include <bits/stdc++.h>
  2.  
  3. #define int LL
  4.  
  5. typedef long long LL;
  6. const int N = , INF = 0x3f3f3f3f3f3f3f3fll;
  7.  
  8. struct Edge {
  9. int nex, v, c, len;
  10. Edge(){}
  11. Edge(int N, int V, int C, int L) {
  12. nex = N, v = V, c = C, len = L;
  13. }
  14. }edge[]; int tp = ;
  15.  
  16. int e[N], n, tot, d[N], pre[N], flow[N], Time, vis[N];
  17. std::queue<int> Q;
  18.  
  19. inline void add(int x, int y, int z, int w) {
  20. edge[++tp] = Edge(e[x], y, z, w);
  21. e[x] = tp;
  22. edge[++tp] = Edge(e[y], x, , -w);
  23. e[y] = tp;
  24. return;
  25. }
  26.  
  27. inline bool SPFA(int s, int t) {
  28. memset(d, 0x3f, sizeof(d));
  29. Q.push(s);
  30. ++Time;
  31. d[s] = ;
  32. vis[s] = Time;
  33. flow[s] = INF;
  34. while(Q.size()) {
  35. int x = Q.front();
  36. Q.pop();
  37. vis[x] = ;
  38. for(int i = e[x]; i; i = edge[i].nex) {
  39. int y = edge[i].v;
  40. if(edge[i].c && d[y] > d[x] + edge[i].len) {
  41. d[y] = d[x] + edge[i].len;
  42. pre[y] = i;
  43. flow[y] = std::min(flow[x], edge[i].c);
  44. if(vis[y] != Time) {
  45. vis[y] = Time;
  46. Q.push(y);
  47. }
  48. }
  49. }
  50. }
  51. return d[t] < INF;
  52. }
  53.  
  54. inline void update(int s, int t) {
  55. int f = flow[t];
  56. while(s != t) {
  57. int i = pre[t];
  58. edge[i].c -= f;
  59. edge[i ^ ].c += f;
  60. t = edge[i ^ ].v;
  61. }
  62. return;
  63. }
  64.  
  65. inline int solve(int s, int t, int &cost) {
  66. cost = ;
  67. int ans = ;
  68. while(SPFA(s, t)) {
  69. //printf("!");
  70. ans += flow[t];
  71. cost += flow[t] * d[t];
  72. update(s, t);
  73. }
  74. return ans;
  75. }
  76.  
  77. signed main() {
  78.  
  79. scanf("%lld", &n);
  80. int s = * n + , t = s + , x, y, z;
  81. for(int i = ; i <= n; i++) {
  82. scanf("%lld%lld%lld", &x, &y, &z);
  83. add(s, i, z, );
  84. add(i, * n + , z, x + y);
  85. add(i, * n + , z, y - x);
  86. add(i, * n + , z, x - y);
  87. add(i, * n + , z, -x - y);
  88. }
  89. for(int i = ; i <= n; i++) {
  90. scanf("%lld%lld%lld", &x, &y, &z);
  91. add(n + i, t, z, );
  92. add( * n + , n + i, z, -x - y);
  93. add( * n + , n + i, z, x - y);
  94. add( * n + , n + i, z, y - x);
  95. add( * n + , n + i, z, x + y);
  96. }
  97. //puts("OVER");
  98. int cost = ;
  99. solve(s, t, cost);
  100. printf("%lld\n", -cost);
  101. return ;
  102. }

AC代码

agc034的更多相关文章

  1. 【AtCoder】AGC034

    AGC034 刷了那么久AtCoder我发现自己还是只会ABCE(手动再见 A - Kenken Race 大意是一个横列,每个点可以跳一步或者跳两步,每个格子是空地或者石头,要求每一步不能走到石头或 ...

  2. AtCoder整理(持续更新中……)

    做了那么久的atcoder觉得自己的题解发的很乱 给有想和我一起交流atcoder题目(或者指出我做法的很菜)(或者指责我为什么整场比赛只会抄题解)的同学一个索引的机会??? 于是写了个爬虫爬了下 A ...

  3. 【长期计划】Atcoder题目泛做

    之前学长跟我说的是700-的应该都能自己做? 然后1000-的应该都能有一定的思路? 记不清了 但总之是要智力康复一下 又加上文化课比较紧 所以这个大概就会是长期计划了 ————————————分鸽线 ...

随机推荐

  1. java 选择结构if

    图1-1      if…else if…else语句的流程图 选择结构if语句与三元运算转换 三元运算符,它和if-else语句类似,语法如下: 判断条件 ? 表达式1 : 表达式2 三元运算符会得 ...

  2. Spring Boot 成长之路(一) 快速上手

    1.创建工程 利用IntelliJ IDEA新建一个Spring Boot项目的Web工程 2.查看初始化的spring boot项目 工程建好之后会出现如下的目录结构: 值得注意的第一件事是,整个项 ...

  3. tomcat下文件路径

    第一种:复制要访问的文件a.txt至tomcat安装路径下的webapps/ROOT文件夹下: 访问路径为:localhost:8080/a.txt 或者在webapps文件夹下新建一个文件夹(tes ...

  4. H5页面在手机上查看 使用手机浏览自己的web项目

    参考:http://www.browsersync.cn/#install 首先全局安装BrowserSync : npm install -g browser-sync 其次在项目文件夹下运行: b ...

  5. spring源码读书笔记

    如果我们在web项目里面使用spring的话,通常会在web.xml里面配置一个listener. <listener> <listener-class> org.spring ...

  6. day 73 Django基础八之cookie和session

      Django基础八之cookie和session   本节目录 一 会话跟踪 二 cookie 三 django中操作cookie 四 session 五 django中操作session 六 x ...

  7. Print Article /// 斜率优化DP oj26302

    题目大意: 经典题 数学分析 G(a,b)<sum[i]时 a优于b G(a,b)<G(b,c)<sum[i]时 b必不为最优 #include <bits/stdc++.h& ...

  8. WPF drag过程中显示ToolTip.

    原文:WPF drag过程中显示ToolTip. 在drag/drop过程中,我们在判断出over的元素上是否可以接受drag的东西之后,通常是通过鼠标的样式简单告诉用户这个元素不接受现在drag的内 ...

  9. java_IO流(输出流)

    ** * io流: * 输入流:硬盘输入到内存 字节/字符输入流 * 输出流:内存输出到硬盘 字节/字符输入流 * 字节流:一切数据都是字节存储(二进制) * 字节输出流(OutputStream): ...

  10. MATLAB 中自定义函数的使用

    MATLAB在文件内部(在函数内部)定义函数,但文件名以开头函数来命名,与Java中每个文件只能有一个公开类,但在文件内部还是可以定义其他非公开类一个道理. 无参函数 do.m function do ...