SRM 598 DIV1
A
只有3种情况:200以上的单独装,3个100的装一起,某两个u,v装一起且u+v<=300,
所以做法是从大到小判断每个大小的最大能与它装一起的是谁,最后剩下100的特判.
B
第一轮如果未分出胜负,考虑一种情况:
mov1 >= mov2, 先手至少不会输.
再判断赢的条件, 设d=mov1-mov2, 先手每一轮结束后可以保证每次距离缩短[1,d],但同时
先手要保持一个安全距离safe以保证不会被后手反击:
safe >= mov2+rng2,
所以当 safe + mov2 <= mov1+d时先手必胜,否则平局.
后手的推理类似.
string FoxAndFencing::WhoCanWin(int m1, int m2, int r1, int r2, int d)
{
if (d<=r1+m1) return "Ciel";
else if (d+m1<=r2+m2) return "Liss";
else if (m2==m1) return "Draw";
else if (m1>m2)
{
if (r1+m1-*m2>r2) return "Ciel";
else return "Draw";
}else
{
printf("%d+%d , %d\n",r2,m2,r1);
if (r2+m2-*m1>r1) return "Liss";
else return "Draw";
}
}
C
首先发现一个性质: 如果某节点x有cnt个孩子,那么往下递归至少有cnt-1个子树存在标记,
这样才能保证x的子树都被识别,根据这条性质设计dp[i][0/1]即可.
但是仅仅这样dp会发现最后结果有一条从根到某叶子的未被标记的链,这条链的某些点可能不会被识别,
为了修正这个问题,可以强制根被标记,换句话说,可以枚举某个被标记的点为根.
#define maxn 51
class TPS {
public:
int minimalBeacons(vector <string>);
};
int dp[maxn][],n,cnts[maxn];
int dfs(int cur,int must,int fa,vector<string> e)
{
int sum=,tmp,res;
if (dp[cur][must]!=-) return dp[cur][must];
if (cnts[cur]==) return dp[cur][must]=must;
for (int i= ; i<n ; i++ ) if (e[cur][i]=='Y' && i!=fa)
sum += dfs(i,,cur,e);
tmp=sum;
for (int i= ; i<n ; i++ ) if(e[cur][i]=='Y' && i!=fa)
tmp = min(tmp,sum-dp[i][]+dfs(i,,cur,e));
if (must && cnts[cur]==) res = sum;
else res = tmp;
if (fa==-) res++;
return dp[cur][must]=res;
}
void initson(int cur,int fa,vector<string> e)
{
for (int i= ; i<n ; i++ )
if (e[cur][i]=='Y' && i!=fa)
{
cnts[cur]++;
initson(i,cur,e);
}
}
int TPS::minimalBeacons(vector <string> e)
{
n = e.size();
int ans = n;
for (int i= ; i<n ; i++ )
{
memset(dp,-,sizeof(dp));
memset(cnts,,sizeof(cnts));
initson(i,-,e);
ans = min(ans,dfs(i,,-,e));
}
return ans;
}
SRM 598 DIV1的更多相关文章
- 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 ...
- SRM 618 DIV1 500
非常棒的组合问题,看了好一会,无想法.... 有很多做法,我发现不考虑顺序的最好理解,也最好写. 结果一定是两种形式 A....A dp[n-1] A...A...A sgma(dp[j]*dp[ ...
随机推荐
- SecureCRT7.3和SecureFX7.3的MAC下破解
破解脚本:http://files.cnblogs.com/files/jieyuefeng/SecureCRTFX_mac_crack.zip 破解方法: sudo perl ~/Downloads ...
- 用SHELL与列表处理了件尴尬事
与列表语法 command-1 && command-2 && command-3 && command-4 && ...command ...
- hdu1869六度分离(dijkstra)
Problem Description 1967年,美国著名的社会学家斯坦利·米尔格兰姆提出了一个名为“小世界现象(small world phenomenon)”的著名假说,大意是说,任何2个素不相 ...
- Ubuntu 14.04 下手动安装Firefox的Flash插件
有时候我们不得不採用手动安装一些软件. Ubuntu 14.04 下手动安装Firefox的Flash插件有下面几步 1. 下载Flash插件 下载地址为http://get.adobe.com/cn ...
- VirtualBox虚拟机网络设置
VirtualBox虚拟机网络设置 测试环境:物理机win10企业版本,VirtaulBox版本5.0.14,虚拟机安装Windows XP及linux系统 想实现虚拟机上网的最简单方式,修改虚拟机网 ...
- netstat 命令详解
netstat命令是一个监控TCP/IP网络的非常有用的工具,它可以显示路由表.实际的网络连接以及每一个网络接口设备的状态信息,在我的计算机上执行netstat后,其输出结果为:netstat命令是一 ...
- CentOS6.X 系统安装图文教程,超详细
http://www.myhack58.com/Article/sort099/sort0102/2011/32363_7.htm
- Python代码分析工具之dis模块
转自:http://hi.baidu.com/tinyweb/item/923d012e8146d00872863ec0 ,格式调整过. 代码分析不是一个新的话题,代码分析重要性的判断比较主观,不同 ...
- 1:scrapy框架原理与环境搭设
1:原理图: (*此图来自网络) 2:开发过程: 1)编写items.py,确定要抓取的关键字段名称 2)编写spider,确定发送request的形式以及对于response的处理 3)编写pipe ...
- (转)sp_executesql介绍和使用
execute相信大家都用的用熟了,简写为exec,除了用来执行存储过程,一般都用来执行动态Sql sp_executesql,sql2005中引入的新的系统存储过程,也是用来处理动态sql的, 如: ...