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

  1. SRM 586 DIV1 L1

    可以化简为求n条线段的最大覆盖问题,需要注意的是对于实数而言. #include <iostream> #include <vector> #include <strin ...

  2. Topcoder SRM 643 Div1 250<peter_pan>

    Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...

  3. Topcoder Srm 726 Div1 Hard

    Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...

  4. 图论 SRM 674 Div1 VampireTree 250

    Problem Statement      You are a genealogist specializing in family trees of vampires. Vampire famil ...

  5. SRM 583 DIV1

    A 裸最短路. class TravelOnMars { public: int minTimes(vector <int>, int, int); }; vector<int> ...

  6. SRM 590 DIV1

    转载请注明出处,谢谢viewmode=contents">http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlov ...

  7. Topcoder SRM 602 div1题解

    打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...

  8. 状态压缩DP SRM 667 Div1 OrderOfOperations 250

    Problem Statement      Cat Noku has just finished writing his first computer program. Noku's compute ...

  9. 数学 SRM 690 Div1 WolfCardGame 300

    Problem Statement      Wolf Sothe and Cat Snuke are playing a card game. The game is played with exa ...

随机推荐

  1. uva 317 - Hexagon(规律推导)

    题目连接:317 - Hexagon 题目大意:在一个19个六边形组成的图形上玩一个游戏,给出9个数字, 分成3组, 分别可以填在左上角, 上, 有上角,因为对于小六边形来说, 对边的数是相同的, 然 ...

  2. 机器学习笔记——K-means

    K-means是一种聚类算法,其要求用户设定聚类个数k作为输入參数,因此,在执行此算法前,须要预计须要的簇的个数. 如果有n个点,须要聚到k个簇中.K-means算法首先从包括k个中心点的初始集合開始 ...

  3. 用Hexo搭建属于自己的Blog

    什么是Hexo 简单的来说,Hexo是一款基于Node.JS的静态博客框架,官方给它的描述是"A fast, simple & powerful blog framework&quo ...

  4. 2015 UESTC Winter Training #7【2010-2011 Petrozavodsk Winter Training Camp, Saratov State U Contest】

    2015 UESTC Winter Training #7 2010-2011 Petrozavodsk Winter Training Camp, Saratov State U Contest 据 ...

  5. mysql数据库安装方法

    前言 MySQL 有三种安装方式:RPM安装.二进制包安装.源码包安装.这3种种方式各有特色,主要特点参考下表.实际应用中,可以根据你所用的主机环境进行优化,选择 最佳的配置值,安装定制更灵活.访问M ...

  6. hdu 5062

    题意:将10^0-10^6之间属于  "Beautiful Palindrome Number" 的数个数打印出来,所谓 "Beautiful Palindrome Nu ...

  7. 简要介绍 My.Ioc 的用法

    下面这段代码展示了 My.Ioc 的基本用法: using System; using System.Collections.Generic; namespace My.Ioc.Sample { pu ...

  8. static类

    静态类,用于类内部. 静态类,不需要创建父类对象,即可使用. 非静态类,需要先创建父类对象,才可使用. class A{ static class  B1{} class B2{} } = new A ...

  9. PHP Calendar 函数

    PHP 5 Calendar 函数 函数 描述 cal_days_in_month() 针对指定的年份和历法,返回一个月中的天数. cal_from_jd() 把儒略日计数转换为指定历法的日期. ca ...

  10. C++ 性能剖析 (二):值语义 (value semantics)

    Value Semantics (值语义) 是C++的一个有趣的话题. 什么是值语义? 简单的说,所有的原始变量(primitive variables)都具有value semantics. 也可以 ...