因为当天的下午才看到所以没来得及请假所以这一场没有打。。。于是信息课就打了这场的模拟赛。

A题:

*题目描述:
火星上的一年有n天,问每年最少和最多有多少休息日(周六周天)。
*题解:
模7分类讨论一下。
*代码:

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. #include <cmath>
  5. #ifdef WIN32
  6. #define LL "%I64d"
  7. #else
  8. #define LL "%lld"
  9. #endif
  10. #ifdef CT
  11. #define debug(...) printf(__VA_ARGS__)
  12. #define setfile()
  13. #else
  14. #define debug(...)
  15. #define filename ""
  16. #define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout);
  17. #endif
  18. #define R register
  19. #define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
  20. #define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
  21. #define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
  22. #define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
  23. #define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
  24. char B[1 << 15], *S = B, *T = B;
  25. inline int FastIn()
  26. {
  27. R char ch; R int cnt = 0; R bool minus = 0;
  28. while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
  29. ch == '-' ? minus = 1 : cnt = ch - '0';
  30. while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
  31. return minus ? -cnt : cnt;
  32. }
  33. int main()
  34. {
  35. // setfile();
  36. R int n = FastIn();
  37. R int minn = n / 7 * 2, maxx = minn;
  38. R int tmp = n % 7;
  39. if (tmp && tmp <= 2 ) maxx += tmp;
  40. else if (tmp) maxx += 2;
  41. if (tmp >= 5) minn += tmp - 5;
  42. printf("%d %d\n",minn, maxx );
  43. return 0;
  44. }

B题:

*题目描述:
有n个机器人,每个机器人有一个特征码,而且每个机器人都可以看见它和排在它左边的机器人的特征码。把所有的机器人看见的特征码按顺序排成一排,求第k个特征码是多少?
*题解:
等差数列随便搞一搞。。。
*代码:

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. #include <cmath>
  5. #ifdef WIN32
  6. #define LL "%I64d"
  7. #else
  8. #define LL "%lld"
  9. #endif
  10. #ifdef CT
  11. #define debug(...) printf(__VA_ARGS__)
  12. #define setfile()
  13. #else
  14. #define debug(...)
  15. #define filename ""
  16. #define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout);
  17. #endif
  18. #define R register
  19. #define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
  20. #define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
  21. #define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
  22. #define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
  23. #define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
  24. char B[1 << 15], *S = B, *T = B;
  25. inline int FastIn()
  26. {
  27. R char ch; R int cnt = 0; R bool minus = 0;
  28. while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
  29. ch == '-' ? minus = 1 : cnt = ch - '0';
  30. while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
  31. return minus ? -cnt : cnt;
  32. }
  33. #define maxn 100010
  34. int a[maxn], p[maxn];
  35. int main()
  36. {
  37. // setfile();
  38. R int n = FastIn(), k = FastIn(), tmp = 0, i;
  39. for (i = 1; i <= n + 1; ++i) p[i] = p[i - 1] + i;
  40. for (i = 1; p[i] < k; ++i);
  41. k -= p[i - 1];
  42. for (R int i = 1; i <= n; ++i)
  43. a[i] = FastIn();
  44. printf("%d\n",a[k] );
  45. return 0;
  46. }

C题:

