2017北京国庆刷题Day3 afternoon
期望得分:100+0+30=130
实际得分:100+36.5+0=136.5
T3 一个变量写混了,丢了30。。

模拟栈
#include<cstdio>
#include<cstring>
using namespace std;
#define N 10001
char s[N];
int st[N],top;
int main()
{
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
scanf("%s",s);
int len=strlen(s);
for(int i=;i<len;i++)
if(s[i]=='(') st[++top]=;
else if(s[i]=='[') st[++top]=;
else if(s[i]=='{') st[++top]=;
else if(s[i]==')')
{
if(st[top]==) top--;
else { printf("Wrong");return ; }
}
else if(s[i]==']')
{
if(st[top]==) top--;
else { printf("Wrong"); return ; }
}
else
{
if(st[top]==) top--;
else { printf("Wrong"); return ; }
}
if(top) printf("Wrong");
else printf("OK");
return ;
}


设直线解析式为 y=(-n/m)* x+n
整理,得:n * x + m * y - n * m = 0
点(b,a)到直线的距离为:| b * n + a * m - n * m | / L
(L : 根号下(n^2 + m^2)=L)
棺材能够在这里拐弯
直观上感受就是棺材拐弯的全程不被点(b,a)卡住
所以 最优解 是 b * n + a * m - n * m / L 的最小值
为什么这里把绝对值去掉?
因为 当式子<0 时,直线到了点的右上方,就是不合法解,此时棺材不能通过
单峰函数求最小值,三分法每次去掉大的一部分
注意特判直接横着/竖着就能拖过去的情况
#include<algorithm>
#include<cstdio>
#include<cmath> using namespace std;
const double eps=1e-; int a,b,l; double f(double n)
{
double m=sqrt(1.0*l*l-n*n);
return (b*n+a*m-n*m)/l;
} int main()
{
freopen("b.in","r",stdin);
freopen("b.out","w",stdout);
scanf("%d%d%d",&a,&b,&l);
if(a>=l && b>=l) { printf("%d.0000000",l); return ; }
if(a>=l) { printf("%d.0000000",b); return ; }
if(b>=l) { printf("%d.0000000",a); return ; }
double L=,R=l,ans=-1e18,mid1,mid2,t1,t2;
int T=;
while(T--)
{
mid1=(R-L)/+L; mid2=L+R-mid1;
t1=f(mid1); t2=f(mid2);
if(t1< || t2<) { printf("My poor head =("); return ; }
if(t1<t2) ans=t1,R=mid2;
else ans=t2,L=mid1;
}
printf("%.7lf",ans);
}

