SRM 468

DIV1 250pt

题意:给出字典,按照一定要求进行查找。

解法:模拟题,暴力即可。

tag:water

score: 0....

这是第一次AC的代码:

  1. /*
  2. * Author: plum rain
  3. * score : 0
  4. */
  5. #line 11 "T9.cpp"
  6. #include <sstream>
  7. #include <stdexcept>
  8. #include <functional>
  9. #include <iomanip>
  10. #include <numeric>
  11. #include <fstream>
  12. #include <cctype>
  13. #include <iostream>
  14. #include <cstdio>
  15. #include <vector>
  16. #include <cstring>
  17. #include <cmath>
  18. #include <algorithm>
  19. #include <map>
  20.  
  21. using namespace std;
  22.  
  23. #define CLR(x) memset(x, 0, sizeof(x))
  24. #define PB push_back
  25. #define SZ(v) ((int)(v).size())
  26. #define out(x) cout<<#x<<":"<<(x)<<endl
  27. #define tst(a) cout<<#a<<endl
  28.  
  29. typedef vector<string> VS;
  30.  
  31. map<char, int> mp;
  32.  
  33. class T9
  34. {
  35. public:
  36. string message(vector <string> part, vector <string> dict, vector <string> ke){
  37. int size = SZ (part);
  38. for (int i = ; i < size; ++ i)
  39. for (int j = ; j < SZ(part[i]); ++ j)
  40. mp[part[i][j]] = i+;
  41.  
  42. VS dic; dic.clear();
  43. size = SZ (dict);
  44. for (int i = ; i < size; ++ i){
  45. string s; s.clear();
  46. int n = SZ (dict[i]);
  47. for (int j = ; j < n; ++ j)
  48. s.PB (mp[dict[i][j]] + '');
  49. dic.PB (s);
  50. }
  51.  
  52. for (int i = ; i < size; ++ i)
  53. for (int j = ; j < size--i; ++ j){
  54. bool ok = false;
  55. if (dic[j] < dic[j+]) ok = true;
  56. if (dic[j] == dic[j+] && dict[j] > dict[j+])
  57. ok = true;
  58. if (ok){
  59. swap (dic[j], dic[j+]);
  60. swap (dict[j], dict[j+]);
  61. }
  62. }
  63.  
  64. string ans; ans.clear();
  65. size = SZ (ke);
  66. string s; s.clear();
  67. for (int i = ; i < size; ++ i)
  68. s += ke[i];
  69. size = SZ (s);
  70. string tmp; tmp.clear();
  71. int cnt = ;
  72. for (int i = ; i < size; ++ i){
  73. if (s[i] == '*') cnt += ;
  74. if (s[i] == '#') ++ cnt;
  75. if (s[i] >= '' && s[i] <= '') tmp.PB(s[i]);
  76. if (s[i] == ''){
  77. if (tmp.empty() && !cnt){
  78. ans.PB (' ');
  79. continue;
  80. }
  81. int pos;
  82. for (int j = ; j < SZ (dic); ++ j)
  83. if (dic[j] == tmp){
  84. pos = j;
  85. break;
  86. }
  87. pos = pos + cnt;
  88. ans = ans + dict[pos];
  89. cnt = ; tmp.clear();
  90. ans.PB (' ');
  91. }
  92. }
  93. if (tmp.empty() && !cnt) return ans;
  94. int pos;
  95. for (int i = ; i < SZ (dic); ++ i)
  96. if (dic[i] == tmp){
  97. pos = i;
  98. break;
  99. }
  100. pos = pos + cnt;
  101. ans = ans + dict[pos];
  102. return ans;
  103. }
  104. };

