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)的更多相关文章

  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. Python之路,Day13-----暂无正在更新中

    Python之路,Day13-----暂无正在更新中

  2. JavaScript调用后台的三种方法实例(包含两种Ajax)

    方法一:直接使用<%=%>调用(ASPX页面) 前台JS,代码如下: <script type="text/javascript"> var methodS ...

  3. Char Varchar Nvarchar区别

    char和varchar是一样的字符型,不同在于,varchar比char更灵活,精确,且不占内存空间,当你取同样的字符时,char会在该字符后面加上空格,而varchar则只取得这个字符,比如有字段 ...

  4. 简单总结焦点事件、Event事件对象、冒泡事件

    每学习一些新的东西,要学会复习,总结和记录. 今天来简单总结一下学到的几个事件:焦点事件.Event事件对象.冒泡事件 其实这几个事件应该往深的说是挺难的,但今天主要是以一个小菜的角度去尝试理解一些基 ...

  5. windows下安装CI框架

    CI框架是一个非常流行的 mvc框架, CI框架如何安装和使用,在CI中文网已经讲的比较详细了 ,这里记录下几个需要注意的地方. 一. index.php问题 把压缩包下载解压到项目根目录即可运行里面 ...

  6. 重新开始学习javase_Exception

    “违例”(Exception)这个词表达的是一种“例外”情况,亦即正常情况之外的一种“异常”.在问题发生的时候,我们可能不知具体该如何解决,但肯定知道已不能不顾一切地继续下去.此时,必须坚决地停下来, ...

  7. TCP连接的状态分析

    1.先来了解一下TCP连接建立与关闭过程中的各种状态: CLOSED:初始状态,表示没有任何连接.LISTEN:Server端的某个Socket正在监听来自远方的TCP端口的连接请求.SYN_SENT ...

  8. linux网络编程常用头文件

    sys/types.h:数据类型定义 sys/socket.h:提供socket函数及数据结构 netinet/in.h:定义数据结构sockaddr_in arpa/inet.h:提供IP地址转换函 ...

  9. javascript 中的nextSibling和previousSibling使用注意事项

    JavaScript中的nextSibling和previousSibling和作用类似于jquery的next()和prev(),都是获取下一个/上一个同胞元素,如果下一个同级节点不存在,则此属性返 ...

  10. phpMemcache消息队列类

    <?php /** * Memcache 消息队列类 */ class QMC { const PREFIX = 'ASDFASDFFWQKE'; /** * 初始化 mc * @staticv ...