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. PHP函数的默认参数

    <?php /** * 函数的参数个数任意 */function foo() { $args = func_get_args(); static $i = 0; //统计参数个数 /* fore ...

  2. 招一位安防软件project师,嵌入式开发project师

    岗位职责 1.负责海思平台IPC产品应用层软件设计及维护 2.私有平台协议对接及为第三方提供技术支持. 任职资格: 1.较强的学习.领悟能力,能够高速熟悉公司现有代码. 2.熟练掌握C.C++开发语言 ...

  3. 【C++深入探索】Copy-and-swap idiom详解和实现安全自我赋值

    分类: C/C++2012-08-30 21:40 2017人阅读 评论(2) 收藏 举报 任何管理某资源的类比如智能指针需要遵循一个规则(The Rule of Three): 如果你需要显式地声明 ...

  4. How to configure Gzip for JBoss?---refer

    Question: I think to try to speed up my Web App by reducing the size of transferred data. For exampl ...

  5. wildcard

    [rusky@rhel7 test]$ lstest1  test123  test2  test317  test33  test335  test336  test44  testtest[rus ...

  6. .bash_profile和.bashrc的区别

    参考资料: http://blog.163.com/wang_hai_fei/blog/static/309020312008728333912/

  7. IO-文件 File 复制 读写 总结

    一定要注意: 传入的参数,应该是包含文件名的完整路径名,不能把一个文件复制到[文件夹]中,因为[文件夹]本身是不能有输入输出流的,只能复制到一个[文件]中,否则会报异常. 以字节流读写的三种方式 pu ...

  8. UFLDL课程学习(二)

    章节地址:http://ufldl.stanford.edu/tutorial/supervised/LogisticRegression/ 章节名称:逻辑回归 (Logisitic Regressi ...

  9. mySQL优化 my.ini 配置说明

    [mysqld] port = 3306 serverid = 1 socket = /tmp/mysql.sock skip-name-resolve #禁止MySQL对外部连接进行DNS解析,使用 ...

  10. Android学习手记(5) 基本UI布局

    1.View和ViewGroup Activity是Android应用程序的基本管理单元,Android的每一个窗口都是通过一个Activity来定义的,但是Activity并不能直接用来显示窗口.我 ...