这是后来改进的代码:

  1. /*
  2. * Author: plum rain
  3. * score : 0
  4. */
  5. #line 11 "T9.cpp"
  6. #include <sstream>
  7. #include <stdexcept>
  8. #include <functional>
  9. #include <iomanip>
  10. #include <numeric>
  11. #include <fstream>
  12. #include <cctype>
  13. #include <iostream>
  14. #include <cstdio>
  15. #include <vector>
  16. #include <cstring>
  17. #include <cmath>
  18. #include <algorithm>
  19. #include <utility>
  20. #include <map>
  21.  
  22. using namespace std;
  23.  
  24. #define CLR(x) memset(x, 0, sizeof(x))
  25. #define PB push_back
  26. #define SZ(v) ((int)(v).size())
  27. #define out(x) cout<<#x<<":"<<(x)<<endl
  28. #define tst(a) cout<<#a<<endl
  29.  
  30. typedef vector<string> VS;
  31.  
  32. map<char, int> mp;
  33.  
  34. bool cmp(pair<string, string> a, pair<string, string> b)
  35. {
  36. if (a.first < b.first) return true;
  37. if (a.first == b.first && a.second < b.second) return true;
  38. return false;
  39. }
  40.  
  41. class T9
  42. {
  43. public:
  44. string message(vector <string> part, vector <string> dict, vector <string> ke){
  45. int size = SZ (part);
  46. mp.clear();
  47. for (int i = ; i < size; ++ i)
  48. for (int j = ; j < SZ(part[i]); ++ j)
  49. mp[part[i][j]] = i+;
  50.  
  51. vector<pair<string, string> > D; D.clear();
  52. size = SZ (dict);
  53. for (int i = ; i < size; ++ i){
  54. string s; s.clear();
  55. int n = SZ (dict[i]);
  56. for (int j = ; j < n; ++ j)
  57. s.PB (mp[dict[i][j]] + '');
  58. D.PB (make_pair(s, dict[i]));
  59. }
  60. sort (D.begin(), D.end(), cmp);
  61.  
  62. size = SZ (ke);
  63. string s; s.clear();
  64. for (int i = ; i < size; ++ i)
  65. s += ke[i];
  66. s.PB ('');
  67. size = SZ (s);
  68.  
  69. string tmp; tmp.clear();
  70. string ans; ans.clear();
  71. int cnt = ;
  72. for (int i = ; i < size; ++ i){
  73. if (s[i] == '*') cnt += ;
  74. if (s[i] == '#') ++ cnt;
  75. if (s[i] >= '' && s[i] <= '') tmp.PB(s[i]);
  76. if (s[i] == ''){
  77. if (tmp.empty() && !cnt){
  78. if (i != (size-))
  79. ans.PB (' ');
  80. continue;
  81. }
  82. int pos;
  83. for (int j = ; j < SZ (D); ++ j)
  84. if (D[j].first == tmp){
  85. pos = j;
  86. break;
  87. }
  88. pos = pos + cnt;
  89. ans = ans + D[pos].second;
  90. cnt = ; tmp.clear();
  91. if (i != (size-))
  92. ans.PB (' ');
  93. }
  94. }
  95. return ans;
  96. }
  97. };

SRM 469

DIV1 250pt

题意:给定n * m的网格中,其中有若干点不能被选择,然后从其他点中选出同行且相邻的两点,问有多少种选择方法?(1 <= n,m <= 10^8)

解法:水题

score: 129.09

tag: math, counting

  1. /*
  2. * Author: plum rain
  3. * score: 129.09
  4. */
  5. #line 10 "TheMoviesLevelOneDivOne.cpp"
  6. #include <iostream>
  7. #include <cstdio>
  8. #include <sstream>
  9. #include <cstring>
  10. #include <algorithm>
  11. #include <vector>
  12.  
  13. using namespace std;
  14.  
  15. #define CLR(x) memset(x, 0, sizeof(x))
  16. #define SZ(v) ((int)(v).size())
  17. #define out(x) cout<<#x<<":"<<(x)<<endl
  18. #define tst(a) cout<<#a<<endl
  19.  
  20. typedef long long int64;
  21.  
  22. struct pos{
  23. int x, y;
  24. };
  25.  
  26. pos a[];
  27.  
  28. bool cmp(pos a, pos b)
  29. {
  30. if (a.x < b.x)
  31. return true;
  32. if (a.x == b.x && a.y < b.y)
  33. return true;
  34. return false;
  35. }
  36.  
  37. int64 gao(int64 size, int64 n, int64 m)
  38. {
  39. int i = ;
  40. int64 tmp = a[].x, dif = ;
  41. if (a[].y == ) dif = ;
  42. if (a[].y >= ) dif = ;
  43. while (i < size){
  44. if (tmp == a[i].x){
  45. if (a[i-].y == a[i].y-) ++ dif;
  46. else dif += ;
  47. ++ i;
  48. continue;
  49. }
  50.  
  51. if (a[i-].y == m) -- dif;
  52. if (a[i].y == ) ++ dif;
  53. if (a[i].y >= ) dif += ;
  54. tmp = a[i].x;
  55. ++ i;
  56. }
  57. if (a[i-].y == m) -- dif;
  58.  
  59. return n * (m-) - dif;
  60. }
  61.  
  62. class TheMoviesLevelOneDivOne
  63. {
  64. public:
  65. long long find(int n, int m, vector <int> row, vector <int> seat){
  66. CLR (a);
  67. int size = SZ (row);
  68. for (int i = ; i < size; ++ i)
  69. a[i].x = row[i], a[i].y = seat[i];
  70. sort (a, a+size, cmp);
  71.  
  72. return (gao(size, n, m));
  73. }
  74. };

