SRM468 - SRM469(1-250pt, 500pt)
SRM 468
DIV1 250pt
题意:给出字典,按照一定要求进行查找。
解法:模拟题,暴力即可。
tag:water
score: 0....
这是第一次AC的代码:
- /*
- * Author: plum rain
- * score : 0
- */
- #line 11 "T9.cpp"
- #include <sstream>
- #include <stdexcept>
- #include <functional>
- #include <iomanip>
- #include <numeric>
- #include <fstream>
- #include <cctype>
- #include <iostream>
- #include <cstdio>
- #include <vector>
- #include <cstring>
- #include <cmath>
- #include <algorithm>
- #include <map>
- using namespace std;
- #define CLR(x) memset(x, 0, sizeof(x))
- #define PB push_back
- #define SZ(v) ((int)(v).size())
- #define out(x) cout<<#x<<":"<<(x)<<endl
- #define tst(a) cout<<#a<<endl
- typedef vector<string> VS;
- map<char, int> mp;
- class T9
- {
- public:
- string message(vector <string> part, vector <string> dict, vector <string> ke){
- int size = SZ (part);
- for (int i = ; i < size; ++ i)
- for (int j = ; j < SZ(part[i]); ++ j)
- mp[part[i][j]] = i+;
- VS dic; dic.clear();
- size = SZ (dict);
- for (int i = ; i < size; ++ i){
- string s; s.clear();
- int n = SZ (dict[i]);
- for (int j = ; j < n; ++ j)
- s.PB (mp[dict[i][j]] + '');
- dic.PB (s);
- }
- for (int i = ; i < size; ++ i)
- for (int j = ; j < size--i; ++ j){
- bool ok = false;
- if (dic[j] < dic[j+]) ok = true;
- if (dic[j] == dic[j+] && dict[j] > dict[j+])
- ok = true;
- if (ok){
- swap (dic[j], dic[j+]);
- swap (dict[j], dict[j+]);
- }
- }
- string ans; ans.clear();
- size = SZ (ke);
- string s; s.clear();
- for (int i = ; i < size; ++ i)
- s += ke[i];
- size = SZ (s);
- string tmp; tmp.clear();
- int cnt = ;
- for (int i = ; i < size; ++ i){
- if (s[i] == '*') cnt += ;
- if (s[i] == '#') ++ cnt;
- if (s[i] >= '' && s[i] <= '') tmp.PB(s[i]);
- if (s[i] == ''){
- if (tmp.empty() && !cnt){
- ans.PB (' ');
- continue;
- }
- int pos;
- for (int j = ; j < SZ (dic); ++ j)
- if (dic[j] == tmp){
- pos = j;
- break;
- }
- pos = pos + cnt;
- ans = ans + dict[pos];
- cnt = ; tmp.clear();
- ans.PB (' ');
- }
- }
- if (tmp.empty() && !cnt) return ans;
- int pos;
- for (int i = ; i < SZ (dic); ++ i)
- if (dic[i] == tmp){
- pos = i;
- break;
- }
- pos = pos + cnt;
- ans = ans + dict[pos];
- return ans;
- }
- };
这是后来改进的代码:
- /*
- * Author: plum rain
- * score : 0
- */
- #line 11 "T9.cpp"
- #include <sstream>
- #include <stdexcept>
- #include <functional>
- #include <iomanip>
- #include <numeric>
- #include <fstream>
- #include <cctype>
- #include <iostream>
- #include <cstdio>
- #include <vector>
- #include <cstring>
- #include <cmath>
- #include <algorithm>
- #include <utility>
- #include <map>
- using namespace std;
- #define CLR(x) memset(x, 0, sizeof(x))
- #define PB push_back
- #define SZ(v) ((int)(v).size())
- #define out(x) cout<<#x<<":"<<(x)<<endl
- #define tst(a) cout<<#a<<endl
- typedef vector<string> VS;
- map<char, int> mp;
- bool cmp(pair<string, string> a, pair<string, string> b)
- {
- if (a.first < b.first) return true;
- if (a.first == b.first && a.second < b.second) return true;
- return false;
- }
- class T9
- {
- public:
- string message(vector <string> part, vector <string> dict, vector <string> ke){
- int size = SZ (part);
- mp.clear();
- for (int i = ; i < size; ++ i)
- for (int j = ; j < SZ(part[i]); ++ j)
- mp[part[i][j]] = i+;
- vector<pair<string, string> > D; D.clear();
- size = SZ (dict);
- for (int i = ; i < size; ++ i){
- string s; s.clear();
- int n = SZ (dict[i]);
- for (int j = ; j < n; ++ j)
- s.PB (mp[dict[i][j]] + '');
- D.PB (make_pair(s, dict[i]));
- }
- sort (D.begin(), D.end(), cmp);
- size = SZ (ke);
- string s; s.clear();
- for (int i = ; i < size; ++ i)
- s += ke[i];
- s.PB ('');
- size = SZ (s);
- string tmp; tmp.clear();
- string ans; ans.clear();
- int cnt = ;
- for (int i = ; i < size; ++ i){
- if (s[i] == '*') cnt += ;
- if (s[i] == '#') ++ cnt;
- if (s[i] >= '' && s[i] <= '') tmp.PB(s[i]);
- if (s[i] == ''){
- if (tmp.empty() && !cnt){
- if (i != (size-))
- ans.PB (' ');
- continue;
- }
- int pos;
- for (int j = ; j < SZ (D); ++ j)
- if (D[j].first == tmp){
- pos = j;
- break;
- }
- pos = pos + cnt;
- ans = ans + D[pos].second;
- cnt = ; tmp.clear();
- if (i != (size-))
- ans.PB (' ');
- }
- }
- return ans;
- }
- };
SRM 469
DIV1 250pt
题意:给定n * m的网格中,其中有若干点不能被选择,然后从其他点中选出同行且相邻的两点,问有多少种选择方法?(1 <= n,m <= 10^8)
解法:水题
score: 129.09
tag: math, counting
- /*
- * Author: plum rain
- * score: 129.09
- */
- #line 10 "TheMoviesLevelOneDivOne.cpp"
- #include <iostream>
- #include <cstdio>
- #include <sstream>
- #include <cstring>
- #include <algorithm>
- #include <vector>
- using namespace std;
- #define CLR(x) memset(x, 0, sizeof(x))
- #define SZ(v) ((int)(v).size())
- #define out(x) cout<<#x<<":"<<(x)<<endl
- #define tst(a) cout<<#a<<endl
- typedef long long int64;
- struct pos{
- int x, y;
- };
- pos a[];
- bool cmp(pos a, pos b)
- {
- if (a.x < b.x)
- return true;
- if (a.x == b.x && a.y < b.y)
- return true;
- return false;
- }
- int64 gao(int64 size, int64 n, int64 m)
- {
- int i = ;
- int64 tmp = a[].x, dif = ;
- if (a[].y == ) dif = ;
- if (a[].y >= ) dif = ;
- while (i < size){
- if (tmp == a[i].x){
- if (a[i-].y == a[i].y-) ++ dif;
- else dif += ;
- ++ i;
- continue;
- }
- if (a[i-].y == m) -- dif;
- if (a[i].y == ) ++ dif;
- if (a[i].y >= ) dif += ;
- tmp = a[i].x;
- ++ i;
- }
- if (a[i-].y == m) -- dif;
- return n * (m-) - dif;
- }
- class TheMoviesLevelOneDivOne
- {
- public:
- long long find(int n, int m, vector <int> row, vector <int> seat){
- CLR (a);
- int size = SZ (row);
- for (int i = ; i < size; ++ i)
- a[i].x = row[i], a[i].y = seat[i];
- sort (a, a+size, cmp);
- return (gao(size, n, m));
- }
- };
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
- /*
- * Author: plum rain
- * score : 0
- */
- #line 10 "TheMoviesLevelTwoDivOne.cpp"
- #include <iostream>
- #include <cstdio>
- #include <sstream>
- #include <cstring>
- #include <algorithm>
- #include <vector>
- using namespace std;
- #define CLR(x) memset(x, 0, sizeof(x))
- #define PB push_back
- #define SZ(v) ((int)(v).size())
- #define out(x) cout<<#x<<":"<<(x)<<endl
- #define tst(a) cout<<#a<<endl
- typedef vector<int> VI;
- const int N = ;
- int n;
- vector<pair<int, int> > a;
- int num[<<N], fir[<<N];
- VI DP()
- {
- CLR (num); CLR (fir);
- for (int opt = ; opt < (<<n); ++ opt){
- int flag, tmp = -;
- int sca = ;
- for (int i = ; i < n; ++ i)
- if (!(opt & (<<i))) sca += - a[i].first;
- for (int i = ; i < n; ++ i) if (opt & (<<i)){
- int x = ;
- if (sca >= a[i].second && sca >= (a[i].first - ))
- x = + num[opt-(<<i)];
- if (x > tmp)
- tmp = x, flag = i;
- }
- num[opt] = tmp;
- fir[opt] = flag;
- }
- int opt = (<<n) - ;
- VI ret; ret.clear();
- while (opt > ){
- ret.PB (fir[opt]);
- opt -= (<<fir[opt]);
- }
- return ret;
- }
- class TheMoviesLevelTwoDivOne
- {
- public:
- vector <int> find(vector <int> ls, vector <int> sc){
- n = SZ (ls);
- a.clear();
- for (int i = ; i < n; ++ i)
- a.PB(make_pair(ls[i], sc[i]));
- return (DP());
- }
- };
SRM468 - SRM469(1-250pt, 500pt)的更多相关文章
- SRM 358(1-250,500pt)
DIV1 250pt 题意:电视目前停留在第100台,有一个遥控器,可以向上或向下换台(需要按键一次),也可以按一些数字,然后直接跳到该台(需要按键次数等于数字数,不需要按确定键).但是,这个遥控一些 ...
- SRM 601(1-250pt,500pt)
DIV1 250pt 题意:有很多袋子,里面装有苹果和橘子(也可能没有),给出每个袋子里有多少个苹果,多少个橘子.如果每个袋子里含有水果的总数都不小于x个,则可以从每个袋子里都拿出x个水果(拿出苹果和 ...
- SRM475 - SRM479(1-250pt,500pt)
SRM 475 DIV1 300pt 题意:玩游戏.给一个棋盘,它有1×n(1行n列,每列标号分别为0,1,2..n-1)的格子,每个格子里面可以放一个棋子,并且给定一个只含三个字母WBR,长度为n的 ...
- SRM470 - SRM474(1-250pt,500pt)(471-500pt为最短路,474-500pt未做)
SRM 470 DIV1 250pt 题意:有n个房间排成一排,相邻两个房间之间有一扇关闭着的门(共n-1扇),每个门上都标有‘A’-‘P’的大写字母.给定一个数n,表示第n个房间.有两个人John和 ...
- SRM469
250pt 在一个10^9 * 10^9大的剧院里,有最多47个位子有人,然后有一对couple想找一对左右相邻的位子,问有多少种选择方式. 思路: 总共有 n * (m-1)种方案,然后扣掉有人位置 ...
- SRM468
250pt 给定手机0-9按键对应的英文字母(1个对多个),0固定对应空格.然后在给定一些单词.以及一个要处理的串,叫你按照那个串模拟输出结果 思路: 大模拟,写的有点乱 // BEGIN CUT H ...
- 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 ...
- SRM 600(1-250pt,500pt)
DIV1 250pt 题意:给定一个vector<int>A,若能从里面选出一些数,使得他们按位或的值为x,则称x为吉利数.给定k,问最少要从A里面去掉多少个数,才能使k变为不吉利数. 解 ...
- SRM593(1-250pt,500pt)
SRM 593 DIV1 250pt 题意:有如下图所示的平面,每个六边形有坐标.将其中一些六边形染色,要求有边相邻的两个六边形不能染同一种颜色.给定哪些六边形需要染色,问最少需要多少种颜色. 解法: ...
随机推荐
- 【IOS】 XML解析和xml转plist文件(GDataXML)
iOS对于XML的解析有系统自带的SDK--NSXMLParser,鄙人愚拙,只会用GDataXML进行解析,这里仅介绍GData的使用.(以下图为例) 1.对于一个xml文件,先读取出来 NSDat ...
- 【开源java游戏框架libgdx专题】-08-中文显示与绘制
libgdx虽然是由美国人Mario Zechner(即BadlogicGames)写的开源引擎,由于Libgdx底层是用OpenGL实现的,所以Libgdx是可以支持中文的,在libgdx中的汉字都 ...
- 如何在ASP.NET端获取屏幕宽度
using System.Windows.Forms; 首先引用上面的命名空间. 然后在代码中获取屏幕信息.如下代码: System.Windows.Forms.Screen screen = Sys ...
- J2EE初探
J2EE概述 3层结构 4层模型 13项核心技术 J2EE容器 J2EE的优势与缺陷 J2EE概述 Java 2平台有3个版本,分别是适用于小型设备和智能卡的Java 2平台Micro版(Java ...
- Java编程思想-注解生成外部例子代码
如果本文帮助到您,请点击下面的链接,这是本人的网站,以示鼓励,谢谢!链接绝对安全! 本人的网站 java注解属于java中高大上的功能,许多开源框架都使用了java注解的功能.比如spring,hib ...
- xmlns:android="http://schemas.android.com/apk/res/android" 是什么意思?
声明xml命名空间.xmlns意思为“xml namespace”.冒号后面是给这个引用起的别名.schemas是xml文档的两种约束文件其中的一种,规定了xml中有哪些元素(标签).元素有哪些属性及 ...
- Hibernate中分页
query.setFirstResult(4);query.setMaxResults(5); 这两个方法就是hibernate的分页
- c++面试(二)
1.宏参数的连接 #define CONS(a,b) (int)(a##e##b) CONS(2,3) =>2e3 =2000 2.const int b=10; int c=20; const ...
- 一个小玩具:NDK编译FFmpeg的例子
FFmpeg NDK编译 和最简单的APK 准备 硬件: 一台电脑,实验在Lenovo T430上 一个Android设备,实验在 三星S3/A7 编译环境: Ubuntu 14.04 (ant\ja ...
- 安装 mysql
1.安装mysql客户端 yum install mysql 2.安装mysql 服务器端 yum install mysql-server 3.配置 mysql字符集 /etc/my.cnf 加入 ...