*题目描述:
有n个人和m场电影,每个人只会一种语言,m场电影有配音和字幕,如果某个人看的电影是自己会的语言配音的话,他就会很高兴,如果是自己会的语言的字幕的话,他就会一般高兴,否则就会不高兴。问:应该选择哪场电影能够使得很高兴的人最多,在保证非常高兴最多的同时,输出一般高兴的人最多的。如果有多个答案输出任意一个。
*题解:
STL题。。。sort+lower_bound,不过还要手写unique就是了。
*代码:

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. #include <cmath>
  5. #ifdef WIN32
  6. #define LL "%I64d"
  7. #else
  8. #define LL "%lld"
  9. #endif
  10. #ifdef CT
  11. #define debug(...) printf(__VA_ARGS__)
  12. #define setfile()
  13. #else
  14. #define debug(...)
  15. #define filename ""
  16. #define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout);
  17. #endif
  18. #define R register
  19. #define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
  20. #define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
  21. #define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
  22. #define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
  23. #define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
  24. char B[1 << 15], *S = B, *T = B;
  25. inline int FastIn()
  26. {
  27. R char ch; R int cnt = 0; R bool minus = 0;
  28. while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
  29. ch == '-' ? minus = 1 : cnt = ch - '0';
  30. while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
  31. return minus ? -cnt : cnt;
  32. }
  33. #define maxn 200010
  34. int a[maxn], num[maxn];
  35. struct Poi
  36. {
  37. int b, c, pos, num1, num2;
  38. inline bool operator < (const Poi &that) const {return num1 < that.num1 || (num1 == that.num1 && num2 < that.num2);}
  39. }p[maxn];
  40. int main()
  41. {
  42. // setfile();
  43. R int n = FastIn();
  44. for (R int i = 1; i <= n; ++i)
  45. a[i] = FastIn();
  46. R int m = FastIn();
  47. for (R int i = 1; i <= m; ++i)
  48. p[i].b = FastIn(), p[i].pos = i;
  49. for (R int i = 1; i <= m; ++i)
  50. p[i].c = FastIn();
  51. std::sort(a + 1, a + n + 1);
  52. R int newn = 0;
  53. for (R int i = 1; i <= n; ++i)
  54. if (a[i] == a[i - 1]) ++num[newn];
  55. else a[++newn] = a[i], num[newn] = 1;
  56. for (R int i = 1; i <= m; ++i)
  57. {
  58. R int tmp = std::lower_bound(a + 1, a + newn + 1, p[i].b) - a;
  59. if (a[tmp] == p[i].b) p[i].num1 = num[tmp];
  60. else p[i].num1 = 0;
  61. tmp = std::lower_bound(a + 1, a + newn + 1, p[i].c) - a;
  62. if (a[tmp] == p[i].c) p[i].num2 = num[tmp];
  63. else p[i].num2 = 0;
  64. }
  65. std::sort(p + 1, p + m + 1);
  66. printf("%d\n",p[m].pos );
  67. return 0;
  68. }

D题:

*题目描述:
你制作一个曲奇需要n种配料,你还有k个可以变成任意一种配料的神奇的粉末。对于每一种配料i,你配出1份曲奇需要第i种配料ai个,而你有bi个这种配料,问:你最多可以配出多少份曲奇?
*题解:
直接二分答案,然后判断需要多少个神奇粉末,再和k比较。
*代码:

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. #include <cmath>
  5. #ifdef WIN32
  6. #define LL "%I64d"
  7. #else
  8. #define LL "%lld"
  9. #endif
  10. #ifdef CT
  11. #define debug(...) printf(__VA_ARGS__)
  12. #define setfile()
  13. #else
  14. #define debug(...)
  15. #define filename ""
  16. #define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout);
  17. #endif
  18. #define R register
  19. #define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
  20. #define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
  21. #define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
  22. #define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
  23. #define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
  24. char B[1 << 15], *S = B, *T = B;
  25. inline int FastIn()
  26. {
  27. R char ch; R int cnt = 0; R bool minus = 0;
  28. while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
  29. ch == '-' ? minus = 1 : cnt = ch - '0';
  30. while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
  31. return minus ? -cnt : cnt;
  32. }
  33. #define maxn 100010
  34. int a[maxn], b[maxn], n, k;
  35. inline bool check(R long long x)
  36. {
  37. R long long tmp = 0;
  38. for (R int i = 1; i <= n; ++i)
  39. if (b[i] < 1ll * x * a[i]) tmp += 1ll * x * a[i] - b[i];
  40. return tmp <= k;
  41. }
  42. int main()
  43. {
  44. // setfile();
  45. n = FastIn(), k = FastIn();
  46. for (R int i = 1; i <= n; ++i)
  47. a[i] = FastIn();
  48. for (R int i = 1; i <= n; ++i)
  49. b[i] = FastIn();
  50. R long long l = 0, r = 2e9 + 233;
  51. while (l < r)
  52. {
  53. R long long mid = l + r >> 1;
  54. if (check(mid)) l = mid + 1;
  55. else r = mid;
  56. }
  57. printf(LL"\n",l - 1 );
  58. return 0;
  59. }