递归回溯时贪心
如果当前点的分支个数>=2,那么断掉它与父节点的边,子节点中只留两个最优
所以 ans+=分支个数-2+1
加1是因为还要断掉与父节点的连边
但是如果是递归的根节点,就是ans+=分支个数-2
如果当前只有一个分支,那就不用断,仍然是它的父节点的一个分支
最终的答案就是ans*2+1
*2是因为断掉一个,相应的就要添加一条
+1是最后要形成一个环
#include<cstdio>
#include<iostream> #define N 100001 using namespace std; int front[N],nxt[N<<],to[N<<],tot;
int ans; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} void add(int u,int v)
{
to[++tot]=v; nxt[tot]=front[u]; front[u]=tot;
to[++tot]=u; nxt[tot]=front[v]; front[v]=tot;
} int dfs(int x,int f)
{
int sum=;
for(int i=front[x];i;i=nxt[i])
if(to[i]!=f) sum+=dfs(to[i],x);
if(sum>=)
{
if(x==) ans+=sum-;
else ans+=sum-;
return ;
}
return ;
} int main()
{
freopen("c.in","r",stdin);
freopen("c.out","w",stdout);
int n,u,v;
read(n);
for(int i=;i<n;i++) read(u),read(v),add(u,v);
dfs(,);
printf("%d",ans*+);
}
2017北京国庆刷题Day3 afternoon的更多相关文章
- 2017北京国庆刷题Day1 afternoon
期望得分:100+100+100=300 实际得分:100+100+100=300 T1 一道图论好题(graph) Time Limit:1000ms Memory Limit:128MB 题目 ...
- 2017北京国庆刷题Day5 afternoon
期望得分:100+60+100=260 实际得分:0+60+40=100 设图中有m个环,每个环有si条边,有k条边不在环中 ans= (2^s1 -2)*( 2^s2 -2)* (2^s3 -2)… ...
- 2017北京国庆刷题Day3 morning
期望得分:100+60+0=160 实际得分:100+30+0=130 考场上用的哈希 #include<cstdio> #include<cstring> #include& ...
- 2017北京国庆刷题Day2 afternoon
期望得分:100+100+50=250 实际得分:100+70+50=220 T1 最大值(max) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK有一 ...
- 2017北京国庆刷题Day4 afternoon
期望得分:100+100+0=200 实际得分:5+0+0=5 每加入一个数,x的因数位置++ 注意:根号x枚举时,如果x是完全平方数,根号x会重复累计2次,要减去 考场上没减,5分 /(ㄒoㄒ)/~ ...
- 2017北京国庆刷题Day6 afternoon
期望得分:100+100+40=240 实际得分:100+0+40=140 二进制拆分.二进制前缀和 #include<cstdio> #include<iostream> u ...
- 2017北京国庆刷题Day7 afternoon
期望得分:100+30+100=230 实际得分:60+30+100=190 排序去重 固定右端点,左端点单调不减 考场上用了二分,没去重,60 #include<cstdio> #inc ...
- 2017北京国庆刷题Day7 morning
期望得分:100+0+100=200 实际得分:100+20+0=120 离散化搞搞 #include<cstdio> #include<iostream> #include& ...
- 2017北京国庆刷题Day2 morning
期望得分:100+100+40=240 实际得分:100+40+0=140 T1 一道图论神题(god) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK ...
随机推荐
- 王者荣耀交流协会 - 第6次Scrum会议(第二周)
Scrum master :刘耀泽 工作照片: 照片由刘耀泽(本人)拍摄,组内成员刘耀泽,高远博,王磊,王玉玲,王超,任思佳,袁玥全部到齐. 时间跨度: 2017年10月25日 17:00 — 17: ...
- PSP Daily软件Alpha版本——基于spec评论
题目要求:每个小组评论其他小组Alpha发布作品的软件功能说明书.要求和提交在[https://edu.cnblogs.com/campus/nenu/SWE2017FALL/homework/122 ...
- 每日Scrum--No.3
Yesterday:帮着队友一起打开地图 Today:学习迪杰斯特拉算法,试着编写程序代码 Problem:语法逻辑出错,在执行的时候,有的时候出现死循环,有的时候屏幕出现null和乱码.语句的编写有 ...
- 严重: Failed to destroy end point associated with ProtocolHandler ["http-nio-8080"] java.lang.NullPointer
刚接触servlet类,按照课本的方法使用eclipse新建了一个servlet类. 新建完成后,在web.xml里面进行注册 这时候就会报错了. 五月 07, 2016 11:23:28 上午 or ...
- 软工网络15个人作业4--alpha阶段个人总结
一.个人总结 自我评价表 类别 具体技能和面试问题 现在的回答 毕业找工作 语言 最拿手的语言之一,代码量是多少 java,代码量大概两三千行吧 语言 最拿手的语言之二,代码量是多少 python,代 ...
- weblogic下JNDI及JDBC连接测试(weblogic环境)
JNDI的专业解释,大家自行去网络搜索吧,这里就不啰嗦了. 单纯从使用角度看,可以简称把它看成一个key-value的“哈希资源”容器.给定一个string类型的key,可以把任何类型的value,放 ...
- Windows下IntelliJ IDEA中调试Spark Standalone
参考:http://dataknocker.github.io/2014/11/12/idea%E4%B8%8Adebug-spark-standalone/ 转载请注明来自:http://www.c ...
- DNS缓存服务器的配置步骤
yum安装bind 编辑主配置文件/etc/named.conf 修改全局配置文件段 listen-on port 53 {172.16.19.45;}; //allow-query ...
- Ulipad和有道词典冲突解决方法
问题现象 Ulipad和目前版本的有道词典有冲突,表现为先开有道词典,Ulipad就无法运行. 解决方法 找到Ulipad安装目录下的config.ini,添加以下两行: [server] port= ...
- [CF1111D]Destroy the Colony
题目大意:有一个长度为$n(n\leqslant10^5,n=0\pmod2)$的字符串,字符集大小为$52$,有$q(q\leqslant10^5)$次询问,每次询问第$x,y$个字符在这个字符串的 ...