SRM468
250pt
给定手机0-9按键对应的英文字母(1个对多个),0固定对应空格。然后在给定一些单词。以及一个要处理的串,叫你按照那个串模拟输出结果
思路:
大模拟,写的有点乱
// BEGIN CUT HERE
/* */
// END CUT HERE
#line 7 "T9.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std; #define PB push_back
#define MP make_pair #define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i) typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII;
struct oo{
string d, s;
bool operator <(const oo &b)const{
if (s < b.s || (s == b.s && d < b.d)) return true;
return false;
}
}; class T9
{
public:
char d[];
oo S[];
int n, m, k;
string find(string a, int k){
int cnt = ;
for (int i = ; i < m; ++i){
if (S[i].s == a) ++cnt;
if (cnt == k) return S[i].d;
}
return "";
}
string message(vector <string> part, vector <string> dict, vector <string> keystr)
{ n = part.size(), m = dict.size(), k = keystr.size();
for (int i = ; i < n; ++i)
for (int j = ; j < part[i].size(); ++j)
d[(int)part[i][j]] = i + ;
for (int i = ; i < m; ++i){
S[i].d = dict[i];
S[i].s.clear();
for (int j = ; j < dict[i].size(); ++j)
S[i].s.push_back(d[dict[i][j]]);
}
sort(S, S + m);
string ans = "";
int cnt = ;
string tmp = "";
string ks = accumulate(keystr.begin(), keystr.end(), string(""));
int k = ks.size();
for (int i = ; i < k; ++i){
if (ks[i] == '*'){ cnt += ; continue; }
if (ks[i] == '#'){ cnt += ; continue; }
if ((ks[i] < '' || ks[i] > '') && (int)tmp.size() > ){
ans += find(tmp, cnt + );
cnt = ;
tmp.clear();
}
if (ks[i] == '') ans += ' ';
if (ks[i] > '' && ks[i] <= '') tmp += ks[i];
}
if ((int)tmp.size() > ) ans += find(tmp, cnt + );
return ans;
} };
500pt
给定n(n <= 40w)个城市,然后在给定2个数组(需要按照给定的算出来),一个为不坐飞机情况下i->i+1所用的时间,一个为作为飞机所用的时间
求在不超过坐k次飞机的情况下,最少时间(一次可以连续做多个城市,但必须连续,比如i->i+1->i+2..)
思路:
动态规划
dp[i][j][k]表示当前到i城市,做了j次飞机,k(0或1)表示最后一次做没做飞机所用的最少时间
方程应该很好推。但要用滚动数组
// BEGIN CUT HERE
/* */
// END CUT HERE
#line 7 "RoadOrFlightHard.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std; #define PB push_back
#define MP make_pair #define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i)
#define Inf (1LL << 50)
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII;
long long rT[], fT[];
long long dp[][][]; class RoadOrFlightHard
{
public:
long long minTime(int N, int roadFirst, int roadProd, int roadAdd, int roadMod, int flightFirst, int flightProd, int flightAdd, int flightMod, int K)
{
rT[] = roadFirst % roadMod;
fT[] = flightFirst % flightMod;
// cout << rT[0] << endl;
for (int i = ; i < N; ++i){
rT[i] = (rT[i-]*roadProd + roadAdd) % roadMod;
fT[i] = (fT[i-]*flightProd + flightAdd) % flightMod;
}
for (int i = ; i <= K; ++i)
dp[][i][] = dp[][i][] = Inf;
dp[][][] = ;
for (int i = ; i < N; ++i){
int cur = i & ;
for (int j = ; j <= K; ++j)
dp[cur^][j][] = dp[cur^][j][] = Inf;
for (int j = ; j <= K; ++j){
if (dp[cur][j][] < Inf){
if(j < K) dp[cur^][j+][] = min(dp[cur^][j+][], dp[cur][j][] + fT[i]);
dp[cur^][j][] = min(dp[cur^][j][], dp[cur][j][] + rT[i]);
}
if (dp[cur][j][] < Inf){
if(j < K) dp[cur^][j+][] = min(dp[cur^][j+][], dp[cur][j][] + fT[i]);
dp[cur^][j][] = min(dp[cur^][j][], dp[cur][j][] + fT[i]);
dp[cur^][j][] = min(dp[cur^][j][], dp[cur][j][] + rT[i]);
}
}
}
long long ans = Inf;
for (int i = ; i <= K; ++i)
for (int j = ; j <= ; ++j)
ans = min(ans, dp[N & ][i][j]);
return ans;
} };
SRM468的更多相关文章
- SRM468 - SRM469(1-250pt, 500pt)
SRM 468 DIV1 250pt 题意:给出字典,按照一定要求进行查找. 解法:模拟题,暴力即可. tag:water score: 0.... 这是第一次AC的代码: /* * Author: ...
随机推荐
- python消息队列Queue
实例1:消息队列Queue,不要将文件命名为"queue.py",否则会报异常"ImportError: cannot import name 'Queue'" ...
- codeforces 数字区分 搜索
Jokewithpermutation Input file: joke.inOutput file: joke.outJoey had saved a permutation of integers f ...
- Delphi--最强大的开发工具(欢迎转载)
最强大的开发工具 Delphi 目录 --------------------------------------------------------------------------- 前言 De ...
- url下载文件到本地
$url = 'http://czd.111.net/extra/car2.jpg'; function download($url, $path = './huahua.jpg') { $ch = ...
- JDesktopPane JInternalFrames
通常 JInternalFrames 需要配合 JDesktopPane 一起使用. JInternalFrames 必须在 JDesktopPane 里面
- where
(二)WHERE //where不单独使用,与match,optional match,start,with搭配 where 与match,optional match 一起用,表示约束 where ...
- robotframework 运行集合
Robot Framework 运行测试通过 pybot 命令,检查 _C:\Python36\Scripts_ 目录下是否有 pybot.bat 文件,正确安装 Robot Framework 一定 ...
- android udp 无法收到数据 (模拟器中)
解决方法:1. 运行模拟器2. 打开window 命令行执行:telnet localhost 55545554是模拟器的端口,执行之后会进入android console3. 在console下执行 ...
- [ASP.net]web.config的customErrors与httpErrors的区别
之前一直知道设置web.config(其实就是xml文件)的customErrors的error来指向自定义的错误页的URL,但是今天在调试的时候发现customErrors无法跳转到自定义的页面,在 ...
- stm8 单线串口能收不能发
原因是把连接的TX和RX短接了,其实在TX和RX间要串一个电阻,然后让stm8的单线TX接到RX.