SRM 586 DIV1
A
考虑都是格点 , 枚举所有y+-0.5就行了.
trick是避免正好在y上的点重复统计.
class PiecewiseLinearFunction {
public:
int maximumSolutions(vector <int>);
};
int n;
int cross(vector<int> Y,double y) {
int res=;
double l,r;
l = (double)Y[];
r = (double)Y[];
for (int i= ; i<n ; i++ ) {
if (y>l && r>l && y<r) res++;
else if (y<l && r<l && y>r) res++;
l = r;
if (i+<n) r = Y[i+];
}
for (int i= ; i<n ; i++ ) if (fabs(Y[i]-y)<1e-) res++;
return res;
}
int solv(vector<int> Y) {
for (int i= ; i<n ; i++ ) if (Y[i]==Y[i-]) return -;
if (Y.size()==) return ;
int res = ;
for (int i= ; i<n ; i++ ) {
int tmp = cross(Y,Y[i]);
res = max(res,tmp);
tmp = cross(Y,Y[i]+0.5);
res = max(res,tmp);
tmp = cross(Y,Y[i]-0.5);
res = max(res,tmp);
printf("y:%d tmp:%d\n",Y[i],tmp);
}
return res;
}
int PiecewiseLinearFunction::maximumSolutions(vector <int> Y) {
n = Y.size();
int ans = solv(Y);
return ans;
}
B
差分约束模型,每一条历史记录可以转化成一条约束,然后建边求最短路.
a->b的最短路和b->a的最短路可以确定一个区间[l,r] 如果l>r则该区间不存在,
判断是否可能时 , 检查线段是否有交点.
using namespace std;
#define maxn 100
#define INF 1000000000
vector<int> his[maxn];
int n,f[maxn][maxn];
class History {
public:
string verifyClaims(vector <string>, vector <string>, vector <string>);
}; void addedge(int a,int ida,int b,int idb) {
int sa = his[a][ida] , ta = his[a][ida+]-;
int sb = his[b][idb] , tb = his[b][idb+]-;
int b_a = ta-sb;
int a_b = tb-sa;
f[b][a] = min(f[b][a],b_a);
f[a][b] = min(f[a][b],a_b);
} void floyd() {
for (int k= ; k<n ; k++ )
for (int i= ; i<n ; i++ )
for (int j= ; j<n ; j++ )
f[i][j] = min(f[i][j] , f[i][k]+f[k][j]);
} void pretreat(vector<string> dyn , vector<string> war) {
n = dyn.size();
for (int i= ; i<n ; i++ ) {
stringstream ss(dyn[i]);
int num;
while (ss>>num) his[i].push_back(num);
} for (int i= ; i<n ; i++ )
for (int j= ; j<n ; j++ ) f[i][j] = INF; string s="";
for (int i= ; i<(int)war.size() ; i++ ) s += war[i];
stringstream ss(s);
string t;
while (ss>>t) {
char a,b;
int ida,idb;
sscanf(t.c_str(),"%c%d-%c%d",&a,&ida,&b,&idb);
addedge(a-'A',ida,b-'A',idb);
}
floyd();
} char check(int a,int ida,int b,int idb) {
int sa = his[a][ida] , ta = his[a][ida+]-;
int sb = his[b][idb] , tb = his[b][idb+]-;
int r = ta-sb;
int l = sa-tb;
int R = f[b][a];
int L = -f[a][b];
if (l>R || r<L) return 'N';
return 'Y';
} string History::verifyClaims(vector <string> dyn, vector <string> war, vector <string> query) {
pretreat(dyn,war);
string res="";
for (int i= ; i<(int)query.size() ; i++ ) {
string t = query[i];
char a,b;
int ida,idb;
sscanf(t.c_str(), "%c%d-%c%d",&a,&ida,&b,&idb);
res += check(a-'A',ida,b-'A',idb);
}
return res;
}
C
首先找出light string的性质:
1. 字符集 = min(26,长度);
2. 相同字母连续出现;
然后发现可以用L,R来表示 从所有串看来,某字母的使用区间 , 第一次使用是L,
最后一次使用是R , 然后就是找到一些约束条件和相关变量,枚举变量dp ,利用约束条件优化复杂度...
int f[maxn][][] , len[maxn] , n;
int dfs(int i,int a,int o,vector<int> L) {
int & res = f[i][a][o];
if (res == -){
res = INF;
if (i==n) {
if (o==) {
res = ;
}
} else {
int s = i->=?len[i-]:;
int m = min(L[i],);
for (int c= ; c<=m && c<=o ; c++ ) {
for (int p= ; c+p<=m && p<=a ; p++ ) {
for (int u= ; p+u+c<=m && u+c<=o ; u++ ) {
int k = m-(c+u+p);
if (p+k>a) continue;
int w = dfs(i+,a-k-p,o-c+p,L);
if (u > ) {
w += s*c + (c-)*c/;
w -= (s+L[i]-)*p - (p-)*p/;
} else {
w += s*c + (c-)*c/;
w -= (s+L[i]-)*p - (p-)*p/;
w += L[i]-(c+p+k);
}
res = min(res,w);
}
}
}
}
}
return f[i][a][o] = res;
}
int StringWeight::getMinimum(vector <int> L) {
n = L.size();
memset(f, -, sizeof(f));
for (int i= ; i<n ; i++ ) len[i] = i==?L[i]:len[i-]+L[i];
int ans = dfs(,,,L);
return ans;
}
SRM 586 DIV1的更多相关文章
- SRM 586 DIV1 L1
可以化简为求n条线段的最大覆盖问题,需要注意的是对于实数而言. #include <iostream> #include <vector> #include <strin ...
- Topcoder SRM 643 Div1 250<peter_pan>
Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...
- Topcoder Srm 726 Div1 Hard
Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...
- 图论 SRM 674 Div1 VampireTree 250
Problem Statement You are a genealogist specializing in family trees of vampires. Vampire famil ...
- SRM 583 DIV1
A 裸最短路. class TravelOnMars { public: int minTimes(vector <int>, int, int); }; vector<int> ...
- SRM 590 DIV1
转载请注明出处,谢谢viewmode=contents">http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlov ...
- Topcoder SRM 602 div1题解
打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...
- 状态压缩DP SRM 667 Div1 OrderOfOperations 250
Problem Statement Cat Noku has just finished writing his first computer program. Noku's compute ...
- 数学 SRM 690 Div1 WolfCardGame 300
Problem Statement Wolf Sothe and Cat Snuke are playing a card game. The game is played with exa ...
随机推荐
- C++ int转string
一.使用atoi 说明: itoa( int value, char *string, int radix ); 第一个参数:你要转化的int; 第 ...
- linux boost 安装
sudo apt-get install libboost-dev 但是,我这样安装以后,编译程序时出现了很多错误,而且都是系统文件的错误.我开始以为是我的boost库版本不对,后来换了好几个版本,都 ...
- Entity Framework Code First 多数据库 控制台迁移代码
1.启动迁移 Enable Migrations Enable-Migrations -MigrationsDirectory "MigrationsOne" -ContextTy ...
- asp.net中应用JQuery.pagination分页
JQuery.pagination这款分页控件非常好用,可实现无刷新分页,为了方便下次做项目便于拷贝,所以在此发布一下,具体的实现流程如下: 效果图: JQuery.pagination的各个参数的说 ...
- IIS 7.5 配置伪静态
IIS 7.5 配置伪静态_win服务器_脚本之家 win7下IIS的安装和配置 图文教程详细出处参考:http://www.jb51.net/article/29787.htm http://blo ...
- linux FILE 类型.
stdio.h 头文件中,有以下内容(用内部行号解释): /* The opaque type of streams. This is the definition used elsewhere. * ...
- oracle 集合运算符
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAY4AAACNCAIAAAAvhQoxAAAbmklEQVR4nO1dX6jc1pn/0lBH4KVV6J ...
- 思科27亿美元收购网络安全公司Sourcefire
据国外媒体报道,思科于今日宣布将以27亿美元的总价收购网络安全公司Sourcefire,以加强自身在网络安全业务领域的优势,该交易将于今年下半年完成. [IT商业新闻网讯](记者 张良)7月23日消息 ...
- smarty 自定义函数
自定义函数:<{方法名称}> 在lib/plugins中新建文件,命名方式是固定的:function.方法名称.php 或者 block.方法名称.php 1.<{literal}& ...
- 前台任意页面调用自定义字段选项 box 单选 多选方法及查询
在模板页增加函数,函数写法比较特殊,但是v9模板引擎nb,能够识别 <? function xbox($field,$na){ $a=p ...