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 ...
随机推荐
- 王者荣耀交流协会第三次Scrum立会
会议时间:2017年10月22号 18:00-18:32,时长32分钟. 会议地点:中快餐厅二楼第二排倒数第二个桌子. 立会内容: 1.每位同学汇报了今日工作. 2.通过讨论我们决定用存excel ...
- 404 Note Found 现场编程
目录 组员职责分工 github 的提交日志截图 程序运行截图 程序运行环境 GUI界面 基础功能实现 运行视频 LCG算法 过滤(降权)算法 算法思路 红黑树 附加功能一 背景 实现 附加功能二(迭 ...
- 博弈---ZOJ 2083 Win the Game(染绳子)
原题:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2083 大意:两个人分别对n条绳子染 每次染m长 最后染不下的输,问先 ...
- ipv6问题
1)百度搜索:针对苹果最新审核要求为应用兼容IPv6 2) ipV6测试网址:http://test-ipv6.com/ http://ipv6.jmu.edu.cn/ http://ipv6test ...
- 初识 es6之 const
const声明一个只读的常量.一旦声明,常量的值就不能改变. 例子: const a=12; a=2;//报错,const 声明的是常量,不能改 const声明的变量不得改变值,这意味着,const一 ...
- jdbc 5.0
1.事务 事务将单个SQL语句或一组SQL语句视为一个逻辑单元,如果任何语句失败,整个事务将失败. jdbc的MySQL驱动程序中的事务默认是自动提交. 默认情况下,每个SQL语句在完成后都会提交到数 ...
- web移动端
h5:低版本(IE8及以下不支持H5标签,要引入html5shiv.js才能正常运行) 条件引入,只是针对PC端,移动端不存在这样的操作 <figure>:专门用来存放图片和相关介绍的 & ...
- 使用Log4在测试过程中打印执行日志 及配置log4j.properties!
http://zengxiantao.iteye.com/blog/1881706 1.环境配置:到网上下载log4j-1.2.17.jar包!完后 添加到 项目的build path 中即可! 2. ...
- 爬虫学习之-操作mysql
在操作数据库的时候,python2中一般使用mysqldb,但在python3中已经不在支持mysqldb了,我们可以用pymysql和mysql.connector.本文的所有操作都是在python ...
- (转)关于ActiveMQ的配置
目前常用的消息队列组建无非就是MSMQ和ActiveMQ,至于他们的异同,这里不想做过多的比较.简单来说,MSMQ内置于微软操作系统之中,在部署上包含一个隐性条件:Server需要是微软操作系统.(对 ...