E题:

*题目描述:
你需要写一个括号序列编辑器。你有一个长度为n的括号序列,以及m个操作,还有初始时光标的位置。每次的操作有:
1.将光标左移一位
2.将光标右移一位
3.删除光标所在的括号以及和它匹配的括号中间的部分。
*题解:
先用一个栈来匹配左右括号序列,然后再用链表维护整个括号序列。每次删除操作就在链表上进行区间删除。(我真的是数据结构写傻了,第一反应居然是Treap,后来马上发现用链表维护就可以了,最后因为边界写搓了没有在规定的时间内ac,后来调过了总算是a了)
*代码:

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. #include <cmath>
  5. #ifdef WIN32
  6. #define LL "%I64d"
  7. #else
  8. #define LL "%lld"
  9. #endif
  10. #ifdef CT
  11. #define debug(...) printf(__VA_ARGS__)
  12. #define setfile()
  13. #else
  14. #define debug(...)
  15. #define filename ""
  16. #define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout);
  17. #endif
  18. #define R register
  19. #define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
  20. #define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
  21. #define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
  22. #define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
  23. #define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
  24. char B[1 << 15], *S = B, *T = B;
  25. inline int FastIn()
  26. {
  27. R char ch; R int cnt = 0; R bool minus = 0;
  28. while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
  29. ch == '-' ? minus = 1 : cnt = ch - '0';
  30. while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
  31. return minus ? -cnt : cnt;
  32. }
  33. #define maxn 500010
  34. bool br[maxn];
  35. int last[maxn], next[maxn], stack[maxn], pr[maxn], q, m, n;
  36. inline void print_ans()
  37. {
  38. for (R int i = next[0]; i <= n; i = next[i]) putchar(br[i] ? '(' : ')');
  39. puts("");
  40. }
  41. int main()
  42. {
  43. // setfile();
  44. n = FastIn(), m = FastIn(), q = FastIn();
  45. for (R int i = 1; i <= n; ++i)
  46. {
  47. R char ch = getc();
  48. while (ch != '(' && ch != ')') ch = getc();
  49. br[i] = ch == '(';
  50. last[i] = i - 1;
  51. next[i] = i + 1;
  52. }
  53. next[0] = 1;
  54. last[n + 1] = n;
  55. R int top = 0;
  56. for (R int i = 1; i <= n; ++i)
  57. {
  58. if (br[i]) stack[++top] = i;
  59. else
  60. {
  61. pr[i] = stack[top--];
  62. pr[pr[i]] = i;
  63. }
  64. }
  65. for (R int i = 1; i <= m; ++i)
  66. {
  67. R char opt = getc();
  68. while (opt < 'A' || opt > 'Z') opt = getc();
  69. if (opt == 'L') q = last[q];
  70. if (opt == 'R') q = next[q];
  71. if (opt == 'D')
  72. {
  73. if (br[q])
  74. {
  75. last[next[pr[q]]] = last[q];
  76. next[last[q]] = next[pr[q]];
  77. q = next[pr[q]];
  78. }
  79. else
  80. {
  81. last[next[q]] = last[pr[q]];
  82. next[last[pr[q]]] = next[q];
  83. q = next[q];
  84. }
  85. if (q > n) q = last[n + 1];
  86. }
  87. }
  88. print_ans();
  89. return 0;
  90. }