DIV1 500pt

题意:一个人看电影,该人有一个scare值,并且没看1min电影scare减1。有很多部恐怖电影,每部电影长度不同(length[i]),且每部都有一个瞬间增加scare(s[i])值的时刻。如果scare值小于0,则这个人就会睡着,不能再看电影。请问他安排一个电影观看顺序,使得他能看尽可能多的电影。如果有多组观看顺序看到的电影数相同,则输出字典序最小的。(电影数量小等于20)

解法:如果这道题不要求输出字典序最小的,而是随便输出一组,那就是一道很简单的贪心题。- -

   状压DP。假设有n部电影,用opt来表示所有电影是否排进观影序列(1为该电影未进入观影序列),用num[opt]表示观影序列为opt时所能看的电影数量的最大值,用scare表示观影序列为opt时看完观影序列上的电影后的scare值。则状态转移方程为:

   if (opt & (1<<i) && scare >= s[i] && scare >= length[i] - 47) num[opt] = 1 + num[opt - (1<<i)],for i = 0 to n-1。注意还要记录路径。

score: 0

tag:DP, good

  1. /*
  2. * Author: plum rain
  3. * score : 0
  4. */
  5. #line 10 "TheMoviesLevelTwoDivOne.cpp"
  6. #include <iostream>
  7. #include <cstdio>
  8. #include <sstream>
  9. #include <cstring>
  10. #include <algorithm>
  11. #include <vector>
  12.  
  13. using namespace std;
  14.  
  15. #define CLR(x) memset(x, 0, sizeof(x))
  16. #define PB push_back
  17. #define SZ(v) ((int)(v).size())
  18. #define out(x) cout<<#x<<":"<<(x)<<endl
  19. #define tst(a) cout<<#a<<endl
  20.  
  21. typedef vector<int> VI;
  22.  
  23. const int N = ;
  24. int n;
  25. vector<pair<int, int> > a;
  26. int num[<<N], fir[<<N];
  27.  
  28. VI DP()
  29. {
  30. CLR (num); CLR (fir);
  31. for (int opt = ; opt < (<<n); ++ opt){
  32. int flag, tmp = -;
  33. int sca = ;
  34. for (int i = ; i < n; ++ i)
  35. if (!(opt & (<<i))) sca += - a[i].first;
  36.  
  37. for (int i = ; i < n; ++ i) if (opt & (<<i)){
  38. int x = ;
  39. if (sca >= a[i].second && sca >= (a[i].first - ))
  40. x = + num[opt-(<<i)];
  41. if (x > tmp)
  42. tmp = x, flag = i;
  43. }
  44.  
  45. num[opt] = tmp;
  46. fir[opt] = flag;
  47. }
  48.  
  49. int opt = (<<n) - ;
  50. VI ret; ret.clear();
  51. while (opt > ){
  52. ret.PB (fir[opt]);
  53. opt -= (<<fir[opt]);
  54. }
  55. return ret;
  56. }
  57.  
  58. class TheMoviesLevelTwoDivOne
  59. {
  60. public:
  61. vector <int> find(vector <int> ls, vector <int> sc){
  62. n = SZ (ls);
  63. a.clear();
  64. for (int i = ; i < n; ++ i)
  65. a.PB(make_pair(ls[i], sc[i]));
  66.  
  67. return (DP());
  68. }
  69. };

