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 题意:有如下图所示的平面,每个六边形有坐标.将其中一些六边形染色,要求有边相邻的两个六边形不能染同一种颜色.给定哪些六边形需要染色,问最少需要多少种颜色. 解法: ...
随机推荐
- Drawable与Bitmap(转)
Drawable 以下这个是测试加载10 ...
- 在/etc/password用户名前面加hello,ID前加is
方法2: #!/bin/sh #set -x file=/etc/passwd while read LINE #for i in `cat $file` do #username=`echo $i| ...
- 转载:C# HashSet 用法
原文地址:http://www.cnblogs.com/xiaopin/archive/2011/01/08/1930540.html 感谢博主分享! NET 3.5在System.Collect ...
- java之迭代器
迭代这个名词对于熟悉Java的人来说绝对不陌生.我们常常使用JDK提供的迭代接口进行java collection的遍历: Iterator it = list.iterator();while(it ...
- js的new操作符
1.创建一个空对象,并且 this 变量引用该对象,同时还继承了该函数的原型. 2.属性和方法被加入到 this 引用的对象中. 3.新创建的对象由 this 所引用,并且最后隐式的返回 this . ...
- JS 通过点击事件动态添加文本框
直接拷贝到浏览器就能实现 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <htm ...
- spring aop pointcut 切入点是类的公共方法(私有方法不行),还是接口的方法
spring aop pointcut 切入点是类的公共方法(私有方法不行),还是接口的方法 类的公共方法可以,但是私有方法不行 测试一下接口的方法是否能够捕捉到
- C#接口的使用
.接口: 接口与抽象类一样,也是表示某种规则,一旦使用了该规则,就必须实现相关的方法.对于C#语言而言,由于只能继承自一个父类,因此若有多个规则需要实现,则使用接口是个比较好的做法. .接口的定义 i ...
- Css四种样式
1. 2 3 4 5 6.
- 【转】 iOS学习之sqlite的创建数据库,表,插入查看数据
原文: http://blog.csdn.net/totogo2010/article/details/7702207 iOS sqlite数据库操作.步骤是: 先加入sqlite开发库libsql ...