Codeforces Round #350(Div 2)的更多相关文章

  1. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 模拟

    题目链接: http://codeforces.com/contest/670/problem/E 题解: 用STL的list和stack模拟的,没想到跑的还挺快. 代码: #include<i ...

  2. Codeforces Round #350 (Div. 2) D2. Magic Powder - 2

    题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cs ...

  3. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor (链表)

    题目链接:http://codeforces.com/contest/670/problem/E 给你n长度的括号字符,m个操作,光标初始位置是p,'D'操作表示删除当前光标所在的字符对应的括号字符以 ...

  4. Codeforces Round #350 (Div. 2)解题报告

    codeforces 670A. Holidays 题目链接: http://codeforces.com/contest/670/problem/A 题意: A. Holidays On the p ...

  5. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 栈 链表

    E. Correct Bracket Sequence Editor 题目连接: http://www.codeforces.com/contest/670/problem/E Description ...

  6. Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分

    D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...

  7. Codeforces Round #350 (Div. 2) C. Cinema 水题

    C. Cinema 题目连接: http://www.codeforces.com/contest/670/problem/C Description Moscow is hosting a majo ...

  8. Codeforces Round #350 (Div. 2) B. Game of Robots 水题

    B. Game of Robots 题目连接: http://www.codeforces.com/contest/670/problem/B Description In late autumn e ...

  9. Codeforces Round #350 (Div. 2) A. Holidays 水题

    A. Holidays 题目连接: http://www.codeforces.com/contest/670/problem/A Description On the planet Mars a y ...

  10. Codeforces Round #350 (Div. 2) E 思维模拟

    给出一个合法的括号串 有LRD三种操作 LR分别是左右移动当前位置 且合法 D为删除这个括号和里面的所有 当删除完成后 位置向右移动 如果不能移动 就向左 比赛都是很久远的事情了 写这道题也是一时兴起 ...

随机推荐

  1. 【Go语言】map在goroutine通信中的使用问题

    简介 本篇文章的主要内容是解决go语言map在使用中遇到的两个问题,对于初学者是不可避免的坑 一.cannot assign to struct field 当map中存在struct类型的成员,如果 ...

  2. Centos7 搭建pptp服务器

    1.检查是否支持pptp 返回ok即表示支持 modprobe ppp-compress-18 && echo ok 2.安装ppp yum install -y ppp 3.安装pp ...

  3. soot学习历程---(1)

    今天看了soot生成手册的部分内容,简单摘录一下 Scene 表示分析所处的完整环境,可以借此设置application class(用sootclass),主类(main),point-to和cal ...

  4. [ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Cannot access nexus-aliyun (http://maven.aliyun.com/nexus/content/groups/public) in off

    这个错误是将work offline打勾引起的. 这个是离线工作模式,相当于断网,远程的jar会拉不下来.

  5. 有序无序Ul->Li Ol->Li菜单,默认点击当前弹出下拉,再次点击收起下拉菜单(变形2 ---修饰)

    从上面可以看出,两个问题,第一:下拉出现的太快太突然,第二:再点击下一个下拉菜单的时候,上一个不会闭合,针对这两个问题,接下来会一 一解决. 解决下拉太快: js中有个jquery效果,有一个效果是j ...

  6. 理解 JavaScript 闭包

    这是本系列的第 4 篇文章. 作为 JS 初学者,第一次接触闭包的概念是因为写出了类似下面的代码: for (var i = 0; i < helpText.length; i++) { var ...

  7. Lock和synchronized的区别和使用(转发)

    今天看了并发实践这本书的ReentantLock这章,感觉对ReentantLock还是不够熟悉,有许多疑问,所有在网上找了很多文章看了一下,总体说的不够详细,重点和焦点问题没有谈到,但这篇文章相当不 ...

  8. Luogu P2756 [网络流24题]飞行员配对方案问题_二分图匹配题解

    二分图模板题 我用的是匈牙利 其实最大流也可以做 #include<iostream> #include<cstdio> #include<cstdlib> #in ...

  9. SSM获取前台参数的方式

    1.直接把表单的参数写在Controller相应的方法的形参中,适用于get方式提交,不适用于post方式提交.若"Content-Type"="application/ ...

  10. js中的函数防抖与节流

    一.滚动条监听的例子 写一个功能需求-- 监听浏览器滚动事件,返回当前滚条与顶部的距离,代码如下: function showTop () { var scrollTop = document.bod ...