SRM468 - SRM469(1-250pt, 500pt)的更多相关文章

  1. SRM 358(1-250,500pt)

    DIV1 250pt 题意:电视目前停留在第100台,有一个遥控器,可以向上或向下换台(需要按键一次),也可以按一些数字,然后直接跳到该台(需要按键次数等于数字数,不需要按确定键).但是,这个遥控一些 ...

  2. SRM 601(1-250pt,500pt)

    DIV1 250pt 题意:有很多袋子,里面装有苹果和橘子(也可能没有),给出每个袋子里有多少个苹果,多少个橘子.如果每个袋子里含有水果的总数都不小于x个,则可以从每个袋子里都拿出x个水果(拿出苹果和 ...

  3. SRM475 - SRM479(1-250pt,500pt)

    SRM 475 DIV1 300pt 题意:玩游戏.给一个棋盘,它有1×n(1行n列,每列标号分别为0,1,2..n-1)的格子,每个格子里面可以放一个棋子,并且给定一个只含三个字母WBR,长度为n的 ...

  4. SRM470 - SRM474(1-250pt,500pt)(471-500pt为最短路,474-500pt未做)

    SRM 470 DIV1 250pt 题意:有n个房间排成一排,相邻两个房间之间有一扇关闭着的门(共n-1扇),每个门上都标有‘A’-‘P’的大写字母.给定一个数n,表示第n个房间.有两个人John和 ...

  5. SRM469

    250pt 在一个10^9 * 10^9大的剧院里,有最多47个位子有人,然后有一对couple想找一对左右相邻的位子,问有多少种选择方式. 思路: 总共有 n * (m-1)种方案,然后扣掉有人位置 ...

  6. SRM468

    250pt 给定手机0-9按键对应的英文字母(1个对多个),0固定对应空格.然后在给定一些单词.以及一个要处理的串,叫你按照那个串模拟输出结果 思路: 大模拟,写的有点乱 // BEGIN CUT H ...

  7. SRM DIV1 500pt DP

    SRM 501 DIV1 500pt SRM 502 DIV1 500pt SRM 508 DIV1 500pt SRM 509 DIV1 500pt SRM 511 DIV1 500pt SRM 5 ...

  8. SRM 600(1-250pt,500pt)

    DIV1 250pt 题意:给定一个vector<int>A,若能从里面选出一些数,使得他们按位或的值为x,则称x为吉利数.给定k,问最少要从A里面去掉多少个数,才能使k变为不吉利数. 解 ...

  9. SRM593(1-250pt,500pt)

    SRM 593 DIV1 250pt 题意:有如下图所示的平面,每个六边形有坐标.将其中一些六边形染色,要求有边相邻的两个六边形不能染同一种颜色.给定哪些六边形需要染色,问最少需要多少种颜色. 解法: ...

随机推荐

  1. 【IOS】 XML解析和xml转plist文件(GDataXML)

    iOS对于XML的解析有系统自带的SDK--NSXMLParser,鄙人愚拙,只会用GDataXML进行解析,这里仅介绍GData的使用.(以下图为例) 1.对于一个xml文件,先读取出来 NSDat ...

  2. 【开源java游戏框架libgdx专题】-08-中文显示与绘制

    libgdx虽然是由美国人Mario Zechner(即BadlogicGames)写的开源引擎,由于Libgdx底层是用OpenGL实现的,所以Libgdx是可以支持中文的,在libgdx中的汉字都 ...

  3. 如何在ASP.NET端获取屏幕宽度

    using System.Windows.Forms; 首先引用上面的命名空间. 然后在代码中获取屏幕信息.如下代码: System.Windows.Forms.Screen screen = Sys ...

  4. J2EE初探

    J2EE概述 3层结构 4层模型 13项核心技术 J2EE容器 J2EE的优势与缺陷   J2EE概述 Java 2平台有3个版本,分别是适用于小型设备和智能卡的Java 2平台Micro版(Java ...

  5. Java编程思想-注解生成外部例子代码

    如果本文帮助到您,请点击下面的链接,这是本人的网站,以示鼓励,谢谢!链接绝对安全! 本人的网站 java注解属于java中高大上的功能,许多开源框架都使用了java注解的功能.比如spring,hib ...

  6. xmlns:android="http://schemas.android.com/apk/res/android" 是什么意思?

    声明xml命名空间.xmlns意思为“xml namespace”.冒号后面是给这个引用起的别名.schemas是xml文档的两种约束文件其中的一种,规定了xml中有哪些元素(标签).元素有哪些属性及 ...

  7. Hibernate中分页

    query.setFirstResult(4);query.setMaxResults(5);       这两个方法就是hibernate的分页

  8. c++面试(二)

    1.宏参数的连接 #define CONS(a,b) (int)(a##e##b) CONS(2,3) =>2e3 =2000 2.const int b=10; int c=20; const ...

  9. 一个小玩具:NDK编译FFmpeg的例子

    FFmpeg NDK编译 和最简单的APK 准备 硬件: 一台电脑,实验在Lenovo T430上 一个Android设备,实验在 三星S3/A7 编译环境: Ubuntu 14.04 (ant\ja ...

  10. 安装 mysql

    1.安装mysql客户端 yum install mysql 2.安装mysql 服务器端 yum install mysql-server 3.配置 mysql字符集 /etc/my.cnf 加入 ...